added an opentelemetry prometheus exporter and example config to the example backend

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2023-05-28 21:07:48 +02:00
parent 0b24ce3270
commit e918c3720f
4 changed files with 98 additions and 4 deletions
+3
View File
@@ -73,6 +73,9 @@
"@backstage/plugin-todo-backend": "workspace:^",
"@gitbeaker/node": "^35.1.0",
"@octokit/rest": "^19.0.3",
"@opentelemetry/api": "^1.4.1",
"@opentelemetry/exporter-prometheus": "^0.39.1",
"@opentelemetry/sdk-metrics": "^1.13.0",
"azure-devops-node-api": "^11.0.1",
"better-sqlite3": "^8.0.0",
"dockerode": "^3.3.1",
+21
View File
@@ -0,0 +1,21 @@
# This is an example configuration file for Prometheus, that is set to scrape
# the metrics endpoint exposed by the example backend.
#
# If you want to run a docker based Prometheus instance locally to try it out,
# run the following command in the Backstage root:
#
# docker run --mount type=bind,source=./packages/backend/prometheus.yml,destination=/etc/prometheus/prometheus.yml --publish published=9090,target=9090,protocol=tcp prom/prometheus
#
# After this, you have a Prometheus instance on http://localhost:9090
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
# This target address specifically works on Docker for MacOS - you may
# need to change it to another host depending on your OS and Docker
# engine.
- targets: ['host.docker.internal:9464']
+13 -2
View File
@@ -30,7 +30,7 @@ import {
loadBackendConfig,
notFoundHandler,
DatabaseManager,
SingleHostDiscovery,
HostDiscovery,
UrlReaders,
useHotMemoize,
ServerTokenManager,
@@ -69,11 +69,22 @@ import { PluginEnvironment } from './types';
import { ServerPermissionClient } from '@backstage/plugin-permission-node';
import { DefaultIdentityClient } from '@backstage/plugin-auth-node';
import { DefaultEventBroker } from '@backstage/plugin-events-backend';
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
import { MeterProvider } from '@opentelemetry/sdk-metrics';
import { metrics } from '@opentelemetry/api';
// Expose opentelemetry metrics using a Prometheus exporter on
// http://localhost:9464/metrics . See prometheus.yml in packages/backend for
// more information on how to scrape it.
const exporter = new PrometheusExporter();
const meterProvider = new MeterProvider();
metrics.setGlobalMeterProvider(meterProvider);
meterProvider.addMetricReader(exporter);
function makeCreateEnv(config: Config) {
const root = getRootLogger();
const reader = UrlReaders.default({ logger: root, config });
const discovery = SingleHostDiscovery.fromConfig(config);
const discovery = HostDiscovery.fromConfig(config);
const tokenManager = ServerTokenManager.fromConfig(config, { logger: root });
const permissions = ServerPermissionClient.fromConfig(config, {
discovery,