-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
102 lines (81 loc) · 2.2 KB
/
Copy pathmain.go
File metadata and controls
102 lines (81 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"bufio"
"flag"
"log"
"net/http"
"os"
"strings"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
listenAddr = flag.String("listen-address", ":9100", "The address to listen on for HTTP requests.")
mountsTotal = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ce_node_mounts_total",
Help: "Total number of mount points on the node",
},
[]string{"type"},
)
)
func init() {
prometheus.MustRegister(mountsTotal)
}
func getMountInfo() error {
file, err := os.Open("/proc/mounts")
if err != nil {
return err
}
defer file.Close()
mountCounts := make(map[string]float64)
var cefs1Count float64
var cefs2Count float64
scanner := bufio.NewScanner(file)
for scanner.Scan() {
fields := strings.Fields(scanner.Text())
if len(fields) < 3 {
continue
}
mountpoint := fields[1]
fstype := fields[2]
mountCounts[fstype]++
mountCounts["all"]++
// Count CEFS1 mounts at /efs/compiler-explorer/ with type squashfs
if strings.HasPrefix(mountpoint, "/efs/compiler-explorer/") && fstype == "squashfs" {
cefs1Count++
}
// Count CEFS2 mounts at /cefs/XX/* where XX is any 2-char hash prefix (these are from /efs/cefs-images)
// Pattern: /cefs/XX/... where XX is exactly 2 characters
if len(mountpoint) > 9 && mountpoint[8] == '/' && strings.HasPrefix(mountpoint, "/cefs/") {
cefs2Count++
}
}
for fstype, count := range mountCounts {
mountsTotal.WithLabelValues(fstype).Set(count)
}
// Add CEFS1 and CEFS2 counts as separate types
mountsTotal.WithLabelValues("cefs1").Set(cefs1Count)
mountsTotal.WithLabelValues("cefs2").Set(cefs2Count)
return scanner.Err()
}
func collectMetrics() {
if err := getMountInfo(); err != nil {
log.Printf("Error collecting mount info: %v", err)
}
}
func main() {
help := flag.Bool("help", false, "Show help message")
flag.Parse()
if *help {
flag.Usage()
os.Exit(0)
}
collectMetrics()
http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
collectMetrics()
promhttp.Handler().ServeHTTP(w, r)
})
log.Printf("Starting CE Node Exporter on %s", *listenAddr)
log.Fatal(http.ListenAndServe(*listenAddr, nil))
}