diff --git a/sensor-exporter/main.go b/sensor-exporter/main.go new file mode 100644 index 0000000..9e70a0a --- /dev/null +++ b/sensor-exporter/main.go @@ -0,0 +1,76 @@ +package main + +import ( + "flag" + "net/http" + _ "net/http/pprof" + "strings" + "time" + + "github.com/md14454/gosensors" + "github.com/prometheus/client_golang/prometheus" +) + +var ( + fanspeed = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: "sensor", + Subsystem: "lm", + Name: "fan_speed_rpm", + Help: "fan speed (rotations per minute).", + }, []string{"fantype", "chip", "adaptor"}) + + temperature = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: "sensor", + Subsystem: "lm", + Name: "temperature_celsius", + Help: "temperature in celsius", + }, []string{"temptype", "chip", "adaptor"}) +) + +func init() { + prometheus.MustRegister(fanspeed) + prometheus.MustRegister(temperature) +} + +func main() { + var ( + listenAddress = flag.String("web.listen-address", ":9255", "Address on which to expose metrics and web interface.") + metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.") + ) + flag.Parse() + + go collect() + + http.Handle(*metricsPath, prometheus.Handler()) + + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte(` +