Giter VIP home page Giter VIP logo

egg-exporter's Introduction

egg-exporter

NPM version npm download

基于 egg-prometheus 开发,增加更多性能指标,为 egg 提供 Prometheus 功能支持。了解更多请看 Node.js 监控方案

展示

./screenshots/egg-metrics-v1.png

安装

$ npm i egg-exporter --save

用法

开启插件

通过 ${app_root}/config/plugin.js 配置启动 Prometheus 插件:

exports.exporter = {
  enable: true,
  package: 'egg-exporter',
};

配置

exports.exporter = {
  scrapePort: 3000,
  scrapePath: '/metrics',
  prefix: 'egg_',
  defaultLabels: { stage: 'dev' },
};
  • scrapePort: 监听的用于采集 metrics 的端口
  • scrapePath: 监听的采集 metrics 的服务路径
  • prefix: 指定 metrics 名称的前缀
  • defaultLabels: 默认的 metrics 标签,全局生效
  • aggregatorPort: 配置 TCP 进程通信所使用的端口

内置的 Metrics

  • http_request_duration_milliseconds histogram: http 请求耗时
  • http_request_size_bytes summary: http 请求 body 大小
  • http_response_size_bytes summary: http 响应 body 大小
  • http_request_total counter: http 请求数
  • http_all_errors_total counter: http 错误数
  • http_all_request_in_processing_total gauge: http 处理中请求数
  • process_resident_memory_bytes gauge: 驻留内存大小
  • nodejs_heap_size_total_bytes gauge: 已申请堆内存大小
  • nodejs_heap_size_used_bytes gauge: 已使用堆内存大小
  • nodejs_external_memory_bytes gauge: V8 管理的,绑定到 Javascript 的 C++ 对象的内存使用情况
  • nodejs_version_info: 版本信息

当 egg-rpc-base 插件开启时,还会提供下面 metrics

  • rpc_consumer_response_time_ms summary: rpc 客户端请求耗时
  • rpc_consumer_request_rate counter: rpc 客户端请求数
  • rpc_consumer_fail_response_time_ms summary: rpc 客户端失败的请求耗时
  • rpc_consumer_request_fail_rate counter: rpc 客户端失败的请求数
  • rpc_consumer_request_size_bytes summary: rpc 请求大小统计
  • rpc_consumer_response_size_bytes summary: rpc 响应大小统计
  • rpc_provider_response_time_ms summary: rpc 服务端处理时间
  • rpc_provider_request_rate counter: rpc 服务端收到请求数
  • rpc_provider_fail_response_time_ms summary: rpc 服务端失败的请求处理时间
  • rpc_provider_request_fail_rate counter: rpc 服务端失败的请求数

自定义 Metrics

可以通过下面 API 自定义业务 metrics

const counter = new app.prometheus.Counter({
  name: 'xxx_total',
  help: 'custom counter',
  labelNames: [ 'xxx' ],
});

const gauge = new app.prometheus.Gauge({
  name: 'xxx_gauge',
  help: 'custom gauge',
  labelNames: [ 'xxx' ],
});

const histogram = new app.prometheus.Histogram({
  name: 'xxx_histogram',
  help: 'custom histogram',
  labelNames: [ 'xxx' ],
});

const summary = new app.prometheus.Summary({
  name: 'xxx_summary',
  help: 'custom summary',
  labelNames: [ 'xxx' ],
});

如何贡献

请告知我们可以为你做些什么,不过在此之前,请检查一下是否有已经存在的Bug或者意见

License

MIT

egg-exporter's People

Contributors

airclear avatar gxcsoccer avatar jianglin-wu avatar popomore avatar semantic-release-bot avatar xujihui1985 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

egg-exporter's Issues

request error 导致插件报错

错误堆栈如下:

/data/frontend/fe-node-staticize-render/node_modules/egg-exporter/lib/metrics/http_server.js:70
    const { method, path } = ctx;
            ^

TypeError: Cannot destructure property `method` of 'undefined' or 'null'.
    at Application.app.on (/data/frontend/fe-node-staticize-render/node_modules/egg-exporter/lib/metrics/http_server.js:70:30)
    at Application.emit (events.js:187:15)
    at Lifecycle.EggCore.lifecycle.on.err (/data/frontend/fe-node-staticize-render/node_modules/egg-core/lib/egg.js:106:44)
    at Lifecycle.emit (events.js:182:13)
    at Ready.ready.on.err (/data/frontend/fe-node-staticize-render/node_modules/egg-core/lib/lifecycle.js:238:35)
    at Ready.emit (events.js:187:15)
    at Ready.readyDone (/data/frontend/fe-node-staticize-render/node_modules/ready-callback/lib/ready.js:118:19)
    at Immediate.setImmediate (/data/frontend/fe-node-staticize-render/node_modules/ready-callback/lib/ready.js:97:31)
    at runCallback (timers.js:693:18)
    at tryOnImmediate (timers.js:664:5)

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.