Skip to content

Commit baf3c42

Browse files
niemp100Niklas EmptNiklas Empt
authored
Pdh output adaptions (#227)
Co-authored-by: Niklas Empt <[email protected]> Co-authored-by: Niklas Empt <[email protected]>
1 parent a824555 commit baf3c42

14 files changed

+30
-1281
lines changed

.golangci.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,4 @@ issues:
146146
linters:
147147
- nolintlint
148148
exclude-files:
149-
- pkg/pdh/pdh.go
150-
- pkg/utils/common.go
151-
- pkg/utils/common_windows.go
152-
- pkg/wincpu/cpu_windows.go
153-
- pkg/wincpu/cpu.go
154-
149+
- pkg/pdh/pdh.go

docs/checks/commands/check_pdh.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ Naemon Config
4141

4242
## Check Specific Arguments
4343

44-
| Argument | Description |
45-
| ------------ | ------------------------------------------------------------------------------------------------------ |
46-
| Counter | The fully qualified Counter Name |
47-
| counter | The fully qualified Counter Name |
48-
| english | Using English Names Regardless of system Language requires Windows Vista or higher |
49-
| expand-index | Should Indices be translated? |
50-
| host | The Name Of the Host Mashine in Network where the Counter should be searched, defults to local mashine |
51-
| instances | Expand WildCards And Fethch all instances |
52-
| type | this can be large or float depending what you expect, default is large |
44+
| Argument | Description |
45+
| ------------ | -------------------------------------------------------------------------------------------------- |
46+
| Counter | The fully qualified counter Name |
47+
| counter | The fully qualified counter Name |
48+
| english | Using English Names Regardless of system Language requires Windows Vista or higher |
49+
| expand-index | Should indices be translated? |
50+
| host | The name Of the machine in the network where the nounter should be searched, defaults to localhost |
51+
| instances | Expand wildcards And fetch all instances |
52+
| type | this can be large or float depending what you expect, default is large |
5353

5454
## Attributes
5555

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/sasha-s/go-deadlock v0.3.5
1919
github.com/sassoftware/go-rpmutils v0.4.0
2020
github.com/sevlyar/go-daemon v0.1.6
21-
github.com/shirou/gopsutil/v4 v4.25.3
21+
github.com/shirou/gopsutil/v4 v4.25.4
2222
github.com/sni/check_http_go/pkg/checkhttp v0.0.0-20250317143157-caa67455f3bb
2323
github.com/sni/go-flags v0.0.0-20241025124417-5e271e4d4cc9
2424
github.com/sni/shelltoken v0.0.0-20250505124910-1de4f4c2c936

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
9090
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
9191
github.com/sevlyar/go-daemon v0.1.6 h1:EUh1MDjEM4BI109Jign0EaknA2izkOyi0LV3ro3QQGs=
9292
github.com/sevlyar/go-daemon v0.1.6/go.mod h1:6dJpPatBT9eUwM5VCw9Bt6CdX9Tk6UWvhW3MebLDRKE=
93-
github.com/shirou/gopsutil/v4 v4.25.3 h1:SeA68lsu8gLggyMbmCn8cmp97V1TI9ld9sVzAUcKcKE=
94-
github.com/shirou/gopsutil/v4 v4.25.3/go.mod h1:xbuxyoZj+UsgnZrENu3lQivsngRR5BdjbJwf2fv4szA=
93+
github.com/shirou/gopsutil/v4 v4.25.4 h1:cdtFO363VEOOFrUCjZRh4XVJkb548lyF0q0uTeMqYPw=
94+
github.com/shirou/gopsutil/v4 v4.25.4/go.mod h1:xbuxyoZj+UsgnZrENu3lQivsngRR5BdjbJwf2fv4szA=
9595
github.com/sni/check_http_go/pkg/checkhttp v0.0.0-20250317143157-caa67455f3bb h1:mSA+KsQF9UHYcWwh/04UZME4pGiL0oQCqxpjL9Axyk0=
9696
github.com/sni/check_http_go/pkg/checkhttp v0.0.0-20250317143157-caa67455f3bb/go.mod h1:Ja52a8d0K4032zY9tOXLcIh2E0e/NprRnl7nXJjebI0=
9797
github.com/sni/go-flags v0.0.0-20241025124417-5e271e4d4cc9 h1:UDgM4SP5Fd2PKVRdeUFlA/WRNHkvMNeIx0Nmw7sn21k=

pkg/snclient/check_pdh.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
func init() {
88
AvailableChecks["check_pdh"] = CheckEntry{"check_pdh", NewCheckPDH}
9-
AvailableChecks["CheckCounter"] = CheckEntry{"check_pdh", NewCheckPDH}
109
}
1110

1211
type CheckPDH struct {
@@ -34,11 +33,11 @@ func (c *CheckPDH) Build() *CheckData {
3433
emptySyntax: "%(status) - No counter found",
3534
emptyState: CheckExitUnknown,
3635
args: map[string]CheckArgument{
37-
"counter": {value: &c.CounterPath, description: "The fully qualified Counter Name"},
38-
"Counter": {value: &c.CounterPath, description: "The fully qualified Counter Name"},
39-
"host": {value: &c.HostName, description: "The Name Of the Host Mashine in Network where the Counter should be searched, defults to local mashine"},
40-
"expand-index": {value: &c.ExpandIndex, description: "Should Indices be translated?"},
41-
"instances": {value: &c.Instances, description: "Expand WildCards And Fethch all instances"},
36+
"counter": {value: &c.CounterPath, description: "The fully qualified counter Name"},
37+
"Counter": {value: &c.CounterPath, description: "The fully qualified counter Name"},
38+
"host": {value: &c.HostName, description: "The name Of the machine in the network where the nounter should be searched, defaults to localhost"},
39+
"expand-index": {value: &c.ExpandIndex, description: "Should indices be translated?"},
40+
"instances": {value: &c.Instances, description: "Expand wildcards And fetch all instances"},
4241
"type": {value: &c.Type, description: "this can be large or float depending what you expect, default is large "},
4342
"english": {value: &c.EnglishFallBackNames, description: "Using English Names Regardless of system Language requires Windows Vista or higher"},
4443
},

pkg/snclient/check_pdh_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func TestCheckPDH(t *testing.T) {
1313
snc := StartTestAgent(t, "")
1414

15-
res := snc.RunCheck("check_pdh", []string{`counter=\4\30`, "warn=value > 80", "crit=value > 90", "show-all"})
15+
res := snc.RunCheck("check_pdh", []string{`counter=\4\30`, "warn=value > 80", "crit=value > 90"})
1616
assert.Equalf(t, CheckExitCritical, res.State, "The check could not be run successful")
1717
assert.Contains(t, string(res.BuildPluginOutput()), "CRITICAL")
1818

@@ -26,7 +26,7 @@ func TestCheckPDH(t *testing.T) {
2626
func TestCheckPDHOptionalAlias(t *testing.T) {
2727
// svchost.exe should run on all windows instances
2828
snc := StartTestAgent(t, "")
29-
res := snc.RunCheck("check_pdh", []string{`counter:svchost=\Process(svchost)\Private Bytes`, "warn=value < 200", "crit=value < 500", "show-all", "instances", "english"})
29+
res := snc.RunCheck("check_pdh", []string{`counter:svchost=\Process(svchost)\Private Bytes`, "warn=value < 200", "crit=value < 500", "instances", "english"})
3030
assert.Equalf(t, CheckExitOK, res.State, "The check could not be run successful")
3131
assert.Contains(t, string(res.BuildPluginOutput()), "OK")
3232

pkg/snclient/check_pdh_windows.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,15 @@ func (c *CheckPDH) collectValuesForAllCounters(hQuery pdh.PDH_HQUERY, counters m
126126
}
127127
entry["name"] = name
128128
entry["value"] = fmt.Sprintf("%d", fmtValue.FmtValue.LargeValue)
129-
if check.showAll {
130-
check.result.Metrics = append(check.result.Metrics,
131-
&CheckMetric{
132-
Name: name,
133-
ThresholdName: "value",
134-
Value: fmtValue.FmtValue.LargeValue,
135-
Warning: check.warnThreshold,
136-
Critical: check.critThreshold,
137-
Min: &Zero,
138-
})
139-
}
129+
check.result.Metrics = append(check.result.Metrics,
130+
&CheckMetric{
131+
Name: name + "_value",
132+
ThresholdName: "value",
133+
Value: fmtValue.FmtValue.LargeValue,
134+
Warning: check.warnThreshold,
135+
Critical: check.critThreshold,
136+
Min: &Zero,
137+
})
140138
if check.MatchMapCondition(check.filter, entry, true) {
141139
check.listData = append(check.listData, entry)
142140
}

pkg/snclient/task_check_system.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
"github.com/consol-monitoring/snclient/pkg/convert"
13-
"github.com/consol-monitoring/snclient/pkg/wincpu"
1413
cpuinfo "github.com/shirou/gopsutil/v4/cpu"
1514
"github.com/shirou/gopsutil/v4/net"
1615
)
@@ -162,7 +161,7 @@ func (c *CheckSystemHandler) update(create bool) {
162161
func (c *CheckSystemHandler) fetch() (data map[string]float64, cputimes *cpuinfo.TimesStat, netdata map[string]float64, err error) {
163162
data = map[string]float64{}
164163

165-
info, err := wincpu.Percent(0, true)
164+
info, err := cpuinfo.Percent(0, true)
166165
if err != nil {
167166
return nil, nil, nil, fmt.Errorf("cpuinfo failed: %s", err.Error())
168167
}

0 commit comments

Comments
 (0)