Skip to content

Commit

Permalink
Update monitoring README and docs requirements files
Browse files Browse the repository at this point in the history
  • Loading branch information
aabmass committed May 9, 2023
1 parent 9fb5235 commit a619139
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/examples/cloud_monitoring/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ grpcio-status==1.50.0
idna==3.4
opentelemetry-api==1.14.0
../../../opentelemetry-exporter-gcp-monitoring
../../../opentelemetry-resourcedetector-gcp
opentelemetry-sdk==1.14.0
opentelemetry-semantic-conventions==0.35b0
proto-plus==1.22.1
Expand Down
1 change: 1 addition & 0 deletions docs/examples/flask_e2e/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ opentelemetry-api==1.14.0
../../../opentelemetry-exporter-gcp-monitoring
../../../opentelemetry-exporter-gcp-trace
../../../opentelemetry-propagator-gcp
../../../opentelemetry-resourcedetector-gcp
opentelemetry-instrumentation==0.35b0
opentelemetry-instrumentation-requests==0.35b0
opentelemetry-instrumentation-flask==0.35b0
Expand Down
39 changes: 26 additions & 13 deletions opentelemetry-exporter-gcp-monitoring/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,45 @@ Usage
.. code:: python
import time
from opentelemetry import metrics
from opentelemetry.exporter.cloud_monitoring import (
CloudMonitoringMetricsExporter,
)
from opentelemetry.sdk.metrics import Counter, MeterProvider
metrics.set_meter_provider(MeterProvider())
meter = metrics.get_meter(__name__)
metrics.get_meter_provider().start_pipeline(
meter, CloudMonitoringMetricsExporter(), 5
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
from opentelemetry.sdk.resources import Resource
metrics.set_meter_provider(
MeterProvider(
metric_readers=[
PeriodicExportingMetricReader(
CloudMonitoringMetricsExporter(), export_interval_millis=5000
)
],
resource=Resource.create(
{
"service.name": "basic_metrics",
"service.namespace": "examples",
"service.instance.id": "instance123",
}
),
)
)
meter = metrics.get_meter(__name__)
# Creates metric workload.googleapis.com/request_counter with monitored resource generic_task
requests_counter = meter.create_counter(
name="request_counter",
description="number of requests",
unit="1",
value_type=int
)
staging_labels = {"environment": "staging"}
for i in range(20):
requests_counter.add(25, staging_labels)
time.sleep(10)
time.sleep(5)
References
Expand Down

0 comments on commit a619139

Please sign in to comment.