-
-
Save mosfet1kg/a46841158e36412debf1a62b636700de to your computer and use it in GitHub Desktop.
prometheus counter example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net/http" | |
"github.com/prometheus/client_golang/prometheus" | |
) | |
var ( | |
cpuTemp = prometheus.NewGauge(prometheus.GaugeOpts{ | |
Name: "cpu_temperature_celsius", | |
Help: "Current temperature of the CPU.", | |
ConstLabels: prometheus.Labels{"version": "1234"}, | |
}) | |
hdFailures = prometheus.NewCounter(prometheus.CounterOpts{ | |
Name: "hd_errors_total", | |
Help: "Number of hard-disk errors.", | |
ConstLabels: prometheus.Labels{"version": "1234"}, | |
}) | |
) | |
func init() { | |
prometheus.MustRegister(cpuTemp) | |
prometheus.MustRegister(hdFailures) | |
} | |
func main() { | |
cpuTemp.Set(65.3) | |
hdFailures.Inc() | |
http.Handle("/metrics", prometheus.Handler()) | |
http.ListenAndServe(":8080", nil) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HELP cpu_temperature_celsius Current temperature of the CPU. | |
# TYPE cpu_temperature_celsius gauge | |
cpu_temperature_celsius{version="1234"} 65.3 | |
# HELP hd_errors_total Number of hard-disk errors. | |
# TYPE hd_errors_total counter | |
hd_errors_total 1 | |
# HELP http_request_duration_microseconds The HTTP request latencies in microseconds. | |
# TYPE http_request_duration_microseconds summary | |
http_request_duration_microseconds{handler="prometheus",quantile="0.5"} 0 | |
http_request_duration_microseconds{handler="prometheus",quantile="0.9"} 0 | |
http_request_duration_microseconds{handler="prometheus",quantile="0.99"} 0 | |
http_request_duration_microseconds_sum{handler="prometheus"} 0 | |
http_request_duration_microseconds_count{handler="prometheus"} 0 | |
# HELP http_request_size_bytes The HTTP request sizes in bytes. | |
# TYPE http_request_size_bytes summary | |
http_request_size_bytes{handler="prometheus",quantile="0.5"} 0 | |
http_request_size_bytes{handler="prometheus",quantile="0.9"} 0 | |
http_request_size_bytes{handler="prometheus",quantile="0.99"} 0 | |
http_request_size_bytes_sum{handler="prometheus"} 0 | |
http_request_size_bytes_count{handler="prometheus"} 0 | |
# HELP http_response_size_bytes The HTTP response sizes in bytes. | |
# TYPE http_response_size_bytes summary | |
http_response_size_bytes{handler="prometheus",quantile="0.5"} 0 | |
http_response_size_bytes{handler="prometheus",quantile="0.9"} 0 | |
http_response_size_bytes{handler="prometheus",quantile="0.99"} 0 | |
http_response_size_bytes_sum{handler="prometheus"} 0 | |
http_response_size_bytes_count{handler="prometheus"} 0 | |
# HELP process_goroutines Number of goroutines that currently exist. | |
# TYPE process_goroutines gauge | |
process_goroutines 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment