Skip to content

Commit

Permalink
Expose application and system metrics on the same port
Browse files Browse the repository at this point in the history
Signed-off-by: Jessica He <jhe@redhat.com>
  • Loading branch information
JessicaJHee committed Dec 2, 2024
1 parent 81ebc75 commit 26f89ad
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
4 changes: 1 addition & 3 deletions docs/monitoring-and-logging.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Setting up Metrics Monitoring and Logging for Backstage Showcase

The Backstage Showcase provides a `/metrics` endpoint on port `9464` (for application metrics) and `9463` (for host metrics) that provides OpenTelemetry metrics about your backstage application. This endpoint can be used to monitor your backstage instance using OpenTelemetry and Grafana.

**Note**: Due to a limitation, the host and application metrics are exposed on separate ports. This is to be improved by making all metrics accessible on the same port (9464) in a future release. This guide will ONLY work with the application metrics from NodeJs and Backstage.
The Backstage Showcase provides a `/metrics` endpoint on port `9464` that provides OpenTelemetry metrics about your backstage application. This endpoint can be used to monitor your backstage instance using OpenTelemetry and Grafana.

When deploying Backstage Showcase onto a kubernetes cluster with the [RHDH Helm chart](https://github.com/redhat-developer/rhdh-chart) or the [RHDH Operator](https://github.com/janus-idp/operator), monitoring and logging for your RHDH instance can be configured using the following steps.

Expand Down
1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@internal/plugin-scalprum-backend": "*",
"@janus-idp/backstage-plugin-audit-log-node": "1.7.0",
"@janus-idp/backstage-scaffolder-backend-module-annotator": "2.2.0",
"@opentelemetry/api": "1.9.0",
"@opentelemetry/auto-instrumentations-node": "0.50.2",
"@opentelemetry/exporter-prometheus": "0.53.0",
"@opentelemetry/host-metrics": "0.35.4",
Expand Down
15 changes: 6 additions & 9 deletions packages/backend/src/instrumentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ const {
} = require('@opentelemetry/instrumentation-runtime-node');
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
const { HostMetrics } = require('@opentelemetry/host-metrics');
const { MeterProvider } = require('@opentelemetry/sdk-metrics');
const { metrics } = require('@opentelemetry/api');

// Application metrics will be exported to localhost:9464/metrics
const prometheusApplication = new PrometheusExporter();
// Metrics will be exported to localhost:9464/metrics
const prometheus = new PrometheusExporter();
const sdk = new NodeSDK({
metricReader: prometheusApplication,
metricReader: prometheus,
instrumentations: [
getNodeAutoInstrumentations(),
new RuntimeNodeInstrumentation(),
Expand All @@ -21,10 +21,7 @@ const sdk = new NodeSDK({

sdk.start();

// Host/process metrics will be exported to localhost:9463/metrics
const prometheusHost = new PrometheusExporter({ port: 9463 });
const meterProvider = new MeterProvider({
readers: [prometheusHost],
const hostMetrics = new HostMetrics({
meterProvider: metrics.getMeterProvider(),
});
const hostMetrics = new HostMetrics({ meterProvider });
hostMetrics.start();
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13986,7 +13986,7 @@ __metadata:
languageName: node
linkType: hard

"@opentelemetry/api@npm:^1.0.0, @opentelemetry/api@npm:^1.0.1, @opentelemetry/api@npm:^1.3.0, @opentelemetry/api@npm:^1.4.0":
"@opentelemetry/api@npm:1.9.0, @opentelemetry/api@npm:^1.0.0, @opentelemetry/api@npm:^1.0.1, @opentelemetry/api@npm:^1.3.0, @opentelemetry/api@npm:^1.4.0":
version: 1.9.0
resolution: "@opentelemetry/api@npm:1.9.0"
checksum: 9e88e59d53ced668f3daaecfd721071c5b85a67dd386f1c6f051d1be54375d850016c881f656ffbe9a03bedae85f7e89c2f2b635313f9c9b195ad033cdc31020
Expand Down Expand Up @@ -22453,6 +22453,7 @@ __metadata:
"@internal/plugin-scalprum-backend": "*"
"@janus-idp/backstage-plugin-audit-log-node": 1.7.0
"@janus-idp/backstage-scaffolder-backend-module-annotator": 2.2.0
"@opentelemetry/api": 1.9.0
"@opentelemetry/auto-instrumentations-node": 0.50.2
"@opentelemetry/exporter-prometheus": 0.53.0
"@opentelemetry/host-metrics": 0.35.4
Expand Down

0 comments on commit 26f89ad

Please sign in to comment.