-
Notifications
You must be signed in to change notification settings - Fork 705
Metrics export pipeline + metrics stdout exporter #341
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
Changes from 22 commits
bbfb6f6
da5a9f4
c783e48
88bdc57
ea77627
07e5bb5
b8e4aed
bb814ec
2f44e84
e7c8eaa
248a793
4ce4ae1
9be693c
f0f302e
8351ef9
4408d94
9db1540
cc862b9
7a5a14d
f9fbd6d
ba41d38
5c2b86e
4e771d6
3af96b7
303fefe
fcb46aa
0ba6611
35697d4
6dfa2b2
9578dba
f4d82e7
a7a9c54
fe44402
d011b8e
6588aee
d99a2a3
1c9d44d
56f68e8
cb51341
b1bfa38
ac1aff9
f135cc8
897a8ba
f73da8d
1619575
6136987
08a5357
5f68832
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
opentelemetry.sdk.metrics.export.aggregate | ||
========================================== | ||
|
||
.. automodule:: opentelemetry.sdk.metrics.export.aggregate | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
opentelemetry.sdk.metrics.export.batcher | ||
========================================== | ||
|
||
.. toctree:: | ||
|
||
opentelemetry.sdk.metrics.export | ||
|
||
.. automodule:: opentelemetry.sdk.metrics.export.batcher | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
opentelemetry.sdk.metrics.export | ||
========================================== | ||
|
||
.. automodule:: opentelemetry.sdk.metrics.export | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright 2019, OpenTelemetry Authors | ||
lzchen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# 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 | ||
# | ||
# http://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. | ||
# | ||
""" | ||
This module serves as an example for a simple application using metrics | ||
Examples show how to recording affects the collection of metrics to be exported | ||
""" | ||
import time | ||
|
||
from opentelemetry import metrics | ||
from opentelemetry.sdk.metrics import Counter, Meter | ||
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter | ||
from opentelemetry.sdk.metrics.export.batcher import UngroupedBatcher | ||
from opentelemetry.sdk.metrics.export.controller import PushController | ||
|
||
# Batcher used to collect all created metrics from meter ready for exporting | ||
# Pass in false for non-stateful batcher. Indicates the batcher computes | ||
# checkpoints which describe the updates of a single collection period (deltas) | ||
batcher = UngroupedBatcher(False) | ||
# Meter is responsible for creating and recording metrics | ||
meter = Meter(batcher) | ||
metrics.set_preferred_meter_implementation(meter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI this example is broken now, possibly as a result of #311.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually it's metrics_example.py that's broken for this reason. This example has some other problems:
This example also creates a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added no-op implementations of the metric and handle functions to the default classes so user's who don't have the I agree the usage should be I don't want to include too many loader changes in this PR. As of now, the examples would not work because the loader doesn't seem to be addressing use case. |
||
# exporter to export metrics to the console | ||
exporter = ConsoleMetricsExporter() | ||
# controller collects metrics created from meter and exports it via the | ||
# exporter every interval | ||
controller = PushController(meter, exporter, 5) | ||
mauriciovasquezbernal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
counter = meter.create_metric( | ||
"available memory", | ||
lzchen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"available memory", | ||
"bytes", | ||
int, | ||
Counter, | ||
("environment",), | ||
) | ||
|
||
label_set = meter.get_label_set({"environment": "staging"}) | ||
|
||
counter.add(25, label_set) | ||
# We sleep for 5 seconds, exported value should be 25 | ||
time.sleep(5) | ||
|
||
counter.add(50, label_set) | ||
# exported value should be 50 due to non-stateful batcher | ||
time.sleep(5) | ||
lzchen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Following exported values would be 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright 2019, 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 | ||
# | ||
# http://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. | ||
# | ||
""" | ||
This module serves as an example for a simple application using metrics. | ||
It demonstrates the different ways you can record metrics via the meter. | ||
""" | ||
|
||
from opentelemetry import metrics | ||
from opentelemetry.sdk.metrics import Counter, Meter | ||
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter | ||
from opentelemetry.sdk.metrics.export.controller import PushController | ||
|
||
# Meter is responsible for creating and recording metrics | ||
meter = Meter() | ||
metrics.set_preferred_meter_implementation(meter) | ||
# exporter to export metrics to the console | ||
exporter = ConsoleMetricsExporter() | ||
# controller collects metrics created from meter and exports it via the | ||
# exporter every interval | ||
controller = PushController(meter, exporter, 5) | ||
|
||
# Example to show how to record using the meter | ||
counter = meter.create_metric( | ||
"available memory", | ||
"available memory", | ||
"bytes", | ||
int, | ||
Counter, | ||
("environment",), | ||
) | ||
|
||
# Labelsets are used to identify key-values that are associated with a specific | ||
lzchen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# metric that you want to record. These are useful for pre-aggregation and can | ||
# be used to store custom dimensions pertaining to a metric | ||
|
||
# The meter takes a dictionary of key value pairs | ||
label_set = meter.get_label_set({"environment": "staging"}) | ||
|
||
# Handle usage | ||
# You can record metrics with metric handles. Handles are created by passing in | ||
# a labelset. A handle is essentially metric data that corresponds to a specific | ||
# set of labels. Therefore, getting a handle using the same set of labels will | ||
# yield the same metric handle. | ||
counter_handle = counter.get_handle(label_set) | ||
counter_handle.add(100) | ||
|
||
# Direct metric usage | ||
# You can record metrics directly using the metric instrument. You pass in a | ||
# labelset that you would like to record for. | ||
counter.add(25, label_set) | ||
|
||
# Record batch usage | ||
# You can record metrics in a batch by passing in a labelset and a sequence of | ||
# (metric, value) pairs. The value would be recorded for each metric using the | ||
# specified labelset for each. | ||
meter.record_batch(label_set, [(counter, 50)]) | ||
lzchen marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Copyright 2019, 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 | ||
# | ||
# http://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. | ||
# | ||
""" | ||
This module serves as an example for a simple application using metrics | ||
Examples show how to recording affects the collection of metrics to be exported | ||
""" | ||
import time | ||
|
||
from opentelemetry import metrics | ||
from opentelemetry.sdk.metrics import Counter, Meter | ||
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter | ||
from opentelemetry.sdk.metrics.export.batcher import UngroupedBatcher | ||
from opentelemetry.sdk.metrics.export.controller import PushController | ||
|
||
# Batcher used to collect all created metrics from meter ready for exporting | ||
# Pass in true/false to indicate whether the batcher is stateful. True | ||
# indicates the batcher computes checkpoints from over the process lifetime. | ||
# False indicates the batcher computes checkpoints which describe the updates | ||
# of a single collection period (deltas) | ||
batcher = UngroupedBatcher(True) | ||
# If a batcher is not provded, a default batcher is used | ||
# Meter is responsible for creating and recording metrics | ||
meter = Meter(batcher) | ||
metrics.set_preferred_meter_implementation(meter) | ||
# exporter to export metrics to the console | ||
exporter = ConsoleMetricsExporter() | ||
# controller collects metrics created from meter and exports it via the | ||
# exporter every interval | ||
controller = PushController(meter, exporter, 5) | ||
|
||
counter = meter.create_metric( | ||
"available memory", | ||
"available memory", | ||
"bytes", | ||
int, | ||
Counter, | ||
("environment",), | ||
) | ||
|
||
counter2 = meter.create_metric( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the "stateful" example different from the "non-stateful" one in ways other than batcher state? If the goal is to compare stateful and non-stateful batchers, what do you think about combining these examples to show only that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Combining the two examples will require metrics to load a different implementation of |
||
"available memory2", | ||
"available memory2", | ||
"bytes2", | ||
int, | ||
Counter, | ||
("environment",), | ||
) | ||
|
||
label_set = meter.get_label_set({"environment": "staging"}) | ||
label_set2 = meter.get_label_set({"environment": "testing"}) | ||
|
||
counter.add(25, label_set) | ||
# We sleep for 5 seconds, exported value should be 25 | ||
time.sleep(5) | ||
|
||
counter.add(50, label_set) | ||
# exported value should be 75 | ||
time.sleep(5) | ||
|
||
counter.add(35, label_set2) | ||
# should be two exported values 75 and 35, one for each labelset | ||
time.sleep(5) | ||
|
||
counter2.add(5, label_set) | ||
# should be three exported values, labelsets can be reused for different | ||
# metrics but will be recorded seperately, 75, 35 and 5 | ||
time.sleep(5) |
Uh oh!
There was an error while loading. Please reload this page.