Skip to content
Draft

wip #2204

Changes from all 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
47 changes: 37 additions & 10 deletions internal/pdh/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"errors"
"fmt"
"log/slog"
"os"
"reflect"
"slices"
"strconv"
Expand Down Expand Up @@ -371,16 +372,6 @@
)

for _, item := range items {
if item.RawValue.CStatus != CstatusValidData && item.RawValue.CStatus != CstatusNewData {
c.logger.Debug("skipping counter item with invalid data status",
slog.String("counter", counter.Name),
slog.String("instance", windows.UTF16PtrToString(item.SzName)),
slog.Uint64("status", uint64(item.RawValue.CStatus)),
)

continue
}

if instanceName, ok = stringMap[item.SzName]; !ok {
instanceName = windows.UTF16PtrToString(item.SzName)
stringMap[item.SzName] = instanceName
Expand Down Expand Up @@ -419,6 +410,34 @@
dv.Set(reflect.Append(dv, elemValue))
}

if item.RawValue.CStatus != CstatusValidData && item.RawValue.CStatus != CstatusNewData {
c.logger.Debug("skipping counter item with invalid data status",
slog.String("counter", counter.Name),
slog.String("instance", windows.UTF16PtrToString(item.SzName)),
slog.Uint64("status", uint64(item.RawValue.CStatus)),
)

f, err := os.OpenFile(os.Getenv("TEMP")+"\\windows_exporter_pdh_error.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)

Check failure on line 420 in internal/pdh/collector.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gofumpt)
if err == nil {
_, _ = f.WriteString(fmt.Sprintf("instance: %s, counter: %s, status: 0x%x\n", windows.UTF16PtrToString(item.SzName), counter.Name, item.RawValue.CStatus))

Check failure on line 422 in internal/pdh/collector.go

View workflow job for this annotation

GitHub Actions / lint

QF1012: Use fmt.Fprintf(...) instead of WriteString(fmt.Sprintf(...)) (staticcheck)
_ = f.Close()
}

if counter.FieldIndexSecondValue != -1 {
dv.Index(index).
Field(counter.FieldIndexSecondValue).
SetFloat(-1)
}

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

continue
}

// This is a workaround for the issue with the elapsed time counter type.
// Source: https://github.com/prometheus-community/windows_exporter/pull/335/files#diff-d5d2528f559ba2648c2866aec34b1eaa5c094dedb52bd0ff22aa5eb83226bd8dR76-R83
// Ref: https://learn.microsoft.com/en-us/windows/win32/perfctrs/calculating-counter-values
Expand All @@ -432,6 +451,14 @@
Field(counter.FieldIndexValue).
SetFloat(float64(item.RawValue.FirstValue) * TicksToSecondScaleFactor)
default:
if counter.Name == "Page Faults/sec" {
f, err := os.OpenFile(os.Getenv("TEMP")+"\\windows_process_page_faults_total.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err == nil {
_, _ = f.WriteString(fmt.Sprintf("instance: %s, counter: %s, value: %d\n", windows.UTF16PtrToString(item.SzName), counter.Name, item.RawValue.FirstValue))

Check failure on line 457 in internal/pdh/collector.go

View workflow job for this annotation

GitHub Actions / lint

QF1012: Use fmt.Fprintf(...) instead of WriteString(fmt.Sprintf(...)) (staticcheck)
_ = f.Close()
}
}

if counter.FieldIndexSecondValue != -1 {
dv.Index(index).
Field(counter.FieldIndexSecondValue).
Expand Down
Loading