Skip to content
This repository has been archived by the owner on May 31, 2019. It is now read-only.

Commit

Permalink
feat: histograms + metric resetting
Browse files Browse the repository at this point in the history
  • Loading branch information
psturc committed Aug 9, 2018
1 parent c6c4b53 commit 91b8e04
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions server/metrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { buildPath } = require('../lib/util/logger')

Prometheus.collectDefaultMetrics()

const resolverTimingMetric = new Prometheus.Gauge({
const resolverTimingMetric = new Prometheus.Histogram({
name: 'resolver_timing_ms',
help: 'Resolver response time in milliseconds',
labelNames: ['datasource_type', 'operation_type', 'name']
Expand All @@ -15,7 +15,13 @@ const resolverRequestsMetric = new Prometheus.Counter({
labelNames: ['datasource_type', 'operation_type', 'path']
})

const serverResponseMetric = new Prometheus.Gauge({
const resolverRequestsTotalMetric = new Prometheus.Counter({
name: 'requests_resolved_total',
help: 'Number of requests resolved by server in total',
labelNames: ['datasource_type', 'operation_type', 'path']
})

const serverResponseMetric = new Prometheus.Histogram({
name: 'server_response_ms',
help: 'Server response time in milliseconds',
labelNames: ['request_type', 'error']
Expand All @@ -24,6 +30,10 @@ const serverResponseMetric = new Prometheus.Gauge({
exports.getMetrics = (req, res) => {
res.set('Content-Type', Prometheus.register.contentType)
res.end(Prometheus.register.metrics())

resolverTimingMetric.reset()
resolverRequestsMetric.reset()
serverResponseMetric.reset()
}

exports.responseLoggingMetric = (req, res, next) => {
Expand All @@ -43,7 +53,7 @@ exports.responseLoggingMetric = (req, res, next) => {

serverResponseMetric
.labels(requestMethod, err !== undefined || res.statusCode > 299)
.set(responseTime)
.observe(responseTime)
}
}

Expand All @@ -58,7 +68,7 @@ exports.updateResolverMetrics = (resolverInfo, responseTime) => {

resolverTimingMetric
.labels(dataSourceType, resolverMappingType, resolverMappingName)
.set(responseTime)
.observe(responseTime)

resolverRequestsMetric
.labels(
Expand All @@ -67,4 +77,12 @@ exports.updateResolverMetrics = (resolverInfo, responseTime) => {
`${resolverParentType}.${buildPath(resolverWholePath)}`
)
.inc(1)

resolverRequestsTotalMetric
.labels(
dataSourceType,
resolverMappingType,
`${resolverParentType}.${buildPath(resolverWholePath)}`
)
.inc(1)
}

0 comments on commit 91b8e04

Please sign in to comment.