Skip to content

Commit 16130ad

Browse files
committed
metrics: export number of open-files by mode
Provides two new metrics: number of total open-file in RO/RW modes. Uses the detailed SMB information provided by 'open_files' section per file. Signed-off-by: Shachar Sharon <[email protected]>
1 parent 0aedee4 commit 16130ad

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

internal/metrics/collectors.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ func (col *smbActivityCollector) Collect(ch chan<- prometheus.Metric) {
8888
totalTreeCons := 0
8989
totalConnectedUsers := 0
9090
totalOpenFiles := 0
91+
totalOpenFilesAccessRW := 0
9192
smbInfo, err := NewUpdatedSMBInfo()
9293
if err == nil {
9394
totalSessions = smbInfo.TotalSessions()
9495
totalTreeCons = smbInfo.TotalTreeCons()
9596
totalConnectedUsers = smbInfo.TotalConnectedUsers()
9697
totalOpenFiles = smbInfo.TotalOpenFiles()
98+
totalOpenFilesAccessRW = smbInfo.TotalOpenFilesAccessRW()
9799
}
98100
ch <- prometheus.MustNewConstMetric(col.dsc[0],
99101
prometheus.GaugeValue, float64(totalSessions))
@@ -106,6 +108,9 @@ func (col *smbActivityCollector) Collect(ch chan<- prometheus.Metric) {
106108

107109
ch <- prometheus.MustNewConstMetric(col.dsc[3],
108110
prometheus.GaugeValue, float64(totalOpenFiles))
111+
112+
ch <- prometheus.MustNewConstMetric(col.dsc[4],
113+
prometheus.GaugeValue, float64(totalOpenFilesAccessRW))
109114
}
110115

111116
func (sme *smbMetricsExporter) newSMBActivityCollector() prometheus.Collector {
@@ -131,6 +136,11 @@ func (sme *smbMetricsExporter) newSMBActivityCollector() prometheus.Collector {
131136
collectorName("openfiles", "total"),
132137
"Number of currently open files",
133138
[]string{}, nil),
139+
140+
prometheus.NewDesc(
141+
collectorName("openfiles", "access_rw"),
142+
"Number of open files with read-write access mode",
143+
[]string{}, nil),
134144
}
135145
return col
136146
}

internal/metrics/smbinfo.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
package metrics
44

5+
import "strings"
6+
57
// SMBInfo provides a bridge layer between raw smbstatus info and exported
68
// metric counters. It also implements the more complex logic which requires in
79
// memory re-mapping of the low-level information (e.g., stats by machine/user).
@@ -40,6 +42,18 @@ func (smbinfo *SMBInfo) TotalOpenFiles() int {
4042
return len(smbinfo.smbstat.OpenFiles)
4143
}
4244

45+
func (smbinfo *SMBInfo) TotalOpenFilesAccessRW() int {
46+
total := 0
47+
for _, openf := range smbinfo.smbstat.OpenFiles {
48+
for _, opens := range openf.Opens {
49+
if strings.Contains(opens.AccessMask.Text, "RW") {
50+
total++
51+
}
52+
}
53+
}
54+
return total
55+
}
56+
4357
func (smbinfo *SMBInfo) TotalConnectedUsers() int {
4458
users := map[string]bool{}
4559
for _, session := range smbinfo.smbstat.Sessions {

0 commit comments

Comments
 (0)