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

Commit

Permalink
Merge pull request #51 from aerogear/AEROGEAR-7650-additional_changes
Browse files Browse the repository at this point in the history
Histograms + metric resetting
  • Loading branch information
psturc committed Aug 10, 2018
2 parents 30aa9a5 + 91b8e04 commit 141e1c6
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 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 @@ -42,8 +52,8 @@ exports.responseLoggingMetric = (req, res, next) => {
const responseTime = Date.now() - this.requestStart

serverResponseMetric
.labels(requestMethod, err === true)
.set(responseTime)
.labels(requestMethod, err !== undefined || res.statusCode > 299)
.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 141e1c6

Please sign in to comment.