Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aggregate metrics across cluster (#3939)
- Loading branch information
Showing
5 changed files
with
149 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
/* eslint-disable @typescript-eslint/no-misused-promises */ | ||
const express = require('express') | ||
|
||
const router = express.Router() | ||
|
||
/** | ||
* Exposes Prometheus metrics at `GET /prometheus_metrics` | ||
* Exposes Prometheus metrics for the worker (not aggregated) at `GET /prometheus_metrics_worker` | ||
*/ | ||
|
||
router.get('/prometheus_metrics', async (req, res) => { | ||
router.get('/prometheus_metrics_worker', async (req, res) => { | ||
const prometheusRegistry = req.app.get('serviceRegistry').prometheusRegistry | ||
const metricData = await prometheusRegistry.getAllMetricData() | ||
|
||
res.setHeader('Content-Type', prometheusRegistry.registry.contentType) | ||
return res.end(metricData) | ||
}) | ||
|
||
/** | ||
* Exposes Prometheus metrics aggregated across all workers at `GET /prometheus_metrics` | ||
*/ | ||
router.get('/prometheus_metrics', async (req, res) => { | ||
try { | ||
const prometheusRegistry = req.app.get('serviceRegistry').prometheusRegistry | ||
const { metricsData, contentType } = | ||
await prometheusRegistry.getCustomAggregateMetricData() | ||
res.setHeader('Content-Type', contentType) | ||
return res.end(metricsData) | ||
} catch (ex) { | ||
res.statusCode = 500 | ||
return res.end(ex.message) | ||
} | ||
}) | ||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters