Skip to content

Commit 7de36b7

Browse files
committed
metrics: use proper counter name for 'open_files'
Renamed to proper counter name 'smb_openfiles_total' instead of the buggy and misleading name of locked-files. Signed-off-by: Shachar Sharon <[email protected]>
1 parent 7e4aa1b commit 7de36b7

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

internal/metrics/collectors.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ func (col *smbActivityCollector) Collect(ch chan<- prometheus.Metric) {
8787
totalSessions := 0
8888
totalTreeCons := 0
8989
totalConnectedUsers := 0
90-
totalLockedFiles := 0
90+
totalOpenFiles := 0
9191
smbInfo, err := NewUpdatedSMBInfo()
9292
if err == nil {
9393
totalSessions = smbInfo.TotalSessions()
9494
totalTreeCons = smbInfo.TotalTreeCons()
9595
totalConnectedUsers = smbInfo.TotalConnectedUsers()
96-
totalLockedFiles = smbInfo.TotalLockedFiles()
96+
totalOpenFiles = smbInfo.TotalOpenFiles()
9797
}
9898
ch <- prometheus.MustNewConstMetric(col.dsc[0],
9999
prometheus.GaugeValue, float64(totalSessions))
@@ -105,7 +105,7 @@ func (col *smbActivityCollector) Collect(ch chan<- prometheus.Metric) {
105105
prometheus.GaugeValue, float64(totalConnectedUsers))
106106

107107
ch <- prometheus.MustNewConstMetric(col.dsc[3],
108-
prometheus.GaugeValue, float64(totalLockedFiles))
108+
prometheus.GaugeValue, float64(totalOpenFiles))
109109
}
110110

111111
func (sme *smbMetricsExporter) newSMBActivityCollector() prometheus.Collector {
@@ -128,8 +128,8 @@ func (sme *smbMetricsExporter) newSMBActivityCollector() prometheus.Collector {
128128
[]string{}, nil),
129129

130130
prometheus.NewDesc(
131-
collectorName("locks", "total"),
132-
"Number of currently active file-locks",
131+
collectorName("openfiles", "total"),
132+
"Number of currently open files",
133133
[]string{}, nil),
134134
}
135135
return col

internal/metrics/smbinfo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func (smbinfo *SMBInfo) TotalTreeCons() int {
3636
return len(smbinfo.smbstat.TCons)
3737
}
3838

