feat(inputs.win_perf_counters): add remote system support (#12556)
This commit is contained in:
parent
d3e1f95b87
commit
2529d5fa16
|
|
@ -26,6 +26,20 @@ For more information on concepts and terminology including object,
|
||||||
counter, and instance names, see the help in the Windows Performance
|
counter, and instance names, see the help in the Windows Performance
|
||||||
Monitor app.
|
Monitor app.
|
||||||
|
|
||||||
|
### Schema
|
||||||
|
|
||||||
|
*Measurement name* is specified per performance object
|
||||||
|
or `win_perf_counters` by default.
|
||||||
|
|
||||||
|
*Tags:*
|
||||||
|
|
||||||
|
- source - computer name, as specified in the `Sources` parameter. Name `localhost` is translated into the host name
|
||||||
|
- objectname - normalized name of the performance object
|
||||||
|
- instance - instance name, if performance object supports multiple instances, otherwise omitted
|
||||||
|
|
||||||
|
*Fields* are counters of the performance object.
|
||||||
|
The field name is normalized counter name.
|
||||||
|
|
||||||
### Plugin wide
|
### Plugin wide
|
||||||
|
|
||||||
Plugin wide entries are underneath `[[inputs.win_perf_counters]]`.
|
Plugin wide entries are underneath `[[inputs.win_perf_counters]]`.
|
||||||
|
|
@ -124,6 +138,27 @@ errors](pdh.go).
|
||||||
Example:
|
Example:
|
||||||
`IgnoredErrors=["PDH_NO_DATA"]`
|
`IgnoredErrors=["PDH_NO_DATA"]`
|
||||||
|
|
||||||
|
#### Sources
|
||||||
|
|
||||||
|
(Optional)
|
||||||
|
|
||||||
|
Host names or ip addresses of computers to gather all performance counters from.
|
||||||
|
The user running Telegraf must be authenticated to the remote computer(s).
|
||||||
|
E.g. via Windows sharing `net use \\SQL-SERVER-01`.
|
||||||
|
Use either localhost (`"localhost"`) or real local computer name to gather
|
||||||
|
counters also from localhost among other computers. Skip, if gather only from
|
||||||
|
localhost.
|
||||||
|
|
||||||
|
If a performance counter is present only on specific hosts set `Sources` param
|
||||||
|
on the specific counter level configuration to override global (plugin wide)
|
||||||
|
sources.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
`Sources = ["localhost", "SQL-SERVER-01", "SQL-SERVER-02", "SQL-SERVER-03"]`
|
||||||
|
|
||||||
|
Default:
|
||||||
|
`Sources = ["localhost"]`
|
||||||
|
|
||||||
### Object
|
### Object
|
||||||
|
|
||||||
See Entry below.
|
See Entry below.
|
||||||
|
|
@ -181,6 +216,13 @@ This must be specified for every counter you want the results of, or use
|
||||||
`["*"]` for all the counters of the object, if the `UseWildcardsExpansion` param
|
`["*"]` for all the counters of the object, if the `UseWildcardsExpansion` param
|
||||||
is set to `true`.
|
is set to `true`.
|
||||||
|
|
||||||
|
#### Sources (Object)
|
||||||
|
|
||||||
|
(Optional)
|
||||||
|
|
||||||
|
Overrides the [Sources](#sources) global parameter for current performance
|
||||||
|
object. See [Sources](#sources) description for more details.
|
||||||
|
|
||||||
#### Measurement
|
#### Measurement
|
||||||
|
|
||||||
(Optional)
|
(Optional)
|
||||||
|
|
@ -204,8 +246,17 @@ as seen in the Windows Performance Monitor.
|
||||||
A field representing raw counter value has the `_Raw` suffix. Raw values should
|
A field representing raw counter value has the `_Raw` suffix. Raw values should
|
||||||
be further used in a calculation,
|
be further used in a calculation,
|
||||||
e.g. `100-(non_negative_derivative("Percent_Processor_Time_Raw",1s)/100000`
|
e.g. `100-(non_negative_derivative("Percent_Processor_Time_Raw",1s)/100000`
|
||||||
Note: Time based counters (i.e. _% Processor Time_) are reported in hundredths
|
Note: Time based counters (i.e. *% Processor Time*) are reported in hundredths
|
||||||
of nanoseconds.
|
of nanoseconds.
|
||||||
|
This key is optional. It is a simple bool.
|
||||||
|
If set to `true`, counter values will be provided in the raw, integer, form.
|
||||||
|
This is in contrast with the default behavior, where values are returned in a
|
||||||
|
formatted, displayable, form as seen in the Windows Performance Monitor.
|
||||||
|
A field representing raw counter value has the `_Raw` suffix.
|
||||||
|
Raw values should be further used in a calculation,
|
||||||
|
e.g. `100-(non_negative_derivative("Percent_Processor_Time_Raw",1s)/100000`
|
||||||
|
Note: Time based counters (i.e. `% Processor Time`)
|
||||||
|
are reported in hundredths of nanoseconds.
|
||||||
|
|
||||||
Example: `UseRawValues = true`
|
Example: `UseRawValues = true`
|
||||||
|
|
||||||
|
|
@ -623,11 +674,17 @@ to check the counter path on the command line. E.g. `typeperf
|
||||||
If no metrics are emitted even with the default config, you may need to repair
|
If no metrics are emitted even with the default config, you may need to repair
|
||||||
your performance counters.
|
your performance counters.
|
||||||
|
|
||||||
1. Launch the Command Prompt as Administrator (right click Runs As Administrator).
|
1. Launch the Command Prompt as Administrator
|
||||||
1. Drop into the C:\WINDOWS\System32 directory by typing `C:` then `cd \Windows\System32`
|
(right click "Runs As Administrator").
|
||||||
|
1. Drop into the C:\WINDOWS\System32 directory by typing `C:` then
|
||||||
|
`cd \Windows\System32`
|
||||||
1. Rebuild your counter values, which may take a few moments so please be
|
1. Rebuild your counter values, which may take a few moments so please be
|
||||||
patient, by running:
|
patient, by running:
|
||||||
|
|
||||||
```batchfile
|
```batchfile
|
||||||
lodctr /r
|
lodctr /r
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Metrics
|
||||||
|
|
||||||
|
## Example Output
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,10 @@ type PerformanceQuery interface {
|
||||||
IsVistaOrNewer() bool
|
IsVistaOrNewer() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PerformanceQueryCreator interface {
|
||||||
|
NewPerformanceQuery(string) PerformanceQuery
|
||||||
|
}
|
||||||
|
|
||||||
// PdhError represents error returned from Performance Counters API
|
// PdhError represents error returned from Performance Counters API
|
||||||
type PdhError struct {
|
type PdhError struct {
|
||||||
ErrorCode uint32
|
ErrorCode uint32
|
||||||
|
|
@ -55,6 +59,13 @@ type PerformanceQueryImpl struct {
|
||||||
query PDH_HQUERY
|
query PDH_HQUERY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PerformanceQueryCreatorImpl struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m PerformanceQueryCreatorImpl) NewPerformanceQuery(string) PerformanceQuery {
|
||||||
|
return &PerformanceQueryImpl{}
|
||||||
|
}
|
||||||
|
|
||||||
// Open creates a new counterPath that is used to manage the collection of performance data.
|
// Open creates a new counterPath that is used to manage the collection of performance data.
|
||||||
// It returns counterPath handle used for subsequent calls for adding counters and querying data
|
// It returns counterPath handle used for subsequent calls for adding counters and querying data
|
||||||
func (m *PerformanceQueryImpl) Open() error {
|
func (m *PerformanceQueryImpl) Open() error {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
|
|
@ -18,7 +20,7 @@ import (
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
var sampleConfig string
|
var sampleConfig string
|
||||||
|
|
||||||
type Win_PerfCounters struct {
|
type WinPerfCounters struct {
|
||||||
PrintValid bool `toml:"PrintValid"`
|
PrintValid bool `toml:"PrintValid"`
|
||||||
PreVistaSupport bool `toml:"PreVistaSupport" deprecated:"1.7.0;determined dynamically"`
|
PreVistaSupport bool `toml:"PreVistaSupport" deprecated:"1.7.0;determined dynamically"`
|
||||||
UsePerfCounterTime bool
|
UsePerfCounterTime bool
|
||||||
|
|
@ -27,15 +29,29 @@ type Win_PerfCounters struct {
|
||||||
UseWildcardsExpansion bool
|
UseWildcardsExpansion bool
|
||||||
LocalizeWildcardsExpansion bool
|
LocalizeWildcardsExpansion bool
|
||||||
IgnoredErrors []string `toml:"IgnoredErrors"`
|
IgnoredErrors []string `toml:"IgnoredErrors"`
|
||||||
|
Sources []string
|
||||||
|
|
||||||
Log telegraf.Logger
|
Log telegraf.Logger
|
||||||
|
|
||||||
lastRefreshed time.Time
|
lastRefreshed time.Time
|
||||||
counters []*counter
|
queryCreator PerformanceQueryCreator
|
||||||
query PerformanceQuery
|
hostCounters map[string]*hostCountersInfo
|
||||||
|
// cached os.Hostname()
|
||||||
|
cachedHostname string
|
||||||
|
}
|
||||||
|
|
||||||
|
type hostCountersInfo struct {
|
||||||
|
// computer name used as key and for printing
|
||||||
|
computer string
|
||||||
|
// computer name used in tag
|
||||||
|
tag string
|
||||||
|
counters []*counter
|
||||||
|
query PerformanceQuery
|
||||||
|
timestamp time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type perfobject struct {
|
type perfobject struct {
|
||||||
|
Sources []string
|
||||||
ObjectName string
|
ObjectName string
|
||||||
Counters []string
|
Counters []string
|
||||||
Instances []string
|
Instances []string
|
||||||
|
|
@ -48,6 +64,7 @@ type perfobject struct {
|
||||||
|
|
||||||
type counter struct {
|
type counter struct {
|
||||||
counterPath string
|
counterPath string
|
||||||
|
computer string
|
||||||
objectName string
|
objectName string
|
||||||
counter string
|
counter string
|
||||||
instance string
|
instance string
|
||||||
|
|
@ -63,20 +80,22 @@ type instanceGrouping struct {
|
||||||
objectname string
|
objectname string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type fieldGrouping map[instanceGrouping]map[string]interface{}
|
||||||
|
|
||||||
var sanitizedChars = strings.NewReplacer("/sec", "_persec", "/Sec", "_persec",
|
var sanitizedChars = strings.NewReplacer("/sec", "_persec", "/Sec", "_persec",
|
||||||
" ", "_", "%", "Percent", `\`, "")
|
" ", "_", "%", "Percent", `\`, "")
|
||||||
|
|
||||||
// extractCounterInfoFromCounterPath gets object name, instance name (if available) and counter name from counter path
|
// extractCounterInfoFromCounterPath gets object name, instance name (if available) and counter name from counter path
|
||||||
// General Counter path pattern is: \\computer\object(parent/instance#index)\counter
|
// General Counter path pattern is: \\computer\object(parent/instance#index)\counter
|
||||||
// parent/instance#index part is skipped in single instance objects (e.g. Memory): \\computer\object\counter
|
// parent/instance#index part is skipped in single instance objects (e.g. Memory): \\computer\object\counter
|
||||||
func extractCounterInfoFromCounterPath(counterPath string) (object string, instance string, counter string, err error) {
|
func extractCounterInfoFromCounterPath(counterPath string) (string, string, string, string, error) {
|
||||||
|
leftComputerBorderIndex := -1
|
||||||
rightObjectBorderIndex := -1
|
rightObjectBorderIndex := -1
|
||||||
leftObjectBorderIndex := -1
|
leftObjectBorderIndex := -1
|
||||||
leftCounterBorderIndex := -1
|
leftCounterBorderIndex := -1
|
||||||
rightInstanceBorderIndex := -1
|
rightInstanceBorderIndex := -1
|
||||||
leftInstanceBorderIndex := -1
|
leftInstanceBorderIndex := -1
|
||||||
bracketLevel := 0
|
var bracketLevel int
|
||||||
|
|
||||||
for i := len(counterPath) - 1; i >= 0; i-- {
|
for i := len(counterPath) - 1; i >= 0; i-- {
|
||||||
switch counterPath[i] {
|
switch counterPath[i] {
|
||||||
|
|
@ -86,6 +105,8 @@ func extractCounterInfoFromCounterPath(counterPath string) (object string, insta
|
||||||
leftCounterBorderIndex = i
|
leftCounterBorderIndex = i
|
||||||
} else if leftObjectBorderIndex == -1 {
|
} else if leftObjectBorderIndex == -1 {
|
||||||
leftObjectBorderIndex = i
|
leftObjectBorderIndex = i
|
||||||
|
} else if leftComputerBorderIndex == -1 {
|
||||||
|
leftComputerBorderIndex = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case '(':
|
case '(':
|
||||||
|
|
@ -105,31 +126,46 @@ func extractCounterInfoFromCounterPath(counterPath string) (object string, insta
|
||||||
rightObjectBorderIndex = leftCounterBorderIndex
|
rightObjectBorderIndex = leftCounterBorderIndex
|
||||||
}
|
}
|
||||||
if rightObjectBorderIndex == -1 || leftObjectBorderIndex == -1 {
|
if rightObjectBorderIndex == -1 || leftObjectBorderIndex == -1 {
|
||||||
err = errors.New("cannot parse object from: " + counterPath)
|
return "", "", "", "", errors.New("cannot parse object from: " + counterPath)
|
||||||
return
|
}
|
||||||
|
|
||||||
|
var computer, object, instance, counter string
|
||||||
|
if leftComputerBorderIndex > -1 {
|
||||||
|
// validate there is leading \\ and not empty computer (\\\O)
|
||||||
|
if leftComputerBorderIndex != 1 || leftComputerBorderIndex == leftObjectBorderIndex-1 {
|
||||||
|
return "", "", "", "", errors.New("cannot parse computer from: " + counterPath)
|
||||||
|
}
|
||||||
|
computer = counterPath[leftComputerBorderIndex+1 : leftObjectBorderIndex]
|
||||||
}
|
}
|
||||||
|
|
||||||
if leftInstanceBorderIndex > -1 && rightInstanceBorderIndex > -1 {
|
if leftInstanceBorderIndex > -1 && rightInstanceBorderIndex > -1 {
|
||||||
instance = counterPath[leftInstanceBorderIndex+1 : rightInstanceBorderIndex]
|
instance = counterPath[leftInstanceBorderIndex+1 : rightInstanceBorderIndex]
|
||||||
} else if (leftInstanceBorderIndex == -1 && rightInstanceBorderIndex > -1) || (leftInstanceBorderIndex > -1 && rightInstanceBorderIndex == -1) {
|
} else if (leftInstanceBorderIndex == -1 && rightInstanceBorderIndex > -1) || (leftInstanceBorderIndex > -1 && rightInstanceBorderIndex == -1) {
|
||||||
err = errors.New("cannot parse instance from: " + counterPath)
|
return "", "", "", "", errors.New("cannot parse instance from: " + counterPath)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
object = counterPath[leftObjectBorderIndex+1 : rightObjectBorderIndex]
|
object = counterPath[leftObjectBorderIndex+1 : rightObjectBorderIndex]
|
||||||
counter = counterPath[leftCounterBorderIndex+1:]
|
counter = counterPath[leftCounterBorderIndex+1:]
|
||||||
return
|
return computer, object, instance, counter, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCounter(
|
func (m *WinPerfCounters) SampleConfig() string {
|
||||||
counterHandle PDH_HCOUNTER,
|
return sampleConfig
|
||||||
counterPath string,
|
}
|
||||||
objectName string,
|
|
||||||
instance string,
|
func (m *WinPerfCounters) hostname() string {
|
||||||
counterName string,
|
if m.cachedHostname != "" {
|
||||||
measurement string,
|
return m.cachedHostname
|
||||||
includeTotal bool,
|
}
|
||||||
useRawValue bool,
|
hostname, err := os.Hostname()
|
||||||
) *counter {
|
if err != nil {
|
||||||
|
m.cachedHostname = "localhost"
|
||||||
|
} else {
|
||||||
|
m.cachedHostname = hostname
|
||||||
|
}
|
||||||
|
return m.cachedHostname
|
||||||
|
}
|
||||||
|
|
||||||
|
func newCounter(counterHandle PDH_HCOUNTER, counterPath string, computer string, objectName string, instance string, counterName string, measurement string, includeTotal bool, useRawValue bool) *counter {
|
||||||
measurementName := sanitizedChars.Replace(measurement)
|
measurementName := sanitizedChars.Replace(measurement)
|
||||||
if measurementName == "" {
|
if measurementName == "" {
|
||||||
measurementName = "win_perf_counters"
|
measurementName = "win_perf_counters"
|
||||||
|
|
@ -138,59 +174,68 @@ func newCounter(
|
||||||
if useRawValue {
|
if useRawValue {
|
||||||
newCounterName += "_Raw"
|
newCounterName += "_Raw"
|
||||||
}
|
}
|
||||||
return &counter{counterPath, objectName, newCounterName, instance, measurementName,
|
return &counter{counterPath, computer, objectName, newCounterName, instance, measurementName,
|
||||||
includeTotal, useRawValue, counterHandle}
|
includeTotal, useRawValue, counterHandle}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Win_PerfCounters) SampleConfig() string {
|
func (m *WinPerfCounters) AddItem(counterPath, computer, objectName, instance, counterName, measurement string, includeTotal bool, useRawValue bool) error {
|
||||||
return sampleConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Win_PerfCounters) AddItem(
|
|
||||||
counterPath string,
|
|
||||||
objectName string,
|
|
||||||
instance string,
|
|
||||||
counterName string,
|
|
||||||
measurement string,
|
|
||||||
includeTotal bool,
|
|
||||||
useRawValue bool,
|
|
||||||
) error {
|
|
||||||
origCounterPath := counterPath
|
origCounterPath := counterPath
|
||||||
var err error
|
var err error
|
||||||
var counterHandle PDH_HCOUNTER
|
var counterHandle PDH_HCOUNTER
|
||||||
if !m.query.IsVistaOrNewer() {
|
|
||||||
counterHandle, err = m.query.AddCounterToQuery(counterPath)
|
sourceTag := computer
|
||||||
|
if computer == "localhost" {
|
||||||
|
sourceTag = m.hostname()
|
||||||
|
}
|
||||||
|
if m.hostCounters == nil {
|
||||||
|
m.hostCounters = make(map[string]*hostCountersInfo)
|
||||||
|
}
|
||||||
|
hostCounter, ok := m.hostCounters[computer]
|
||||||
|
if !ok {
|
||||||
|
hostCounter = &hostCountersInfo{computer: computer, tag: sourceTag}
|
||||||
|
m.hostCounters[computer] = hostCounter
|
||||||
|
hostCounter.query = m.queryCreator.NewPerformanceQuery(computer)
|
||||||
|
if err = hostCounter.query.Open(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
hostCounter.counters = make([]*counter, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !hostCounter.query.IsVistaOrNewer() {
|
||||||
|
counterHandle, err = hostCounter.query.AddCounterToQuery(counterPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
counterHandle, err = m.query.AddEnglishCounterToQuery(counterPath)
|
counterHandle, err = hostCounter.query.AddEnglishCounterToQuery(counterPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.UseWildcardsExpansion {
|
if m.UseWildcardsExpansion {
|
||||||
origInstance := instance
|
origInstance := instance
|
||||||
counterPath, err = m.query.GetCounterPath(counterHandle)
|
counterPath, err = hostCounter.query.GetCounterPath(counterHandle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
counters, err := m.query.ExpandWildCardPath(counterPath)
|
counters, err := hostCounter.query.ExpandWildCardPath(counterPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
origObjectName, _, origCounterName, err := extractCounterInfoFromCounterPath(origCounterPath)
|
_, origObjectName, _, origCounterName, err := extractCounterInfoFromCounterPath(origCounterPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, counterPath := range counters {
|
for _, counterPath := range counters {
|
||||||
var err error
|
_, err := hostCounter.query.AddCounterToQuery(counterPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
objectName, instance, counterName, err = extractCounterInfoFromCounterPath(counterPath)
|
computer, objectName, instance, counterName, err = extractCounterInfoFromCounterPath(counterPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -209,11 +254,15 @@ func (m *Win_PerfCounters) AddItem(
|
||||||
} else {
|
} else {
|
||||||
newInstance = instance
|
newInstance = instance
|
||||||
}
|
}
|
||||||
counterPath = formatPath(origObjectName, newInstance, origCounterName)
|
counterPath = formatPath(computer, origObjectName, newInstance, origCounterName)
|
||||||
counterHandle, err = m.query.AddEnglishCounterToQuery(counterPath)
|
counterHandle, err = hostCounter.query.AddEnglishCounterToQuery(counterPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
newItem = newCounter(
|
newItem = newCounter(
|
||||||
counterHandle,
|
counterHandle,
|
||||||
counterPath,
|
counterPath,
|
||||||
|
computer,
|
||||||
origObjectName, instance,
|
origObjectName, instance,
|
||||||
origCounterName,
|
origCounterName,
|
||||||
measurement,
|
measurement,
|
||||||
|
|
@ -221,10 +270,14 @@ func (m *Win_PerfCounters) AddItem(
|
||||||
useRawValue,
|
useRawValue,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
counterHandle, err = m.query.AddCounterToQuery(counterPath)
|
counterHandle, err = hostCounter.query.AddCounterToQuery(counterPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
newItem = newCounter(
|
newItem = newCounter(
|
||||||
counterHandle,
|
counterHandle,
|
||||||
counterPath,
|
counterPath,
|
||||||
|
computer,
|
||||||
objectName,
|
objectName,
|
||||||
instance,
|
instance,
|
||||||
counterName,
|
counterName,
|
||||||
|
|
@ -238,7 +291,7 @@ func (m *Win_PerfCounters) AddItem(
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
m.counters = append(m.counters, newItem)
|
hostCounter.counters = append(hostCounter.counters, newItem)
|
||||||
|
|
||||||
if m.PrintValid {
|
if m.PrintValid {
|
||||||
m.Log.Infof("Valid: %s", counterPath)
|
m.Log.Infof("Valid: %s", counterPath)
|
||||||
|
|
@ -248,6 +301,7 @@ func (m *Win_PerfCounters) AddItem(
|
||||||
newItem := newCounter(
|
newItem := newCounter(
|
||||||
counterHandle,
|
counterHandle,
|
||||||
counterPath,
|
counterPath,
|
||||||
|
computer,
|
||||||
objectName,
|
objectName,
|
||||||
instance,
|
instance,
|
||||||
counterName,
|
counterName,
|
||||||
|
|
@ -255,7 +309,7 @@ func (m *Win_PerfCounters) AddItem(
|
||||||
includeTotal,
|
includeTotal,
|
||||||
useRawValue,
|
useRawValue,
|
||||||
)
|
)
|
||||||
m.counters = append(m.counters, newItem)
|
hostCounter.counters = append(hostCounter.counters, newItem)
|
||||||
if m.PrintValid {
|
if m.PrintValid {
|
||||||
m.Log.Infof("Valid: %s", counterPath)
|
m.Log.Infof("Valid: %s", counterPath)
|
||||||
}
|
}
|
||||||
|
|
@ -266,19 +320,41 @@ func (m *Win_PerfCounters) AddItem(
|
||||||
|
|
||||||
const emptyInstance = "------"
|
const emptyInstance = "------"
|
||||||
|
|
||||||
func formatPath(objectname string, instance string, counter string) string {
|
func formatPath(computer, objectname, instance, counter string) string {
|
||||||
|
path := ""
|
||||||
if instance == emptyInstance {
|
if instance == emptyInstance {
|
||||||
return "\\" + objectname + "\\" + counter
|
path = fmt.Sprintf(`\%s\%s`, objectname, counter)
|
||||||
} else {
|
} else {
|
||||||
return "\\" + objectname + "(" + instance + ")\\" + counter
|
path = fmt.Sprintf(`\%s(%s)\%s`, objectname, instance, counter)
|
||||||
}
|
}
|
||||||
|
if computer != "" && computer != "localhost" {
|
||||||
|
path = fmt.Sprintf(`\\%s%s`, computer, path)
|
||||||
|
}
|
||||||
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Win_PerfCounters) ParseConfig() error {
|
func (m *WinPerfCounters) ParseConfig() error {
|
||||||
var counterPath string
|
var counterPath string
|
||||||
|
|
||||||
if len(m.Object) > 0 {
|
if len(m.Sources) == 0 {
|
||||||
for _, PerfObject := range m.Object {
|
m.Sources = []string{"localhost"}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(m.Object) <= 0 {
|
||||||
|
err := errors.New("no performance objects configured")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, PerfObject := range m.Object {
|
||||||
|
computers := PerfObject.Sources
|
||||||
|
if len(computers) == 0 {
|
||||||
|
computers = m.Sources
|
||||||
|
}
|
||||||
|
for _, computer := range computers {
|
||||||
|
if computer == "" {
|
||||||
|
// localhost as a computer name in counter path doesn't work
|
||||||
|
computer = "localhost"
|
||||||
|
}
|
||||||
for _, counter := range PerfObject.Counters {
|
for _, counter := range PerfObject.Counters {
|
||||||
if len(PerfObject.Instances) == 0 {
|
if len(PerfObject.Instances) == 0 {
|
||||||
m.Log.Warnf("Missing 'Instances' param for object '%s'\n", PerfObject.ObjectName)
|
m.Log.Warnf("Missing 'Instances' param for object '%s'\n", PerfObject.ObjectName)
|
||||||
|
|
@ -286,13 +362,12 @@ func (m *Win_PerfCounters) ParseConfig() error {
|
||||||
for _, instance := range PerfObject.Instances {
|
for _, instance := range PerfObject.Instances {
|
||||||
objectname := PerfObject.ObjectName
|
objectname := PerfObject.ObjectName
|
||||||
|
|
||||||
counterPath = formatPath(objectname, instance, counter)
|
counterPath = formatPath(computer, objectname, instance, counter)
|
||||||
|
|
||||||
err := m.AddItem(counterPath, objectname, instance, counter, PerfObject.Measurement, PerfObject.IncludeTotal, PerfObject.UseRawValues)
|
|
||||||
|
|
||||||
|
err := m.AddItem(counterPath, computer, objectname, instance, counter, PerfObject.Measurement, PerfObject.IncludeTotal, PerfObject.UseRawValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if PerfObject.FailOnMissing || PerfObject.WarnOnMissing {
|
if PerfObject.FailOnMissing || PerfObject.WarnOnMissing {
|
||||||
m.Log.Errorf("Invalid counterPath: '%s'. Error: %s\n", counterPath, err.Error())
|
m.Log.Errorf("invalid counterPath: '%s'. Error: %s\n", counterPath, err.Error())
|
||||||
}
|
}
|
||||||
if PerfObject.FailOnMissing {
|
if PerfObject.FailOnMissing {
|
||||||
return err
|
return err
|
||||||
|
|
@ -301,15 +376,12 @@ func (m *Win_PerfCounters) ParseConfig() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
err := errors.New("no performance objects configured")
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Win_PerfCounters) checkError(err error) error {
|
func (m *WinPerfCounters) checkError(err error) error {
|
||||||
if pdhErr, ok := err.(*PdhError); ok {
|
if pdhErr, ok := err.(*PdhError); ok {
|
||||||
for _, ignoredErrors := range m.IgnoredErrors {
|
for _, ignoredErrors := range m.IgnoredErrors {
|
||||||
if PDHErrors[pdhErr.ErrorCode] == ignoredErrors {
|
if PDHErrors[pdhErr.ErrorCode] == ignoredErrors {
|
||||||
|
|
@ -322,54 +394,74 @@ func (m *Win_PerfCounters) checkError(err error) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Win_PerfCounters) Gather(acc telegraf.Accumulator) error {
|
func (m *WinPerfCounters) Gather(acc telegraf.Accumulator) error {
|
||||||
// Parse the config once
|
// Parse the config once
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if m.lastRefreshed.IsZero() || (m.CountersRefreshInterval > 0 && m.lastRefreshed.Add(time.Duration(m.CountersRefreshInterval)).Before(time.Now())) {
|
if m.lastRefreshed.IsZero() || (m.CountersRefreshInterval > 0 && m.lastRefreshed.Add(time.Duration(m.CountersRefreshInterval)).Before(time.Now())) {
|
||||||
if m.counters != nil {
|
if err = m.cleanQueries(); err != nil {
|
||||||
m.counters = m.counters[:0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = m.query.Open(); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = m.ParseConfig(); err != nil {
|
if err = m.ParseConfig(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//some counters need two data samples before computing a value
|
for _, hostCounterSet := range m.hostCounters {
|
||||||
if err = m.query.CollectData(); err != nil {
|
//some counters need two data samples before computing a value
|
||||||
return m.checkError(err)
|
if err = hostCounterSet.query.CollectData(); err != nil {
|
||||||
|
return m.checkError(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m.lastRefreshed = time.Now()
|
m.lastRefreshed = time.Now()
|
||||||
|
// minimum time between collecting two samples
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
var collectFields = make(map[instanceGrouping]map[string]interface{})
|
for _, hostCounterSet := range m.hostCounters {
|
||||||
|
if m.UsePerfCounterTime && hostCounterSet.query.IsVistaOrNewer() {
|
||||||
var timestamp time.Time
|
hostCounterSet.timestamp, err = hostCounterSet.query.CollectDataWithTime()
|
||||||
if m.UsePerfCounterTime && m.query.IsVistaOrNewer() {
|
if err != nil {
|
||||||
timestamp, err = m.query.CollectDataWithTime()
|
return err
|
||||||
if err != nil {
|
}
|
||||||
return err
|
} else {
|
||||||
}
|
hostCounterSet.timestamp = time.Now()
|
||||||
} else {
|
if err = hostCounterSet.query.CollectData(); err != nil {
|
||||||
timestamp = time.Now()
|
return err
|
||||||
if err = m.query.CollectData(); err != nil {
|
}
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
//iterate over computers
|
||||||
|
for _, hostCounterInfo := range m.hostCounters {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(hostInfo *hostCountersInfo) {
|
||||||
|
m.Log.Debugf("gathering from %s", hostInfo.computer)
|
||||||
|
start := time.Now()
|
||||||
|
err := m.gatherComputerCounters(hostInfo, acc)
|
||||||
|
m.Log.Debugf("gathering from %s finished in %.3fs", hostInfo.computer, time.Since(start))
|
||||||
|
if err != nil {
|
||||||
|
acc.AddError(fmt.Errorf("error during collecting data on host '%s': %s", hostInfo.computer, err.Error()))
|
||||||
|
}
|
||||||
|
wg.Done()
|
||||||
|
}(hostCounterInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *WinPerfCounters) gatherComputerCounters(hostCounterInfo *hostCountersInfo, acc telegraf.Accumulator) error {
|
||||||
var value interface{}
|
var value interface{}
|
||||||
|
var err error
|
||||||
|
collectedFields := make(fieldGrouping)
|
||||||
// For iterate over the known metrics and get the samples.
|
// For iterate over the known metrics and get the samples.
|
||||||
for _, metric := range m.counters {
|
for _, metric := range hostCounterInfo.counters {
|
||||||
// collect
|
// collect
|
||||||
if m.UseWildcardsExpansion {
|
if m.UseWildcardsExpansion {
|
||||||
if metric.useRawValue {
|
if metric.useRawValue {
|
||||||
value, err = m.query.GetRawCounterValue(metric.counterHandle)
|
value, err = hostCounterInfo.query.GetRawCounterValue(metric.counterHandle)
|
||||||
} else {
|
} else {
|
||||||
value, err = m.query.GetFormattedCounterValueDouble(metric.counterHandle)
|
value, err = hostCounterInfo.query.GetFormattedCounterValueDouble(metric.counterHandle)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//ignore invalid data as some counters from process instances returns this sometimes
|
//ignore invalid data as some counters from process instances returns this sometimes
|
||||||
|
|
@ -379,13 +471,13 @@ func (m *Win_PerfCounters) Gather(acc telegraf.Accumulator) error {
|
||||||
m.Log.Warnf("error while getting value for counter %q, instance: %s, will skip metric: %v", metric.counterPath, metric.instance, err)
|
m.Log.Warnf("error while getting value for counter %q, instance: %s, will skip metric: %v", metric.counterPath, metric.instance, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
addCounterMeasurement(metric, metric.instance, value, collectFields)
|
addCounterMeasurement(metric, metric.instance, value, collectedFields)
|
||||||
} else {
|
} else {
|
||||||
var counterValues []CounterValue
|
var counterValues []CounterValue
|
||||||
if metric.useRawValue {
|
if metric.useRawValue {
|
||||||
counterValues, err = m.query.GetRawCounterArray(metric.counterHandle)
|
counterValues, err = hostCounterInfo.query.GetRawCounterArray(metric.counterHandle)
|
||||||
} else {
|
} else {
|
||||||
counterValues, err = m.query.GetFormattedCounterArrayDouble(metric.counterHandle)
|
counterValues, err = hostCounterInfo.query.GetFormattedCounterArrayDouble(metric.counterHandle)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//ignore invalid data as some counters from process instances returns this sometimes
|
//ignore invalid data as some counters from process instances returns this sometimes
|
||||||
|
|
@ -404,22 +496,34 @@ func (m *Win_PerfCounters) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if shouldIncludeMetric(metric, cValue) {
|
if shouldIncludeMetric(metric, cValue) {
|
||||||
addCounterMeasurement(metric, cValue.InstanceName, cValue.Value, collectFields)
|
addCounterMeasurement(metric, cValue.InstanceName, cValue.Value, collectedFields)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for instance, fields := range collectedFields {
|
||||||
for instance, fields := range collectFields {
|
|
||||||
var tags = map[string]string{
|
var tags = map[string]string{
|
||||||
"objectname": instance.objectname,
|
"objectname": instance.objectname,
|
||||||
}
|
}
|
||||||
if len(instance.instance) > 0 {
|
if len(instance.instance) > 0 {
|
||||||
tags["instance"] = instance.instance
|
tags["instance"] = instance.instance
|
||||||
}
|
}
|
||||||
acc.AddFields(instance.name, fields, tags, timestamp)
|
if len(hostCounterInfo.tag) > 0 {
|
||||||
|
tags["source"] = hostCounterInfo.tag
|
||||||
|
}
|
||||||
|
acc.AddFields(instance.name, fields, tags, hostCounterInfo.timestamp)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *WinPerfCounters) cleanQueries() error {
|
||||||
|
for _, hostCounterInfo := range m.hostCounters {
|
||||||
|
if err := hostCounterInfo.query.Close(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.hostCounters = nil
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -442,7 +546,7 @@ func shouldIncludeMetric(metric *counter, cValue CounterValue) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func addCounterMeasurement(metric *counter, instanceName string, value interface{}, collectFields map[instanceGrouping]map[string]interface{}) {
|
func addCounterMeasurement(metric *counter, instanceName string, value interface{}, collectFields fieldGrouping) {
|
||||||
var instance = instanceGrouping{metric.measurement, instanceName, metric.objectName}
|
var instance = instanceGrouping{metric.measurement, instanceName, metric.objectName}
|
||||||
if collectFields[instance] == nil {
|
if collectFields[instance] == nil {
|
||||||
collectFields[instance] = make(map[string]interface{})
|
collectFields[instance] = make(map[string]interface{})
|
||||||
|
|
@ -461,7 +565,7 @@ func isKnownCounterDataError(err error) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Win_PerfCounters) Init() error {
|
func (m *WinPerfCounters) Init() error {
|
||||||
if m.UseWildcardsExpansion && !m.LocalizeWildcardsExpansion {
|
if m.UseWildcardsExpansion && !m.LocalizeWildcardsExpansion {
|
||||||
// Counters must not have wildcards with this option
|
// Counters must not have wildcards with this option
|
||||||
|
|
||||||
|
|
@ -494,10 +598,10 @@ func (m *Win_PerfCounters) Init() error {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
inputs.Add("win_perf_counters", func() telegraf.Input {
|
inputs.Add("win_perf_counters", func() telegraf.Input {
|
||||||
return &Win_PerfCounters{
|
return &WinPerfCounters{
|
||||||
query: &PerformanceQueryImpl{},
|
|
||||||
CountersRefreshInterval: config.Duration(time.Second * 60),
|
CountersRefreshInterval: config.Duration(time.Second * 60),
|
||||||
LocalizeWildcardsExpansion: true,
|
LocalizeWildcardsExpansion: true,
|
||||||
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,13 @@
|
||||||
package win_perf_counters
|
package win_perf_counters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWinPerformanceQueryImplIntegration(t *testing.T) {
|
func TestWinPerformanceQueryImplIntegration(t *testing.T) {
|
||||||
|
|
@ -152,13 +150,12 @@ func TestWinPerfcountersConfigGet1Integration(t *testing.T) {
|
||||||
|
|
||||||
perfobjects[0] = PerfObject
|
perfobjects[0] = PerfObject
|
||||||
|
|
||||||
m := Win_PerfCounters{
|
m := WinPerfCounters{
|
||||||
PrintValid: false,
|
PrintValid: false,
|
||||||
Object: perfobjects,
|
Object: perfobjects,
|
||||||
query: &PerformanceQueryImpl{},
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
_ = m.query.Open()
|
|
||||||
|
|
||||||
err := m.ParseConfig()
|
err := m.ParseConfig()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -191,26 +188,26 @@ func TestWinPerfcountersConfigGet2Integration(t *testing.T) {
|
||||||
|
|
||||||
perfobjects[0] = PerfObject
|
perfobjects[0] = PerfObject
|
||||||
|
|
||||||
m := Win_PerfCounters{
|
m := WinPerfCounters{
|
||||||
PrintValid: false,
|
PrintValid: false,
|
||||||
Object: perfobjects,
|
Object: perfobjects,
|
||||||
query: &PerformanceQueryImpl{},
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
_ = m.query.Open()
|
|
||||||
|
|
||||||
err := m.ParseConfig()
|
err := m.ParseConfig()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if len(m.counters) == 1 {
|
hostCounters, ok := m.hostCounters["localhost"]
|
||||||
|
require.True(t, ok)
|
||||||
|
|
||||||
|
if len(hostCounters.counters) == 1 {
|
||||||
require.NoError(t, nil)
|
require.NoError(t, nil)
|
||||||
} else if len(m.counters) == 0 {
|
} else if len(hostCounters.counters) == 0 {
|
||||||
var errorstring1 = "No results returned from the counterPath"
|
err2 := fmt.Errorf("no results returned from the counterPath: %v", len(hostCounters.counters))
|
||||||
err2 := errors.New(errorstring1)
|
|
||||||
require.NoError(t, err2)
|
require.NoError(t, err2)
|
||||||
} else if len(m.counters) > 1 {
|
} else if len(hostCounters.counters) > 1 {
|
||||||
var errorstring1 = fmt.Sprintf("Too many results returned from the counterPath: %v", len(m.counters))
|
err2 := fmt.Errorf("too many results returned from the counterPath: %v", len(hostCounters.counters))
|
||||||
err2 := errors.New(errorstring1)
|
|
||||||
require.NoError(t, err2)
|
require.NoError(t, err2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -220,6 +217,7 @@ func TestWinPerfcountersConfigGet3Integration(t *testing.T) {
|
||||||
t.Skip("Skipping integration test in short mode")
|
t.Skip("Skipping integration test in short mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sources = make([]string, 1)
|
||||||
var instances = make([]string, 1)
|
var instances = make([]string, 1)
|
||||||
var counters = make([]string, 2)
|
var counters = make([]string, 2)
|
||||||
var perfobjects = make([]perfobject, 1)
|
var perfobjects = make([]perfobject, 1)
|
||||||
|
|
@ -228,10 +226,12 @@ func TestWinPerfcountersConfigGet3Integration(t *testing.T) {
|
||||||
instances[0] = "_Total"
|
instances[0] = "_Total"
|
||||||
counters[0] = "% Processor Time"
|
counters[0] = "% Processor Time"
|
||||||
counters[1] = "% Idle Time"
|
counters[1] = "% Idle Time"
|
||||||
|
sources[0] = "localhost"
|
||||||
|
|
||||||
var measurement = "test"
|
var measurement = "test"
|
||||||
|
|
||||||
PerfObject := perfobject{
|
PerfObject := perfobject{
|
||||||
|
Sources: sources,
|
||||||
ObjectName: objectname,
|
ObjectName: objectname,
|
||||||
Instances: instances,
|
Instances: instances,
|
||||||
Counters: counters,
|
Counters: counters,
|
||||||
|
|
@ -243,28 +243,26 @@ func TestWinPerfcountersConfigGet3Integration(t *testing.T) {
|
||||||
|
|
||||||
perfobjects[0] = PerfObject
|
perfobjects[0] = PerfObject
|
||||||
|
|
||||||
m := Win_PerfCounters{
|
m := WinPerfCounters{
|
||||||
PrintValid: false,
|
PrintValid: false,
|
||||||
Object: perfobjects,
|
Object: perfobjects,
|
||||||
query: &PerformanceQueryImpl{},
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
_ = m.query.Open()
|
|
||||||
|
|
||||||
err := m.ParseConfig()
|
err := m.ParseConfig()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if len(m.counters) == 2 {
|
hostCounters, ok := m.hostCounters["localhost"]
|
||||||
|
require.True(t, ok)
|
||||||
|
|
||||||
|
if len(hostCounters.counters) == 2 {
|
||||||
require.NoError(t, nil)
|
require.NoError(t, nil)
|
||||||
} else if len(m.counters) < 2 {
|
} else if len(hostCounters.counters) < 2 {
|
||||||
|
err2 := fmt.Errorf("too few results returned from the counterPath: %v", len(hostCounters.counters))
|
||||||
var errorstring1 = fmt.Sprintf("Too few results returned from the counterPath: %v", len(m.counters))
|
|
||||||
err2 := errors.New(errorstring1)
|
|
||||||
require.NoError(t, err2)
|
require.NoError(t, err2)
|
||||||
} else if len(m.counters) > 2 {
|
} else if len(hostCounters.counters) > 2 {
|
||||||
|
err2 := fmt.Errorf("too many results returned from the counterPath: %v", len(hostCounters.counters))
|
||||||
var errorstring1 = fmt.Sprintf("Too many results returned from the counterPath: %v", len(m.counters))
|
|
||||||
err2 := errors.New(errorstring1)
|
|
||||||
require.NoError(t, err2)
|
require.NoError(t, err2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -297,28 +295,26 @@ func TestWinPerfcountersConfigGet4Integration(t *testing.T) {
|
||||||
|
|
||||||
perfobjects[0] = PerfObject
|
perfobjects[0] = PerfObject
|
||||||
|
|
||||||
m := Win_PerfCounters{
|
m := WinPerfCounters{
|
||||||
PrintValid: false,
|
PrintValid: false,
|
||||||
Object: perfobjects,
|
Object: perfobjects,
|
||||||
query: &PerformanceQueryImpl{},
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
_ = m.query.Open()
|
|
||||||
|
|
||||||
err := m.ParseConfig()
|
err := m.ParseConfig()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if len(m.counters) == 2 {
|
hostCounters, ok := m.hostCounters["localhost"]
|
||||||
|
require.True(t, ok)
|
||||||
|
|
||||||
|
if len(hostCounters.counters) == 2 {
|
||||||
require.NoError(t, nil)
|
require.NoError(t, nil)
|
||||||
} else if len(m.counters) < 2 {
|
} else if len(hostCounters.counters) < 2 {
|
||||||
|
err2 := fmt.Errorf("too few results returned from the counterPath: %v", len(hostCounters.counters))
|
||||||
var errorstring1 = fmt.Sprintf("Too few results returned from the counterPath: %v", len(m.counters))
|
|
||||||
err2 := errors.New(errorstring1)
|
|
||||||
require.NoError(t, err2)
|
require.NoError(t, err2)
|
||||||
} else if len(m.counters) > 2 {
|
} else if len(hostCounters.counters) > 2 {
|
||||||
|
err2 := fmt.Errorf("too many results returned from the counterPath: %v", len(hostCounters.counters))
|
||||||
var errorstring1 = fmt.Sprintf("Too many results returned from the counterPath: %v", len(m.counters))
|
|
||||||
err2 := errors.New(errorstring1)
|
|
||||||
require.NoError(t, err2)
|
require.NoError(t, err2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -352,26 +348,26 @@ func TestWinPerfcountersConfigGet5Integration(t *testing.T) {
|
||||||
|
|
||||||
perfobjects[0] = PerfObject
|
perfobjects[0] = PerfObject
|
||||||
|
|
||||||
m := Win_PerfCounters{
|
m := WinPerfCounters{
|
||||||
PrintValid: false,
|
PrintValid: false,
|
||||||
Object: perfobjects,
|
Object: perfobjects,
|
||||||
query: &PerformanceQueryImpl{},
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
_ = m.query.Open()
|
|
||||||
|
|
||||||
err := m.ParseConfig()
|
err := m.ParseConfig()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if len(m.counters) == 4 {
|
hostCounters, ok := m.hostCounters["localhost"]
|
||||||
|
require.True(t, ok)
|
||||||
|
|
||||||
|
if len(hostCounters.counters) == 4 {
|
||||||
require.NoError(t, nil)
|
require.NoError(t, nil)
|
||||||
} else if len(m.counters) < 4 {
|
} else if len(hostCounters.counters) < 4 {
|
||||||
var errorstring1 = fmt.Sprintf("Too few results returned from the counterPath: %v", len(m.counters))
|
err2 := fmt.Errorf("too few results returned from the counterPath: %v", len(hostCounters.counters))
|
||||||
err2 := errors.New(errorstring1)
|
|
||||||
require.NoError(t, err2)
|
require.NoError(t, err2)
|
||||||
} else if len(m.counters) > 4 {
|
} else if len(hostCounters.counters) > 4 {
|
||||||
var errorstring1 = fmt.Sprintf("Too many results returned from the counterPath: %v", len(m.counters))
|
err2 := fmt.Errorf("too many results returned from the counterPath: %v", len(hostCounters.counters))
|
||||||
err2 := errors.New(errorstring1)
|
|
||||||
require.NoError(t, err2)
|
require.NoError(t, err2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -403,16 +399,18 @@ func TestWinPerfcountersConfigGet6Integration(t *testing.T) {
|
||||||
|
|
||||||
perfobjects[0] = PerfObject
|
perfobjects[0] = PerfObject
|
||||||
|
|
||||||
m := Win_PerfCounters{
|
m := WinPerfCounters{
|
||||||
PrintValid: false,
|
PrintValid: false,
|
||||||
Object: perfobjects,
|
Object: perfobjects,
|
||||||
query: &PerformanceQueryImpl{},
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
_ = m.query.Open()
|
|
||||||
|
|
||||||
err := m.ParseConfig()
|
err := m.ParseConfig()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, ok := m.hostCounters["localhost"]
|
||||||
|
require.True(t, ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWinPerfcountersConfigGet7Integration(t *testing.T) {
|
func TestWinPerfcountersConfigGet7Integration(t *testing.T) {
|
||||||
|
|
@ -433,38 +431,34 @@ func TestWinPerfcountersConfigGet7Integration(t *testing.T) {
|
||||||
var measurement = "test"
|
var measurement = "test"
|
||||||
|
|
||||||
PerfObject := perfobject{
|
PerfObject := perfobject{
|
||||||
objectname,
|
ObjectName: objectname,
|
||||||
counters,
|
Counters: counters,
|
||||||
instances,
|
Instances: instances,
|
||||||
measurement,
|
Measurement: measurement,
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
perfobjects[0] = PerfObject
|
perfobjects[0] = PerfObject
|
||||||
|
|
||||||
m := Win_PerfCounters{
|
m := WinPerfCounters{
|
||||||
PrintValid: false,
|
PrintValid: false,
|
||||||
Object: perfobjects,
|
Object: perfobjects,
|
||||||
query: &PerformanceQueryImpl{},
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
_ = m.query.Open()
|
|
||||||
|
|
||||||
err := m.ParseConfig()
|
err := m.ParseConfig()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if len(m.counters) == 2 {
|
hostCounters, ok := m.hostCounters["localhost"]
|
||||||
|
require.True(t, ok)
|
||||||
|
|
||||||
|
if len(hostCounters.counters) == 2 {
|
||||||
require.NoError(t, nil)
|
require.NoError(t, nil)
|
||||||
} else if len(m.counters) < 2 {
|
} else if len(hostCounters.counters) < 2 {
|
||||||
var errorstring1 = fmt.Sprintf("Too few results returned from the counterPath: %v", len(m.counters))
|
err2 := fmt.Errorf("too few results returned from the counterPath: %v", len(hostCounters.counters))
|
||||||
err2 := errors.New(errorstring1)
|
|
||||||
require.NoError(t, err2)
|
require.NoError(t, err2)
|
||||||
} else if len(m.counters) > 2 {
|
} else if len(hostCounters.counters) > 2 {
|
||||||
var errorstring1 = fmt.Sprintf("Too many results returned from the counterPath: %v", len(m.counters))
|
err2 := fmt.Errorf("too many results returned from the counterPath: %v", len(hostCounters.counters))
|
||||||
err2 := errors.New(errorstring1)
|
|
||||||
require.NoError(t, err2)
|
require.NoError(t, err2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -496,13 +490,12 @@ func TestWinPerfcountersConfigError1Integration(t *testing.T) {
|
||||||
|
|
||||||
perfobjects[0] = PerfObject
|
perfobjects[0] = PerfObject
|
||||||
|
|
||||||
m := Win_PerfCounters{
|
m := WinPerfCounters{
|
||||||
PrintValid: false,
|
PrintValid: false,
|
||||||
Object: perfobjects,
|
Object: perfobjects,
|
||||||
query: &PerformanceQueryImpl{},
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
_ = m.query.Open()
|
|
||||||
|
|
||||||
err := m.ParseConfig()
|
err := m.ParseConfig()
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
@ -535,13 +528,12 @@ func TestWinPerfcountersConfigError2Integration(t *testing.T) {
|
||||||
|
|
||||||
perfobjects[0] = PerfObject
|
perfobjects[0] = PerfObject
|
||||||
|
|
||||||
m := Win_PerfCounters{
|
m := WinPerfCounters{
|
||||||
PrintValid: false,
|
PrintValid: false,
|
||||||
Object: perfobjects,
|
Object: perfobjects,
|
||||||
query: &PerformanceQueryImpl{},
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
_ = m.query.Open()
|
|
||||||
|
|
||||||
err := m.ParseConfig()
|
err := m.ParseConfig()
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
@ -576,13 +568,12 @@ func TestWinPerfcountersConfigError3Integration(t *testing.T) {
|
||||||
|
|
||||||
perfobjects[0] = PerfObject
|
perfobjects[0] = PerfObject
|
||||||
|
|
||||||
m := Win_PerfCounters{
|
m := WinPerfCounters{
|
||||||
PrintValid: false,
|
PrintValid: false,
|
||||||
Object: perfobjects,
|
Object: perfobjects,
|
||||||
query: &PerformanceQueryImpl{},
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
_ = m.query.Open()
|
|
||||||
|
|
||||||
err := m.ParseConfig()
|
err := m.ParseConfig()
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
@ -616,11 +607,11 @@ func TestWinPerfcountersCollect1Integration(t *testing.T) {
|
||||||
|
|
||||||
perfobjects[0] = PerfObject
|
perfobjects[0] = PerfObject
|
||||||
|
|
||||||
m := Win_PerfCounters{
|
m := WinPerfCounters{
|
||||||
PrintValid: false,
|
PrintValid: false,
|
||||||
Object: perfobjects,
|
Object: perfobjects,
|
||||||
query: &PerformanceQueryImpl{},
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
err := m.Gather(&acc)
|
err := m.Gather(&acc)
|
||||||
|
|
@ -667,14 +658,15 @@ func TestWinPerfcountersCollect2Integration(t *testing.T) {
|
||||||
|
|
||||||
perfobjects[0] = PerfObject
|
perfobjects[0] = PerfObject
|
||||||
|
|
||||||
m := Win_PerfCounters{
|
m := WinPerfCounters{
|
||||||
PrintValid: false,
|
PrintValid: false,
|
||||||
UsePerfCounterTime: true,
|
UsePerfCounterTime: true,
|
||||||
Object: perfobjects,
|
Object: perfobjects,
|
||||||
query: &PerformanceQueryImpl{},
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
UseWildcardsExpansion: true,
|
UseWildcardsExpansion: true,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
err := m.Gather(&acc)
|
err := m.Gather(&acc)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -721,11 +713,11 @@ func TestWinPerfcountersCollectRawIntegration(t *testing.T) {
|
||||||
|
|
||||||
perfobjects[0] = PerfObject
|
perfobjects[0] = PerfObject
|
||||||
|
|
||||||
m := Win_PerfCounters{
|
m := WinPerfCounters{
|
||||||
PrintValid: false,
|
PrintValid: false,
|
||||||
Object: perfobjects,
|
Object: perfobjects,
|
||||||
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
UseWildcardsExpansion: true,
|
UseWildcardsExpansion: true,
|
||||||
query: &PerformanceQueryImpl{},
|
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
}
|
}
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
@ -746,7 +738,13 @@ func TestWinPerfcountersCollectRawIntegration(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test *Array way
|
// Test *Array way
|
||||||
m = Win_PerfCounters{PrintValid: false, Object: perfobjects, UseWildcardsExpansion: false, query: &PerformanceQueryImpl{}, Log: testutil.Logger{}}
|
m = WinPerfCounters{
|
||||||
|
PrintValid: false,
|
||||||
|
Object: perfobjects,
|
||||||
|
queryCreator: &PerformanceQueryCreatorImpl{},
|
||||||
|
UseWildcardsExpansion: false,
|
||||||
|
Log: testutil.Logger{},
|
||||||
|
}
|
||||||
var acc2 testutil.Accumulator
|
var acc2 testutil.Accumulator
|
||||||
err = m.Gather(&acc)
|
err = m.Gather(&acc)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue