...
1 package metrics
2
3 import (
4 "net/http"
5 "time"
6
7 "github.com/gorilla/mux"
8 "github.com/prometheus/client_golang/prometheus"
9 "github.com/prometheus/client_golang/prometheus/promhttp"
10
11 "edge-infra.dev/pkg/k8s/runtime/controller/metrics"
12 )
13
14 var DeviceReconcileDurationMetric prometheus.HistogramVec = *prometheus.NewHistogramVec(
15 prometheus.HistogramOpts{
16 Name: metrics.Name("device_agent", "reconcile_duration_seconds"),
17 Help: "Metric for device agent reconciliation time to process device event updates",
18 Buckets: prometheus.LinearBuckets(0.0, 0.2, 10),
19 },
20 []string{"node"},
21 )
22
23 var NodeDiskBytesMetric prometheus.GaugeVec = *prometheus.NewGaugeVec(
24 prometheus.GaugeOpts{
25 Name: "node_disk_size_bytes",
26 Help: "Metric for reporting size of disks",
27 },
28 []string{"device", "node"},
29 )
30
31 func RecordDiskMetricsBytesSize(diskName, node string, size float64) {
32 NodeDiskBytesMetric.WithLabelValues(diskName, node).Set(size)
33 }
34
35 func RecordDuration(node string, duration float64) {
36 DeviceReconcileDurationMetric.WithLabelValues(node).Observe(duration)
37 }
38
39 func Server(addr string) *http.Server {
40 router := router()
41 server := &http.Server{
42 Addr: addr,
43 Handler: router,
44 ReadHeaderTimeout: 3 * time.Second,
45 }
46 return server
47 }
48
49 func router() *mux.Router {
50 r := mux.NewRouter()
51 r.PathPrefix("/metrics").Handler(promhttp.Handler())
52 return r
53 }
54
View as plain text