39-
func (smbinfo *SMBInfo) TotalLockedFiles() int {
40-
return len(smbinfo.smbstat.LockedFiles)
39+
func (smbinfo *SMBInfo) TotalOpenFiles() int {
40+
return len(smbinfo.smbstat.OpenFiles)
4141
}
4242

4343
func (smbinfo *SMBInfo) TotalConnectedUsers() int {

internal/metrics/smbstatus.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ type SMBStatusFileID struct {
6868
Extid int32 `json:"extid"`
6969
}
7070

71-
// SMBStatusLockedFile represents a locked-file output field
72-
type SMBStatusLockedFile struct {
71+
// SMBStatusOpenFile represents a open-file output field
72+
type SMBStatusOpenFile struct {
7373
ServicePath string `json:"service_path"`
7474
Filename string `json:"filename"`
7575
FileID SMBStatusFileID `json:"fileid"`
@@ -78,20 +78,20 @@ type SMBStatusLockedFile struct {
7878

7979
// SMBStatus represents output of 'smbstatus --json'
8080
type SMBStatus struct {
81-
Timestamp string `json:"timestamp"`
82-
Version string `json:"version"`
83-
SmbConf string `json:"smb_conf"`
84-
Sessions map[string]SMBStatusSession `json:"sessions"`
85-
TCons map[string]SMBStatusTreeCon `json:"tcons"`
86-
LockedFiles map[string]SMBStatusLockedFile `json:"locked_files"`
81+
Timestamp string `json:"timestamp"`
82+
Version string `json:"version"`
83+
SmbConf string `json:"smb_conf"`
84+
Sessions map[string]SMBStatusSession `json:"sessions"`
85+
TCons map[string]SMBStatusTreeCon `json:"tcons"`
86+
OpenFiles map[string]SMBStatusOpenFile `json:"open_files"`
8787
}
8888

8989
// SMBStatusLocks represents output of 'smbstatus -L --json'
9090
type SMBStatusLocks struct {
91-
Timestamp string `json:"timestamp"`
92-
Version string `json:"version"`
93-
SmbConf string `json:"smb_conf"`
94-
OpenFiles map[string]SMBStatusLockedFile `json:"open_files"`
91+
Timestamp string `json:"timestamp"`
92+
Version string `json:"version"`
93+
SmbConf string `json:"smb_conf"`
94+
OpenFiles map[string]SMBStatusOpenFile `json:"open_files"`
9595
}
9696

9797
// LocateSMBStatus finds the local executable of 'smbstatus' on host.
@@ -155,16 +155,16 @@ func parseSMBStatusTreeCons(dat string) ([]SMBStatusTreeCon, error) {
155155
}
156156

157157
// RunSMBStatusLocks executes 'smbstatus --locks --json' on host
158-
func RunSMBStatusLocks() ([]SMBStatusLockedFile, error) {
158+
func RunSMBStatusLocks() ([]SMBStatusOpenFile, error) {
159159
dat, err := executeSMBStatusCommand("--locks --json")
160160
if err != nil {
161-
return []SMBStatusLockedFile{}, err
161+
return []SMBStatusOpenFile{}, err
162162
}
163163
return parseSMBStatusLockedFiles(dat)
164164
}
165165

166-
func parseSMBStatusLockedFiles(dat string) ([]SMBStatusLockedFile, error) {
167-
lockedFiles := []SMBStatusLockedFile{}
166+
func parseSMBStatusLockedFiles(dat string) ([]SMBStatusOpenFile, error) {
167+
lockedFiles := []SMBStatusOpenFile{}
168168
res, err := parseSMBStatusLocks(dat)
169169
if err != nil {
170170
return lockedFiles, err
@@ -230,12 +230,12 @@ func parseSMBStatusLocks(data string) (*SMBStatusLocks, error) {
230230
// NewSMBStatus returns non-populated SMBStatus object
231231
func NewSMBStatus() *SMBStatus {
232232
smbStatus := SMBStatus{
233-
Timestamp: "",
234-
Version: "",
235-
SmbConf: "",
236-
Sessions: map[string]SMBStatusSession{},
237-
TCons: map[string]SMBStatusTreeCon{},
238-
LockedFiles: map[string]SMBStatusLockedFile{},
233+
Timestamp: "",
234+
Version: "",
235+
SmbConf: "",
236+
Sessions: map[string]SMBStatusSession{},
237+
TCons: map[string]SMBStatusTreeCon{},
238+
OpenFiles: map[string]SMBStatusOpenFile{},
239239
}
240240
return &smbStatus
241241
}

internal/metrics/smbstatus_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ var (
147147
}
148148
}
149149
},
150-
"locked_files": {
150+
"open_files": {
151151
"/home/janger/testfolder/hallo": {
152152
"service_path": "/home/janger/testfolder",
153153
"filename": "hallo",
@@ -267,7 +267,7 @@ var (
267267
}
268268
}
269269
},
270-
"locked_files": {
270+
"open_files": {
271271
"/mnt/96dd85fd-6c60-409c-bc1c-15f98eb358ee/a/y": {
272272
"service_path": "/mnt/96dd85fd-6c60-409c-bc1c-15f98eb358ee",
273273
"filename": "a/y",
@@ -584,11 +584,11 @@ func TestParseSMBStatusAll(t *testing.T) {
584584
assert.NoError(t, err)
585585
assert.Equal(t, len(dat.Sessions), 1)
586586
assert.Equal(t, len(dat.TCons), 1)
587-
assert.Equal(t, len(dat.LockedFiles), 1)
587+
assert.Equal(t, len(dat.OpenFiles), 1)
588588

589589
dat2, err := parseSMBStatus(smbstatusOutput4)
590590
assert.NoError(t, err)
591-
assert.Equal(t, len(dat2.LockedFiles), 2)
591+
assert.Equal(t, len(dat2.OpenFiles), 2)
592592
}
593593

594594
func TestParseSMBStatusLocks(t *testing.T) {

0 commit comments

Comments
 (0)