Skip to content

Commit 7e4aa1b

Browse files
committed
metrics: defined activity collector
Defined a new metrics collector-and-exporter which provide top-level overview on the current activity of the local Samba-server. This exporter represents the first layer of SMB counters which are exported to Prometheus. Signed-off-by: Shachar Sharon <[email protected]>
1 parent 5d78796 commit 7e4aa1b

File tree

1 file changed

+56
-40
lines changed

1 file changed

+56
-40
lines changed

internal/metrics/collectors.go

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ var (
1313
func (sme *smbMetricsExporter) register() error {
1414
cols := []prometheus.Collector{
1515
sme.newSMBVersionsCollector(),
16+
sme.newSMBActivityCollector(),
1617
sme.newSMBSharesCollector(),
17-
sme.newSMBLocksCollector(),
1818
}
1919
for _, c := range cols {
2020
if err := sme.reg.Register(c); err != nil {
@@ -79,72 +79,88 @@ func (sme *smbMetricsExporter) newSMBVersionsCollector() prometheus.Collector {
7979
return col
8080
}
8181

82-
type smbSharesCollector struct {
82+
type smbActivityCollector struct {
8383
smbCollector
8484
}
8585

86-
func (col *smbSharesCollector) Collect(ch chan<- prometheus.Metric) {
87-
total := 0
86+
func (col *smbActivityCollector) Collect(ch chan<- prometheus.Metric) {
87+
totalSessions := 0
88+
totalTreeCons := 0
89+
totalConnectedUsers := 0
90+
totalLockedFiles := 0
8891
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-
}
92+
if err == nil {
93+
totalSessions = smbInfo.TotalSessions()
94+
totalTreeCons = smbInfo.TotalTreeCons()
95+
totalConnectedUsers = smbInfo.TotalConnectedUsers()
96+
totalLockedFiles = smbInfo.TotalLockedFiles()
10497
}
98+
ch <- prometheus.MustNewConstMetric(col.dsc[0],
99+
prometheus.GaugeValue, float64(totalSessions))
100+
105101
ch <- prometheus.MustNewConstMetric(col.dsc[1],
106-
prometheus.GaugeValue, float64(total))
102+
prometheus.GaugeValue, float64(totalTreeCons))
103+
104+
ch <- prometheus.MustNewConstMetric(col.dsc[2],
105+
prometheus.GaugeValue, float64(totalConnectedUsers))
106+
107+
ch <- prometheus.MustNewConstMetric(col.dsc[3],
108+
prometheus.GaugeValue, float64(totalLockedFiles))
107109
}
108110

109-
func (sme *smbMetricsExporter) newSMBSharesCollector() prometheus.Collector {
110-
col := &smbSharesCollector{}
111+
func (sme *smbMetricsExporter) newSMBActivityCollector() prometheus.Collector {
112+
col := &smbActivityCollector{}
111113
col.sme = sme
112114
col.dsc = []*prometheus.Desc{
113115
prometheus.NewDesc(
114-
collectorName("shares", "machine"),
115-
"Number of currently active shares by host-machine ip",
116-
[]string{"service", "machine"}, nil),
116+
collectorName("sessions", "total"),
117+
"Number of currently active SMB sessions",
118+
[]string{}, nil),
119+
120+
prometheus.NewDesc(
121+
collectorName("tcon", "total"),
122+
"Number of currently active SMB tree-connections",
123+
[]string{}, nil),
117124

118125
prometheus.NewDesc(
119-
collectorName("shares", "total"),
120-
"Total number of currently active shares",
126+
collectorName("users", "total"),
127+
"Number of currently active SMB users",
128+
[]string{}, nil),
129+
130+
prometheus.NewDesc(
131+
collectorName("locks", "total"),
132+
"Number of currently active file-locks",
121133
[]string{}, nil),
122134
}
123135
return col
124136
}
125137

126-
type smbLocksCollector struct {
138+
type smbSharesCollector struct {
127139
smbCollector
128140
}
129141

130-
func (col *smbLocksCollector) Collect(ch chan<- prometheus.Metric) {
131-
value := 0
132-
smbInfo, err := NewUpdatedSMBInfo()
133-
if err == nil {
134-
value = smbInfo.TotalLockedFiles()
142+
func (col *smbSharesCollector) Collect(ch chan<- prometheus.Metric) {
143+
smbInfo, _ := NewUpdatedSMBInfo()
144+
serviceByMachine := smbInfo.MapServiceToMachines()
145+
for serviceID, machineToCount := range serviceByMachine {
146+
for machineID, count := range machineToCount {
147+
ch <- prometheus.MustNewConstMetric(col.dsc[0],
148+
prometheus.GaugeValue,
149+
float64(count),
150+
serviceID,
151+
machineID)
152+
}
135153
}
136-
ch <- prometheus.MustNewConstMetric(col.dsc[0],
137-
prometheus.GaugeValue, float64(value))
138154
}
139155

140-
func (sme *smbMetricsExporter) newSMBLocksCollector() prometheus.Collector {
141-
col := &smbLocksCollector{}
156+
func (sme *smbMetricsExporter) newSMBSharesCollector() prometheus.Collector {
157+
col := &smbSharesCollector{}
142158
col.sme = sme
143159
col.dsc = []*prometheus.Desc{
144160
prometheus.NewDesc(
145-
collectorName("locks", "total"),
146-
"Total number of active locks",
147-
[]string{}, nil),
161+
collectorName("shares", "machine"),
162+
"Number of currently active shares by host-machine ip",
163+
[]string{"service", "machine"}, nil),
148164
}
149165
return col
150166
}

0 commit comments

Comments
 (0)