Custom metrics prometheus exporter source code

Stay organized with collections Save and categorize content based on your preferences.

Source code for custom prometheus exporter to Cloud Monitoring.

Code sample

Go

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.