Skip to content

Commit 5d78796

Browse files
committed
metrics: use smbinfo to export values
Use the newly introduce smbinfo layer to convert from raw smbstatus information into high-level Prometheus metrics representation. In particular, export a more fine grained information of active shares: show the service-id and machine-ip (address) as labels on the actual metrics-counter value. Signed-off-by: Shachar Sharon <[email protected]>
1 parent 1c4d92f commit 5d78796

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

internal/metrics/collectors.go

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,26 @@ type smbSharesCollector struct {
8484
}
8585

8686
func (col *smbSharesCollector) Collect(ch chan<- prometheus.Metric) {
87-
sharesTotal := 0
88-
sharesMap, _ := SMBStatusSharesByMachine()
89-
for machine, share := range sharesMap {
90-
sharesCount := len(share)
91-
ch <- prometheus.MustNewConstMetric(col.dsc[0],
92-
prometheus.GaugeValue, float64(sharesCount), machine)
93-
sharesTotal += sharesCount
87+
total := 0
88+
smbInfo, err := NewUpdatedSMBInfo()
89+
if err != nil {
90+
ch <- prometheus.MustNewConstMetric(col.dsc[1],
91+
prometheus.GaugeValue, float64(total))
92+
return
93+
}
94+
serviceByMachine := smbInfo.MapServiceToMachines()
95+
for serviceID, machineToCount := range serviceByMachine {
96+
for machineID, count := range machineToCount {
97+
ch <- prometheus.MustNewConstMetric(col.dsc[0],
98+
prometheus.GaugeValue,
99+
float64(count),
100+
serviceID,
101+
machineID)
102+
total += count
103+
}
94104
}
95-
96105
ch <- prometheus.MustNewConstMetric(col.dsc[1],
97-
prometheus.GaugeValue, float64(sharesTotal))
106+
prometheus.GaugeValue, float64(total))
98107
}
99108

100109
func (sme *smbMetricsExporter) newSMBSharesCollector() prometheus.Collector {
@@ -103,12 +112,12 @@ func (sme *smbMetricsExporter) newSMBSharesCollector() prometheus.Collector {
103112
col.dsc = []*prometheus.Desc{
104113
prometheus.NewDesc(
105114
collectorName("shares", "machine"),
106-
"Number of shares by host-machine ip",
107-
[]string{"machine"}, nil),
115+
"Number of currently active shares by host-machine ip",
116+
[]string{"service", "machine"}, nil),
108117

109118
prometheus.NewDesc(
110119
collectorName("shares", "total"),
111-
"Total number of active shares",
120+
"Total number of currently active shares",
112121
[]string{}, nil),
113122
}
114123
return col
@@ -119,9 +128,13 @@ type smbLocksCollector struct {
119128
}
120129

121130
func (col *smbLocksCollector) Collect(ch chan<- prometheus.Metric) {
122-
locks, _ := RunSMBStatusLocks()
131+
value := 0
132+
smbInfo, err := NewUpdatedSMBInfo()
133+
if err == nil {
134+
value = smbInfo.TotalLockedFiles()
135+
}
123136
ch <- prometheus.MustNewConstMetric(col.dsc[0],
124-
prometheus.GaugeValue, float64(len(locks)))
137+
prometheus.GaugeValue, float64(value))
125138
}
126139

127140
func (sme *smbMetricsExporter) newSMBLocksCollector() prometheus.Collector {

0 commit comments

Comments
 (0)