google-cloud-platformgoogle-kubernetes-enginestackdrivergoogle-cloud-stackdriveropencensus

Simple hello world demo for writing custom OpenCensus metrics to StackDriver on GKE?


Is there a simple hello world sample for creating and writing custom metrics in a GKE application to StackDriver?

I see there’s a couple larger demo projects that seem to use it, like:

https://github.com/GoogleCloudPlatform/microservices-demo https://github.com/rghetia/microservices-demo/tree/oc_agent

But they seem to be different. The latter one has a DaemonSet for the oc-agent, whereas the first one appears to not have one. Also, there’s the beta Stackdriver Kubernetes Engine Monitoring, and I’m not sure if it would be done differently that way? It seems already set up a metrics server pod, as well as a prometheus-to-sd prod.


Solution

  • If you're looking to specifically write custom OpenCensus metrics to Stackdriver, there are supported Stats/Metrics and Trace exporters for Stackdriver available for OpenCensus. Examples can be found at https://opencensus.io/exporters/ .

    There is example code for stats/metrics implementation with Stackdriver specifically for Node.js, Go, and JAVA.

    And here's an example from the GCP Documentation: https://cloud.google.com/monitoring/custom-metrics/open-census