Skip to content

Commit 3ccf4fe

Browse files
committed
metrics: export using explicit values
Labels can not be used in order to plot graphs based on metrics. Export various smb profile stats as explicit metric values, where only the operation name is used as label. Use helper mapping from operation name to entry when emitting output metrics in order to avoid boilerplate code. Signed-off-by: Shachar Sharon <ssharon@redhat.com>
1 parent 8f3ddd3 commit 3ccf4fe

File tree

1 file changed

+176
-78
lines changed

1 file changed

+176
-78
lines changed

internal/metrics/collectors.go

Lines changed: 176 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
package metrics
44

55
import (
6-
"strconv"
7-
86
"github.com/prometheus/client_golang/prometheus"
97
)
108

@@ -151,7 +149,6 @@ type smbProfileCollector struct {
151149
smbCollector
152150
}
153151

154-
//nolint:funlen
155152
func (col *smbProfileCollector) Collect(ch chan<- prometheus.Metric) {
156153
if !col.sme.profile {
157154
return
@@ -162,99 +159,176 @@ func (col *smbProfileCollector) Collect(ch chan<- prometheus.Metric) {
162159
}
163160
smb2Calls := smbProfileInfo.profileStatus.SMB2Calls
164161
if smb2Calls != nil {
165-
ch <- col.smb2RequestMetric(&smb2Calls.NegProt, "negprot")
166-
ch <- col.smb2RequestMetric(&smb2Calls.SessSetup, "sesssetup")
167-
ch <- col.smb2RequestMetric(&smb2Calls.LogOff, "logoff")
168-
ch <- col.smb2RequestMetric(&smb2Calls.Tcon, "tcon")
169-
ch <- col.smb2RequestMetric(&smb2Calls.Tdis, "tdis")
170-
ch <- col.smb2RequestMetric(&smb2Calls.Create, "create")
171-
ch <- col.smb2RequestMetric(&smb2Calls.Close, "close")
172-
ch <- col.smb2RequestMetric(&smb2Calls.Flush, "flush")
173-
ch <- col.smb2RequestMetric(&smb2Calls.Read, "read")
174-
ch <- col.smb2RequestMetric(&smb2Calls.Write, "write")
175-
ch <- col.smb2RequestMetric(&smb2Calls.Lock, "lock")
176-
ch <- col.smb2RequestMetric(&smb2Calls.Ioctl, "ioctl")
177-
ch <- col.smb2RequestMetric(&smb2Calls.Cancel, "cancel")
178-
ch <- col.smb2RequestMetric(&smb2Calls.KeepAlive, "keepalive")
179-
ch <- col.smb2RequestMetric(&smb2Calls.Find, "find")
180-
ch <- col.smb2RequestMetric(&smb2Calls.Notify, "notify")
181-
ch <- col.smb2RequestMetric(&smb2Calls.GetInfo, "getinfo")
182-
ch <- col.smb2RequestMetric(&smb2Calls.SetInfo, "setinfo")
183-
ch <- col.smb2RequestMetric(&smb2Calls.Break, "break")
162+
col.collectSMB2CallsMetrics(ch, smb2Calls)
184163
}
185164
sysCalls := smbProfileInfo.profileStatus.SystemCalls
186165
if sysCalls != nil {
187-
ch <- col.vfsIORequestMetric(&sysCalls.PRead, "pread")
188-
ch <- col.vfsIORequestMetric(&sysCalls.AsysPRead, "asys_pread")
189-
ch <- col.vfsIORequestMetric(&sysCalls.PWrite, "pwrite")
190-
ch <- col.vfsIORequestMetric(&sysCalls.AsysPWrite, "asys_pwrite")
191-
ch <- col.vfsIORequestMetric(&sysCalls.AsysFSync, "asys_fsync")
192-
ch <- col.vfsRequestMetric(&sysCalls.Opendir, "opendir")
193-
ch <- col.vfsRequestMetric(&sysCalls.FDOpendir, "fdopendir")
194-
ch <- col.vfsRequestMetric(&sysCalls.Readdir, "readdir")
195-
ch <- col.vfsRequestMetric(&sysCalls.Rewinddir, "rewinddir")
196-
ch <- col.vfsRequestMetric(&sysCalls.Mkdirat, "mkdirat")
197-
ch <- col.vfsRequestMetric(&sysCalls.Closedir, "closedir")
198-
ch <- col.vfsRequestMetric(&sysCalls.Open, "open")
199-
ch <- col.vfsRequestMetric(&sysCalls.OpenAt, "openat")
200-
ch <- col.vfsRequestMetric(&sysCalls.CreateFile, "createfile")
201-
ch <- col.vfsRequestMetric(&sysCalls.Close, "close")
202-
ch <- col.vfsRequestMetric(&sysCalls.Lseek, "lseek")
203-
ch <- col.vfsRequestMetric(&sysCalls.RenameAt, "renameat")
204-
ch <- col.vfsRequestMetric(&sysCalls.Stat, "stat")
205-
ch <- col.vfsRequestMetric(&sysCalls.FStat, "fstat")
206-
ch <- col.vfsRequestMetric(&sysCalls.LStat, "lstat")
207-
ch <- col.vfsRequestMetric(&sysCalls.FStatAt, "fstatat")
208-
ch <- col.vfsRequestMetric(&sysCalls.UnlinkAt, "unlinkat")
209-
ch <- col.vfsRequestMetric(&sysCalls.Chmod, "chmod")
210-
ch <- col.vfsRequestMetric(&sysCalls.FChmod, "fchmod")
211-
ch <- col.vfsRequestMetric(&sysCalls.FChown, "fchown")
212-
ch <- col.vfsRequestMetric(&sysCalls.LChown, "lchown")
213-
ch <- col.vfsRequestMetric(&sysCalls.Chdir, "chdir")
214-
ch <- col.vfsRequestMetric(&sysCalls.GetWD, "getwd")
215-
ch <- col.vfsRequestMetric(&sysCalls.Fntimes, "fntimes")
216-
ch <- col.vfsRequestMetric(&sysCalls.FTruncate, "ftruncate")
217-
ch <- col.vfsRequestMetric(&sysCalls.FAllocate, "fallocate")
218-
ch <- col.vfsRequestMetric(&sysCalls.ReadLinkAt, "readlinkat")
219-
ch <- col.vfsRequestMetric(&sysCalls.SymLinkAt, "symlinkat")
220-
ch <- col.vfsRequestMetric(&sysCalls.LinkAt, "linkat")
221-
ch <- col.vfsRequestMetric(&sysCalls.MknodAt, "mknodat")
222-
ch <- col.vfsRequestMetric(&sysCalls.RealPath, "realpath")
166+
col.collectSysCallsMetrics(ch, sysCalls)
223167
}
224168
}
225169

226-
func (col *smbProfileCollector) smb2RequestMetric(pce *SMBProfileCallEntry,
227-
operation string) prometheus.Metric {
170+
func (col *smbProfileCollector) collectSMB2CallsMetrics(
171+
ch chan<- prometheus.Metric, smb2Calls *SMBProfileSMB2Calls) {
172+
operationToProfileCallEntry := map[string]*SMBProfileCallEntry{
173+
"negprot": &smb2Calls.NegProt,
174+
"sesssetup": &smb2Calls.SessSetup,
175+
"logoff": &smb2Calls.LogOff,
176+
"tcon": &smb2Calls.Tcon,
177+
"tdis": &smb2Calls.Tdis,
178+
"create": &smb2Calls.Create,
179+
"close": &smb2Calls.Close,
180+
"flush": &smb2Calls.Flush,
181+
"read": &smb2Calls.Read,
182+
"write": &smb2Calls.Write,
183+
"lock": &smb2Calls.Lock,
184+
"ioctl": &smb2Calls.Ioctl,
185+
"cancel": &smb2Calls.Cancel,
186+
"keepalive": &smb2Calls.KeepAlive,
187+
"find": &smb2Calls.Find,
188+
"notify": &smb2Calls.Notify,
189+
"getinfo": &smb2Calls.GetInfo,
190+
"setinfo": &smb2Calls.SetInfo,
191+
"break": &smb2Calls.Break,
192+
}
193+
for op, pce := range operationToProfileCallEntry {
194+
ch <- col.smb2RequestTotalMetric(op, pce)
195+
ch <- col.smb2RequestInbytesMetric(op, pce)
196+
ch <- col.smb2RequestOutbytesMetric(op, pce)
197+
ch <- col.smb2RequestDurationMetric(op, pce)
198+
}
199+
}
200+
201+
func (col *smbProfileCollector) collectSysCallsMetrics(
202+
ch chan<- prometheus.Metric, sysCalls *SMBProfileSyscalls) {
203+
operationToProfileIOEntry := map[string]*SMBProfileIOEntry{
204+
"pread": &sysCalls.PRead,
205+
"asys_pread": &sysCalls.AsysPRead,
206+
"pwrite": &sysCalls.PWrite,
207+
"asys_pwrite": &sysCalls.AsysPWrite,
208+
"asys_fsync": &sysCalls.AsysFSync,
209+
}
210+
operationToProfileEntry := map[string]*SMBProfileEntry{
211+
"opendir": &sysCalls.Opendir,
212+
"fdopendir": &sysCalls.FDOpendir,
213+
"readdir": &sysCalls.Readdir,
214+
"rewinddir": &sysCalls.Rewinddir,
215+
"mkdirat": &sysCalls.Mkdirat,
216+
"closedir": &sysCalls.Closedir,
217+
"open": &sysCalls.Open,
218+
"openat": &sysCalls.OpenAt,
219+
"createfile": &sysCalls.CreateFile,
220+
"close": &sysCalls.Close,
221+
"lseek": &sysCalls.Lseek,
222+
"renameat": &sysCalls.RenameAt,
223+
"stat": &sysCalls.Stat,
224+
"fstat": &sysCalls.FStat,
225+
"lstat": &sysCalls.LStat,
226+
"fstatat": &sysCalls.FStatAt,
227+
"unlinkat": &sysCalls.UnlinkAt,
228+
"chmod": &sysCalls.Chmod,
229+
"fchmod": &sysCalls.FChmod,
230+
"fchown": &sysCalls.FChown,
231+
"lchown": &sysCalls.LChown,
232+
"chdir": &sysCalls.Chdir,
233+
"getwd": &sysCalls.GetWD,
234+
"fntimes": &sysCalls.Fntimes,
235+
"ftruncate": &sysCalls.FTruncate,
236+
"fallocate": &sysCalls.FAllocate,
237+
"readlinkat": &sysCalls.ReadLinkAt,
238+
"symlinkat": &sysCalls.SymLinkAt,
239+
"linkat": &sysCalls.LinkAt,
240+
"mknodat": &sysCalls.MknodAt,
241+
"realpath": &sysCalls.RealPath,
242+
}
243+
for op, pioe := range operationToProfileIOEntry {
244+
ch <- col.vfsIOTotalMetric(op, pioe)
245+
ch <- col.vfsIOBytesMetric(op, pioe)
246+
ch <- col.vfsIODurationMetric(op, pioe)
247+
}
248+
for op, pe := range operationToProfileEntry {
249+
ch <- col.vfsTotalMetric(op, pe)
250+
ch <- col.vfsDurationMetric(op, pe)
251+
}
252+
}
253+
254+
func (col *smbProfileCollector) smb2RequestTotalMetric(operation string,
255+
pce *SMBProfileCallEntry) prometheus.Metric {
228256
return prometheus.MustNewConstMetric(
229257
col.dsc[0],
230258
prometheus.GaugeValue,
231259
float64(pce.Count),
232-
strconv.Itoa(pce.Time),
233-
strconv.Itoa(pce.Idle),
234-
strconv.Itoa(pce.Inbytes),
235-
strconv.Itoa(pce.Outbytes),
236260
operation)
237261
}
238262

239-
func (col *smbProfileCollector) vfsIORequestMetric(pioe *SMBProfileIOEntry,
240-
operation string) prometheus.Metric {
263+
func (col *smbProfileCollector) smb2RequestInbytesMetric(operation string,
264+
pce *SMBProfileCallEntry) prometheus.Metric {
241265
return prometheus.MustNewConstMetric(
242266
col.dsc[1],
243267
prometheus.GaugeValue,
244-
float64(pioe.Count),
245-
strconv.Itoa(pioe.Time),
246-
strconv.Itoa(pioe.Idle),
247-
strconv.Itoa(pioe.Bytes),
268+
float64(pce.Inbytes),
248269
operation)
249270
}
250271

251-
func (col *smbProfileCollector) vfsRequestMetric(pe *SMBProfileEntry,
252-
operation string) prometheus.Metric {
272+
func (col *smbProfileCollector) smb2RequestOutbytesMetric(operation string,
273+
pce *SMBProfileCallEntry) prometheus.Metric {
253274
return prometheus.MustNewConstMetric(
254275
col.dsc[2],
255276
prometheus.GaugeValue,
277+
float64(pce.Outbytes),
278+
operation)
279+
}
280+
281+
func (col *smbProfileCollector) smb2RequestDurationMetric(operation string,
282+
pce *SMBProfileCallEntry) prometheus.Metric {
283+
return prometheus.MustNewConstMetric(
284+
col.dsc[3],
285+
prometheus.GaugeValue,
286+
float64(pce.Time),
287+
operation)
288+
}
289+
290+
func (col *smbProfileCollector) vfsIOTotalMetric(operation string,
291+
pioe *SMBProfileIOEntry) prometheus.Metric {
292+
return prometheus.MustNewConstMetric(
293+
col.dsc[4],
294+
prometheus.GaugeValue,
295+
float64(pioe.Count),
296+
operation)
297+
}
298+
299+
func (col *smbProfileCollector) vfsIOBytesMetric(operation string,
300+
pioe *SMBProfileIOEntry) prometheus.Metric {
301+
return prometheus.MustNewConstMetric(
302+
col.dsc[5],
303+
prometheus.GaugeValue,
304+
float64(pioe.Bytes),
305+
operation)
306+
}
307+
308+
func (col *smbProfileCollector) vfsIODurationMetric(operation string,
309+
pioe *SMBProfileIOEntry) prometheus.Metric {
310+
return prometheus.MustNewConstMetric(
311+
col.dsc[6],
312+
prometheus.GaugeValue,
313+
float64(pioe.Time),
314+
operation)
315+
}
316+
317+
func (col *smbProfileCollector) vfsTotalMetric(operation string,
318+
pe *SMBProfileEntry) prometheus.Metric {
319+
return prometheus.MustNewConstMetric(
320+
col.dsc[7],
321+
prometheus.GaugeValue,
256322
float64(pe.Count),
257-
strconv.Itoa(pe.Time),
323+
operation)
324+
}
325+
326+
func (col *smbProfileCollector) vfsDurationMetric(operation string,
327+
pe *SMBProfileEntry) prometheus.Metric {
328+
return prometheus.MustNewConstMetric(
329+
col.dsc[8],
330+
prometheus.GaugeValue,
331+
float64(pe.Time),
258332
operation)
259333
}
260334

@@ -265,15 +339,39 @@ func (sme *smbMetricsExporter) newSMBProfileCollector() prometheus.Collector {
265339
prometheus.NewDesc(
266340
collectorName("smb2", "request_total"),
267341
"Total number of SMB2 requests",
268-
[]string{"time", "idle", "inbytes", "outbytes", "operation"}, nil),
342+
[]string{"operation"}, nil),
269343
prometheus.NewDesc(
270-
collectorName("vfs_io", "call_total"),
344+
collectorName("smb2", "request_inbytes"),
345+
"Bytes received for SMB2 requests",
346+
[]string{"operation"}, nil),
347+
prometheus.NewDesc(
348+
collectorName("smb2", "request_outbytes"),
349+
"Bytes replied for SMB2 requests",
350+
[]string{"operation"}, nil),
351+
prometheus.NewDesc(
352+
collectorName("smb2", "request_duration_microseconds_sum"),
353+
"Execution time in microseconds of SMB2 requests",
354+
[]string{"operation"}, nil),
355+
prometheus.NewDesc(
356+
collectorName("vfs_io", "total"),
271357
"Total number of I/O calls to underlying VFS layer",
272-
[]string{"time", "idle", "bytes", "operation"}, nil),
358+
[]string{"operation"}, nil),
273359
prometheus.NewDesc(
274-
collectorName("vfs", "call_total"),
360+
collectorName("vfs_io", "bytes"),
361+
"Number of bytes transferred via underlying VFS I/O layer",
362+
[]string{"operation"}, nil),
363+
prometheus.NewDesc(
364+
collectorName("vfs_io", "duration_microseconds_sum"),
365+
"Execution time in microseconds of VFS I/O requests",
366+
[]string{"operation"}, nil),
367+
prometheus.NewDesc(
368+
collectorName("vfs", "total"),
275369
"Total number of calls to underlying VFS layer",
276-
[]string{"time", "operation"}, nil),
370+
[]string{"operation"}, nil),
371+
prometheus.NewDesc(
372+
collectorName("vfs", "duration_microseconds_sum"),
373+
"Execution time in microseconds of VFS requests",
374+
[]string{"operation"}, nil),
277375
}
278376

279377
return col

0 commit comments

Comments
 (0)