0

I'm running a custom Python application. The logging inside the code is written to Stackdriverm, fine. But for specific blocks of code I'm thinking to create custom metrics in Stackdriver. But here's my problem. There are some official docs for that:

All of them are using code that starts like this:

from google.cloud import monitoring

client = monitoring.Client()
descriptor = client.metric_descriptor(
    'custom.googleapis.com/my_metric',
    metric_kind=monitoring.MetricKind.GAUGE,
    value_type=monitoring.ValueType.DOUBLE,
    description='This is a simple example of a custom metric.')

My problem is, that I can not reproduce this code. I've installed the following libs:

google-cloud-monitoring

But when I try the code, it say that there is no Client in the google-cloud-monitoring package. Instead there is a MetricServiceClient, but I can not find any good documentation on how to use that.

source code

PS: my IDE is PyCharm.

And idea?

Matthias
  • 5,574
  • 8
  • 61
  • 121
  • Brother, search is useful. https://google-cloud-python.readthedocs.io/en/latest/monitoring/gapic/v3/api.html#google.cloud.monitoring_v3.MetricServiceClient – Sraw May 08 '18 at 08:41
  • I'm not your brother ;) anyway, I found some links to readthedocs yesterday, but all of them ended up in 404. So, thanks for providing a link that works. By the way: I can not see a full example how the properties of a metric descriptor should be initialized before calling `create_metric_descriptor` – Matthias May 08 '18 at 08:55

1 Answers1

4

For now, use version 0.28.1 of the client library. I will update the official docs shortly so they work 0.29.

https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/monitoring/api/v3/cloud-client/requirements.txt

Jeffrey Rennie
  • 3,193
  • 1
  • 18
  • 19