github.com/google/cloudprober@v0.11.3/docs/content/surfacers/stackdriver.md (about) 1 --- 2 menu: 3 main: 4 parent: "Exporting Metrics (Surfacers)" 5 weight: 30 6 title: "Stackdriver (Google Cloud Monitoring)" 7 date: 2020-11-01T17:24:32-07:00 8 --- 9 Cloudprober can natively export metrics to Google Cloud Monitoring (formerly, Stackdriver) using stackdriver [surfacer](/surfacers/overview). Adding stackdriver surfacer to cloudprober is as simple as adding the following stanza to the config: 10 11 ``` 12 surfacer { 13 type: STACKDRIVER 14 } 15 ``` 16 17 This config will work if you're running on GCP and your VM (or GKE pod) has access to Cloud Monitoring (Stackdriver). If running on any other platform, you'll have to specify the GCP project where you want to send the metrics, and you'll have to configure your environment for [Google Application Default Credentials](https://cloud.google.com/docs/authentication/production#automatically). 18 19 By default, stackdriver surfacer exports metrics with the following prefix: `custom.googleapis.com/cloudprober/<probe-type>/<probe>`. For example, for HTTP probe named `google_com`, standard metrics will be exported as: 20 21 ``` 22 custom.googleapis.com/cloudprober/http/google_com/total 23 custom.googleapis.com/cloudprober/http/google_com/success 24 custom.googleapis.com/cloudprober/http/google_com/failure 25 custom.googleapis.com/cloudprober/http/google_com/latency 26 ``` 27 28 Here are all the config options for stackdriver surfacer: 29 30 ```protobuf 31 // GCP project name for stackdriver. If not specified and running on GCP, 32 // local project is used. 33 optional string project = 1; 34 35 // If allowed_metrics_regex is specified, only metrics matching the given 36 // regular expression will be exported to stackdriver. Since probe type and 37 // probe name are part of the metric name, you can use this field to restrict 38 // stackdriver metrics to a particular probe. 39 // Example: 40 // allowed_metrics_regex: ".*(http|ping).*(success|validation_failure).*" 41 optional string allowed_metrics_regex = 3; 42 43 // Monitoring URL base. Full metric URL looks like the following: 44 // <monitoring_url>/<ptype>/<probe>/<metric> 45 // Example: 46 // custom.googleapis.com/cloudprober/http/google-homepage/latency 47 optional string monitoring_url = 4 48 [default = "custom.googleapis.com/cloudprober/"]; 49 ``` 50 51 (Source: https://github.com/google/cloudprober/blob/master/surfacers/stackdriver/proto/config.proto) 52 53 For example, you can configure stackdriver surfacer to export only metrics that match a specific regex: 54 55 ```protobuf 56 surfacer { 57 stackdriver_surfacer { 58 # Export only "http" probe metrics. 59 allowed_metrics_regex: ".*\\/http\\/.*" 60 } 61 } 62 ``` 63 64 65 66 ## Accessing the data 67 68 Cloudprober exports metrics to stackdriver as [custom metrics](https://cloud.google.com/monitoring/custom-metrics). Since all cloudprober metrics are counters (total number of probes, success, latency), you'll see rates of these metrics in stackdriver [metrics explorer](https://cloud.google.com/monitoring/charts/metrics-explorer) by default. This data may not be very useful as it is (unless you're using distributions in cludprober, more on that later). 69 70 However, stackdriver now provides a powerful monitoring query language,[MQL](https://cloud.google.com/monitoring/mql), using which we can get more useful metrics. 71 72 MQL to get failure ratio: 73 74 ```shell 75 fetch global 76 | { metric 'custom.googleapis.com/cloudprober/http/google_com/failure' 77 ; metric 'custom.googleapis.com/cloudprober/http/google_com/total' } 78 | align delta(1m) 79 | join 80 | div 81 ``` 82 83 MQL to get average latency for a probe: 84 85 ```shell 86 fetch global 87 | { metric 'custom.googleapis.com/cloudprober/http/google_com/latency' 88 ; metric 'custom.googleapis.com/cloudprober/http/google_com/success' } 89 | align delta(1m) 90 | join 91 | div 92 ``` 93 94 You can use MQL to create graphs and generate alerts. Note that in the examples here we are fetching from the "global" source (_fetch global_); if you're running on GCP, you can improve performance of your queries by specifying the "gce_instance" resource type: _fetch gce_instance_. 95