Skip to content

Commit

Permalink
chore: update prometheus examples (#2939)
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas authored Apr 30, 2022
1 parent 60a17ee commit 6436d85
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 181 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
packages/*/package-lock.json
experimental/packages/*/node_modules
experimental/packages/*/package-lock.json
key: node-tests-${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('package.json', 'packages/*/package.json', 'experimental/packages/*/package.json') }}-04142022
key: node-tests-${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('package.json', 'packages/*/package.json', 'experimental/packages/*/package.json') }}-04292022

- name: Bootstrap
run: |
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
packages/*/package-lock.json
experimental/packages/*/node_modules
experimental/packages/*/package-lock.json
key: browser-tests-${{ runner.os }}-${{ hashFiles('package.json', 'packages/*/package.json', 'experimental/packages/*/package.json') }}-04142022
key: browser-tests-${{ runner.os }}-${{ hashFiles('package.json', 'packages/*/package.json', 'experimental/packages/*/package.json') }}-04292022

- name: Bootstrap
run: |
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
packages/*/package-lock.json
experimental/packages/*/node_modules
experimental/packages/*/package-lock.json
key: webworker-tests-${{ runner.os }}-${{ hashFiles('package.json', 'packages/*/package.json', 'experimental/packages/*/package.json') }}-04142022
key: webworker-tests-${{ runner.os }}-${{ hashFiles('package.json', 'packages/*/package.json', 'experimental/packages/*/package.json') }}-04292022

- name: Bootstrap
run: |
Expand Down
Binary file removed examples/prometheus/images/prom-counter.png
Binary file not shown.
Binary file removed examples/prometheus/images/prom-updowncounter.png
Binary file not shown.
32 changes: 0 additions & 32 deletions examples/prometheus/index.js

This file was deleted.

7 changes: 7 additions & 0 deletions experimental/examples/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
"env": {
"mocha": true,
"node": true
},
...require('../../eslint.config.js')
}
File renamed without changes.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions experimental/examples/prometheus/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

const { DiagConsoleLogger, DiagLogLevel, diag } = require('@opentelemetry/api');
const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');

This comment has been minimized.

Copy link
@SourovKH

SourovKH Oct 26, 2024

this package itself is deprecated
please use @opentelemetry/sdk-metrics
https://www.npmjs.com/package/@opentelemetry/sdk-metrics

const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');

// Optional and only needed to see the internal diagnostic logging (during development)
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);

const { endpoint, port } = PrometheusExporter.DEFAULT_OPTIONS;

const exporter = new PrometheusExporter({}, () => {
console.log(
`prometheus scrape endpoint: http://localhost:${port}${endpoint}`,
);
});

// Creates MeterProvider and installs the exporter as a MetricReader
const meterProvider = new MeterProvider();
meterProvider.addMetricReader(exporter);

This comment has been minimized.

Copy link
@SourovKH

SourovKH Oct 26, 2024

This is deprecated now, please update this and provide some alternative

const meter = meterProvider.getMeter('example-prometheus');

// Creates metric instruments
const requestCounter = meter.createCounter('requests', {
description: 'Example of a Counter',
});

const upDownCounter = meter.createUpDownCounter('test_up_down_counter', {
description: 'Example of a UpDownCounter',
});

const attributes = { pid: process.pid, environment: 'staging' };

// Record metrics
setInterval(() => {
requestCounter.add(1, attributes);
upDownCounter.add(Math.random() > 0.5 ? 1 : -1, attributes);
}, 1000);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prometheus-example",
"version": "0.25.0",
"version": "0.28.0",
"description": "Example of using @opentelemetry/sdk-metrics-base and @opentelemetry/exporter-prometheus",
"main": "index.js",
"scripts": {
Expand All @@ -10,7 +10,7 @@
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/api": "^1.0.2",
"@opentelemetry/exporter-prometheus": "0.25.0",
"@opentelemetry/sdk-metrics-base": "0.25.0"
"@opentelemetry/exporter-prometheus": "0.28.0",
"@opentelemetry/sdk-metrics-base": "0.28.0"
}
}
File renamed without changes.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

0 comments on commit 6436d85

Please sign in to comment.