-
Notifications
You must be signed in to change notification settings - Fork 807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: metric observer #828
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8060876
feat: metric observer
obecny 79f2e48
chore: update after review
obecny 220cd89
chore: reviews
obecny 6afdfbe
chore: merge branch 'master' into metric_observer
obecny 1aea1c6
chore: merge branch 'master' into metric_observer
obecny 8a8cd51
Merge branch 'master' into metric_observer
mayurkale22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Overview | ||
|
||
OpenTelemetry metrics allow a user to collect data and export it to a metrics backend like Prometheus. | ||
|
||
This is a simple example that demonstrates basic metrics collection and exports those metrics to a Prometheus compatible endpoint. | ||
|
||
## Installation | ||
|
||
```sh | ||
$ # from this directory | ||
$ npm install | ||
``` | ||
|
||
How to setup [Prometheus](https://prometheus.io/docs/prometheus/latest/getting_started/) please check | ||
[Setup Prometheus](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-exporter-prometheus) | ||
|
||
## Run the Application | ||
- Run the example | ||
|
||
### Observer | ||
```sh | ||
$ npm run start:observer | ||
``` | ||
|
||
### Prometheus | ||
1. In prometheus search for "metric_observer" | ||
|
||
### Links | ||
1. Prometheus Scrape Endpoint http://localhost:9464/metrics | ||
2. Prometheus graph http://localhost:9090/graph | ||
|
||
### Example | ||
<p align="center"><img src="metrics/observer.png"/></p> | ||
|
||
## Useful links | ||
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/> | ||
- For more information on OpenTelemetry metrics, visit: <https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-metrics> | ||
|
||
## LICENSE | ||
|
||
Apache License 2.0 |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const { MeterProvider } = require('@opentelemetry/metrics'); | ||
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus'); | ||
|
||
const exporter = new PrometheusExporter( | ||
{ | ||
startServer: true, | ||
}, | ||
() => { | ||
console.log('prometheus scrape endpoint: http://localhost:9464/metrics'); | ||
}, | ||
); | ||
|
||
const meter = new MeterProvider({ | ||
exporter, | ||
interval: 1000, | ||
}).getMeter('example-observer'); | ||
|
||
const otelCpuUsage = meter.createObserver('metric_observer', { | ||
monotonic: false, | ||
labelKeys: ['pid', 'core'], | ||
description: 'Example of a observer', | ||
}); | ||
|
||
function getCpuUsage() { | ||
return Math.random(); | ||
} | ||
|
||
otelCpuUsage.setCallback((observerResult) => { | ||
observerResult.observe(getCpuUsage, meter.labels({ pid: process.pid, core: '1' })); | ||
observerResult.observe(getCpuUsage, meter.labels({ pid: process.pid, core: '2' })); | ||
observerResult.observe(getCpuUsage, meter.labels({ pid: process.pid, core: '3' })); | ||
observerResult.observe(getCpuUsage, meter.labels({ pid: process.pid, core: '4' })); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "example-metrics", | ||
"private": true, | ||
"version": "0.4.0", | ||
"description": "Example of using @opentelemetry/metrics", | ||
"main": "index.js", | ||
"scripts": { | ||
"start:observer": "node metrics/observer.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/open-telemetry/opentelemetry-js.git" | ||
}, | ||
"keywords": [ | ||
"opentelemetry", | ||
"http", | ||
"tracing", | ||
"metrics" | ||
], | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"author": "OpenTelemetry Authors", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/open-telemetry/opentelemetry-js/issues" | ||
}, | ||
"dependencies": { | ||
"@opentelemetry/exporter-prometheus": "^0.4.0", | ||
"@opentelemetry/metrics": "^0.4.0" | ||
}, | ||
"homepage": "https://github.com/open-telemetry/opentelemetry-js#readme" | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*! | ||
* Copyright 2020, OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { LabelSet } from './Metric'; | ||
|
||
/** | ||
* Interface that is being used in function setCallback for Observer Metric | ||
*/ | ||
export interface ObserverResult { | ||
observers: Map<LabelSet, Function>; | ||
observe(callback: Function, labelSet: LabelSet): void; | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some reason this is
start:observer
instead of juststart
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have created metrics example to be a place for other metrics too, so next step when working on documentation and examples should be to add
start:counter
,start:measure