@zcong/koa-prometheus
TypeScript icon, indicating that this package has built-in type declarations

0.5.3 • Public • Published

koa-prometheus

NPM version NPM downloads CircleCI codecov

koa prometheus middleware

Install

$ yarn add @zcong/koa-prometheus
# npm
$ npm i @zcong/koa-prometheus --save

Usage

import * as Koa from 'koa'
import { setupProm } from '@zcong/koa-prometheus'

const app = new Koa()

setupProm(app) // use default config

default metrics route is /metrics.

Config

use custom config

setupProm(app, {
  // custom config here
})
name description default example
metricsPath export metrics route /metrics /custom/route
collectDefaultMetrics if collect default metrics true false
defaultLabels global labels {} { app: 'myApp' }
statusNormalizer func for normalizing status code config.ts
requestDurationUseHistogram if requestDuration use Histogram or Summary true false

Prometheus query examples

QPS over the last 5m

sum(rate(http_requests_total{job=~"__your_job__", route=~".*"}[5m])) by (route)

Avarage request durations in ms over the last 5m

avg(increase(http_request_duration_ms_sum{job=~"__your_job__", route=~".*"}[5m])/ increase(http_request_duration_ms_count{job=~"__your_job__", route=~".*"}[5m]) >0) by (route)

Non 200 status rate over the last 5m

sum(irate(http_requests_total{status!~"200",job=~"__your_job__", route=~".*"}[5m])) BY (job, route, status) / IGNORING(status) GROUP_LEFT() sum(irate(http_requests_total{job=~"__your_job__", route=~".*"}[5m])) BY (job, route) * 100

90th percentile of request durations over the last 5m

histogram_quantile(0.90, sum(irate(http_request_duration_ms_bucket{job=~"__your_job__", route=~".*"}[5m])) by (route, le))

License

MIT © zcong1993

Readme

Keywords

none

Package Sidebar

Install

npm i @zcong/koa-prometheus

Weekly Downloads

0

Version

0.5.3

License

MIT

Unpacked Size

21.1 kB

Total Files

31

Last publish

Collaborators

  • zcong