Skip to content

Commit 67fb65f

Browse files
committed
metrics: refine shares' counters
Define two distinct share counter-metrics: number of remote machines currently using a specific share and the number of distinct shares used by a specific remote machine (identified by IP-address). Signed-off-by: Shachar Sharon <[email protected]>
1 parent 16130ad commit 67fb65f

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

internal/metrics/collectors.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,19 @@ type smbSharesCollector struct {
151151

152152
func (col *smbSharesCollector) Collect(ch chan<- prometheus.Metric) {
153153
smbInfo, _ := NewUpdatedSMBInfo()
154-
serviceByMachine := smbInfo.MapServiceToMachines()
155-
for serviceID, machineToCount := range serviceByMachine {
156-
for machineID, count := range machineToCount {
157-
ch <- prometheus.MustNewConstMetric(col.dsc[0],
158-
prometheus.GaugeValue,
159-
float64(count),
160-
serviceID,
161-
machineID)
162-
}
154+
serviceToMachine := smbInfo.MapServiceToMachines()
155+
for service, machines := range serviceToMachine {
156+
ch <- prometheus.MustNewConstMetric(col.dsc[0],
157+
prometheus.GaugeValue,
158+
float64(len(machines)),
159+
service)
160+
}
161+
machineToServices := smbInfo.MapMachineToServies()
162+
for machine, services := range machineToServices {
163+
ch <- prometheus.MustNewConstMetric(col.dsc[1],
164+
prometheus.GaugeValue,
165+
float64(len(services)),
166+
machine)
163167
}
164168
}
165169

@@ -168,9 +172,14 @@ func (sme *smbMetricsExporter) newSMBSharesCollector() prometheus.Collector {
168172
col.sme = sme
169173
col.dsc = []*prometheus.Desc{
170174
prometheus.NewDesc(
171-
collectorName("shares", "machine"),
172-
"Number of currently active shares by host-machine ip",
173-
[]string{"service", "machine"}, nil),
175+
collectorName("share", "activity"),
176+
"Number of remote machines currently using a share",
177+
[]string{"service"}, nil),
178+
179+
prometheus.NewDesc(
180+
collectorName("share", "byremote"),
181+
"Number of shares served for remote machine",
182+
[]string{"machine"}, nil),
174183
}
175184
return col
176185
}

internal/metrics/smbinfo.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,18 @@ func (smbinfo *SMBInfo) MapServiceToMachines() map[string]map[string]int {
109109
}
110110
return ret
111111
}
112+
113+
func (smbinfo *SMBInfo) MapMachineToServies() map[string]map[string]int {
114+
ret := map[string]map[string]int{}
115+
for _, tcon := range smbinfo.smbstat.TCons {
116+
serviceID := tcon.Service
117+
machineID := tcon.Machine
118+
sub, found := ret[machineID]
119+
if !found {
120+
ret[machineID] = map[string]int{serviceID: 1}
121+
} else {
122+
sub[serviceID]++
123+
}
124+
}
125+
return ret
126+
}

0 commit comments

Comments
 (0)