Skip to content

Commit dd51d5b

Browse files
Added support for Windows operating systems pre-Vista.
1 parent 331b700 commit dd51d5b

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

plugins/inputs/win_perf_counters/README.md

+31-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,30 @@ as counters used when performance monitoring
1818
This file is likely to be updated in the future with more examples for
1919
useful configurations for separate scenarios.
2020

21+
### Plugin wide
22+
23+
Plugin wide entries are underneath `[[inputs.win_perf_counters]]`.
24+
25+
#### PrintValid
26+
27+
Bool, if set to `true` will print out all matching performance objects.
28+
29+
Example:
30+
`PrintValid=true`
31+
32+
#### PreVistaSupport
33+
34+
Bool, if set to `true` will use the localized PerfCounter interface that is present before Vista for backwards compatability.
35+
36+
It is recommended NOT to use this on OSes starting with Vista and newer because it requires more configuration to use this than the newer interface present since Vista.
37+
38+
Example for Windows Server 2003, this would be set to true:
39+
`PreVistaSupport=true`
40+
41+
### Object
42+
43+
See Entry below.
44+
2145
### Entry
2246
A new configuration entry consists of the TOML header to start with,
2347
`[[inputs.win_perf_counters.object]]`.
@@ -26,14 +50,14 @@ beneath the main win_perf_counters entry, `[[inputs.win_perf_counters]]`.
2650

2751
Following this is 3 required key/value pairs and the three optional parameters and their usage.
2852

29-
### ObjectName
53+
#### ObjectName
3054
**Required**
3155

3256
ObjectName is the Object to query for, like Processor, DirectoryServices, LogicalDisk or similar.
3357

3458
Example: `ObjectName = "LogicalDisk"`
3559

36-
### Instances
60+
#### Instances
3761
**Required**
3862

3963
Instances (this is an array) is the instances of a counter you would like returned,
@@ -49,7 +73,7 @@ Some Objects does not have instances to select from at all,
4973
here only one option is valid if you want data back,
5074
and that is to specify `Instances = ["------"]`.
5175

52-
### Counters
76+
#### Counters
5377
**Required**
5478

5579
Counters (this is an array) is the counters of the ObjectName
@@ -59,7 +83,7 @@ Example: `Counters = ["% Idle Time", "% Disk Read Time", "% Disk Write Time"]`
5983
This must be specified for every counter you want the results of,
6084
it is not possible to ask for all counters in the ObjectName.
6185

62-
### Measurement
86+
#### Measurement
6387
*Optional*
6488

6589
This key is optional, if it is not set it will be win_perf_counters.
@@ -70,7 +94,7 @@ separate from Processor results.
7094

7195
Example: `Measurement = "win_disk"
7296

73-
### IncludeTotal
97+
#### IncludeTotal
7498
*Optional*
7599

76100
This key is optional, it is a simple bool.
@@ -80,7 +104,7 @@ and you would also like all instances containg _Total returned,
80104
like "_Total", "0,_Total" and so on where applicable
81105
(Processor Information is one example).
82106

83-
### WarnOnMissing
107+
#### WarnOnMissing
84108
*Optional*
85109

86110
This key is optional, it is a simple bool.
@@ -89,7 +113,7 @@ This only has an effect on the first execution of the plugin,
89113
it will print out any ObjectName/Instance/Counter combinations
90114
asked for that does not match. Useful when debugging new configurations.
91115

92-
### FailOnMissing
116+
#### FailOnMissing
93117
*Internal*
94118

95119
This key should not be used, it is for testing purposes only.

plugins/inputs/win_perf_counters/win_perf_counters.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ var testConfigParsed bool
7474
var testObject string
7575

7676
type Win_PerfCounters struct {
77-
PrintValid bool
78-
TestName string
79-
Object []perfobject
77+
PrintValid bool
78+
TestName string
79+
PreVistaSupport bool
80+
Object []perfobject
8081
}
8182

8283
type perfobject struct {
@@ -112,8 +113,11 @@ func (m *Win_PerfCounters) AddItem(metrics *itemList, query string, objectName s
112113
var handle win.PDH_HQUERY
113114
var counterHandle win.PDH_HCOUNTER
114115
ret := win.PdhOpenQuery(0, 0, &handle)
115-
ret = win.PdhAddEnglishCounter(handle, query, 0, &counterHandle)
116-
116+
if m.PreVistaSupport {
117+
ret = win.PdhAddCounter(handle, query, 0, &counterHandle)
118+
} else {
119+
ret = win.PdhAddEnglishCounter(handle, query, 0, &counterHandle)
120+
}
117121
_ = ret
118122

119123
temp := &item{query, objectName, counter, instance, measurement,

0 commit comments

Comments
 (0)