Skip to content

Commit

Permalink
metrics: ignore "IPC$" service-id
Browse files Browse the repository at this point in the history
Ignore the special value of "IPC$" when collecting and exporting shares'
metrics.

Signed-off-by: Shachar Sharon <[email protected]>
  • Loading branch information
synarete committed Jul 1, 2024
1 parent 3e7296f commit cb7f8b5
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion internal/metrics/smbinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ func (smbinfo *SMBInfo) TotalSessions() int {
}

func (smbinfo *SMBInfo) TotalTreeCons() int {
return len(smbinfo.smbstat.TCons)
total := 0
for _, tcon := range smbinfo.smbstat.TCons {
serviceID := tcon.Service
if isInternalServiceID(serviceID) {
continue
}
total++
}
return total
}

func (smbinfo *SMBInfo) TotalOpenFiles() int {
Expand Down Expand Up @@ -79,6 +87,9 @@ func (smbinfo *SMBInfo) MapServiceToTreeCons() map[string][]*SMBStatusTreeCon {
ret := map[string][]*SMBStatusTreeCon{}
for _, tcon := range smbinfo.smbstat.TCons {
serviceID := tcon.Service
if isInternalServiceID(serviceID) {
continue
}
tconRef := &tcon
ret[serviceID] = append(ret[serviceID], tconRef)
}
Expand All @@ -88,6 +99,10 @@ func (smbinfo *SMBInfo) MapServiceToTreeCons() map[string][]*SMBStatusTreeCon {
func (smbinfo *SMBInfo) MapMachineToTreeCons() map[string][]*SMBStatusTreeCon {
ret := map[string][]*SMBStatusTreeCon{}
for _, tcon := range smbinfo.smbstat.TCons {
serviceID := tcon.Service
if isInternalServiceID(serviceID) {
continue
}
machineID := tcon.Machine
tconRef := &tcon
ret[machineID] = append(ret[machineID], tconRef)
Expand All @@ -99,6 +114,9 @@ func (smbinfo *SMBInfo) MapServiceToMachines() map[string]map[string]int {
ret := map[string]map[string]int{}
for _, tcon := range smbinfo.smbstat.TCons {
serviceID := tcon.Service
if isInternalServiceID(serviceID) {
continue
}
machineID := tcon.Machine
sub, found := ret[serviceID]
if !found {
Expand All @@ -114,6 +132,9 @@ func (smbinfo *SMBInfo) MapMachineToServies() map[string]map[string]int {
ret := map[string]map[string]int{}
for _, tcon := range smbinfo.smbstat.TCons {
serviceID := tcon.Service
if isInternalServiceID(serviceID) {
continue
}
machineID := tcon.Machine
sub, found := ret[machineID]
if !found {
Expand All @@ -124,3 +145,7 @@ func (smbinfo *SMBInfo) MapMachineToServies() map[string]map[string]int {
}
return ret
}

func isInternalServiceID(serviceID string) bool {
return serviceID == "IPC$"
}

0 comments on commit cb7f8b5

Please sign in to comment.