Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions connector/datadogconnector/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion exporter/datadogexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ require (
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/prometheus-community/windows_exporter v0.27.2 // indirect
github.com/prometheus/alertmanager v0.27.0 // indirect
github.com/prometheus/client_golang v1.21.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions exporter/datadogexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion exporter/datadogexporter/integrationtest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ require (
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/prometheus-community/windows_exporter v0.27.2 // indirect
github.com/prometheus/alertmanager v0.27.0 // indirect
github.com/prometheus/client_golang v1.21.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions exporter/datadogexporter/integrationtest/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions receiver/hostmetricsreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter v0.123.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata v0.123.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.123.0
github.com/prometheus-community/windows_exporter v0.27.2
github.com/prometheus/procfs v0.16.0
github.com/shirou/gopsutil/v4 v4.25.3
github.com/stretchr/testify v1.10.0
Expand Down Expand Up @@ -51,8 +50,6 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/ebitengine/purego v0.8.2 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
Expand All @@ -63,7 +60,7 @@ require (
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/knadh/koanf/maps v0.1.2 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.2 // indirect
Expand Down
10 changes: 2 additions & 8 deletions receiver/hostmetricsreceiver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Package perfcounters is a thin wrapper around
// Package perfcounters is a thin wrapper around code vendored from
// https://pkg.go.dev/github.com/prometheus-community/windows_exporter/pkg/perflib that
// provides functions to scrape raw performance counter data, without
// calculating rates or formatting them, from the registry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
"strconv"
"strings"

"github.com/prometheus-community/windows_exporter/pkg/perflib"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/perfcounters/third_party/perflib"
)

const totalInstanceName = "_Total"
Expand Down Expand Up @@ -67,7 +66,7 @@ func (p *PerfLibScraper) Initialize(objects ...string) error {
}

func (p *PerfLibScraper) Scrape() (PerfDataCollection, error) {
objects, err := perflib.QueryPerformanceData(p.objectIndices)
objects, err := perflib.QueryPerformanceData(p.objectIndices, "")
if err != nil {
return nil, fmt.Errorf("failed to query performance data: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Leopold Schabel / The perflib_exporter authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
//go:build windows

package perflib // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/perfcounters/third_party/perflib"

import (
"fmt"
"reflect"
"strings"
)

type Collector struct {
object string
query string

counters map[string]Counter
nameIndexValue int
}

type Counter struct {
Name string
Desc string
Instances map[string]uint32
Type uint32
Frequency float64

FieldIndexValue int
FieldIndexSecondValue int
}

func NewCollector[T any](object string, _ []string) (*Collector, error) {
collector := &Collector{
object: object,
query: MapCounterToIndex(object),
nameIndexValue: -1,
counters: make(map[string]Counter),
}

var values [0]T
valueType := reflect.TypeOf(values).Elem()

if f, ok := valueType.FieldByName("Name"); ok {
if f.Type.Kind() == reflect.String {
collector.nameIndexValue = f.Index[0]
}
}

for _, f := range reflect.VisibleFields(valueType) {
counterName, ok := f.Tag.Lookup("perfdata")
if !ok {
continue
}

var counter Counter
if counter, ok = collector.counters[counterName]; !ok {
counter = Counter{
Name: counterName,
FieldIndexSecondValue: -1,
FieldIndexValue: -1,
}
}

if strings.HasSuffix(counterName, ",secondvalue") {
counterName = strings.TrimSuffix(counterName, ",secondvalue")

counter.FieldIndexSecondValue = f.Index[0]
} else {
counter.FieldIndexValue = f.Index[0]
}

collector.counters[counterName] = counter
}

var collectValues []T

if err := collector.Collect(&collectValues); err != nil {
return nil, fmt.Errorf("failed to collect initial data: %w", err)
}

return collector, nil
}

func (c *Collector) Describe() map[string]string {
return map[string]string{}
}

func (c *Collector) Collect(data any) error {
dv := reflect.ValueOf(data)
if dv.Kind() != reflect.Ptr || dv.IsNil() {
return ErrInvalidEntityType
}

dv = dv.Elem()

elemType := dv.Type().Elem()
elemValue := reflect.ValueOf(reflect.New(elemType).Interface()).Elem()

if dv.Kind() != reflect.Slice || elemType.Kind() != reflect.Struct {
return ErrInvalidEntityType
}

perfObjects, err := QueryPerformanceData(c.query, c.object)
if err != nil {
return fmt.Errorf("QueryPerformanceData: %w", err)
}

if len(perfObjects) == 0 || perfObjects[0] == nil || len(perfObjects[0].Instances) == 0 {
return nil
}

if dv.Len() != 0 {
dv.Set(reflect.MakeSlice(dv.Type(), 0, len(perfObjects[0].Instances)))
}

dv.Clear()

for _, perfObject := range perfObjects {
if perfObject.Name != c.object {
continue
}

for _, perfInstance := range perfObject.Instances {
instanceName := perfInstance.Name
if strings.HasSuffix(instanceName, "_Total") {
continue
}

if instanceName == "" || instanceName == "*" {
instanceName = InstanceEmpty
}

if c.nameIndexValue != -1 {
elemValue.Field(c.nameIndexValue).SetString(instanceName)
}

dv.Set(reflect.Append(dv, elemValue))
index := dv.Len() - 1

for _, perfCounter := range perfInstance.Counters {
if perfCounter.Def.IsBaseValue && !perfCounter.Def.IsNanosecondCounter {
continue
}

counter, ok := c.counters[perfCounter.Def.Name]
if !ok {
continue
}

switch perfCounter.Def.CounterType {
case PERF_ELAPSED_TIME:
dv.Index(index).
Field(counter.FieldIndexValue).
SetFloat(float64((perfCounter.Value - WindowsEpoch) / perfObject.Frequency))
case PERF_100NSEC_TIMER, PERF_PRECISION_100NS_TIMER:
dv.Index(index).
Field(counter.FieldIndexValue).
SetFloat(float64(perfCounter.Value) * TicksToSecondScaleFactor)
default:
if counter.FieldIndexSecondValue != -1 {
dv.Index(index).
Field(counter.FieldIndexSecondValue).
SetFloat(float64(perfCounter.SecondValue))
}

if counter.FieldIndexValue != -1 {
dv.Index(index).
Field(counter.FieldIndexValue).
SetFloat(float64(perfCounter.Value))
}
}
}
}
}

return nil
}

func (c *Collector) Close() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build windows

package perflib // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/perfcounters/third_party/perflib"

import "errors"

var ErrInvalidEntityType = errors.New("invalid entity type")
Loading