Custom metrics prometheus exporter source code

Source code for custom prometheus exporter to Cloud Monitoring.

Code sample

Go

To authenticate to GKE, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

metric := prometheus.NewGauge(
	prometheus.GaugeOpts{
		Name: *metricName,
		Help: "Custom metric",
	},
)
prometheus.MustRegister(metric)
metric.Set(float64(*metricValue))

http.Handle("/metrics", promhttp.Handler())
log.Printf("Starting to listen on :%d", *port)
err := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.