Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git log disk utilization percent metrics #1781

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions internal/windows/pdh_poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import (
"fmt"

"github.com/newrelic/infrastructure-agent/internal/windows/api"
"github.com/newrelic/infrastructure-agent/pkg/log" //nolint:depguard
)

//nolint:gochecknoglobals
var plog = log.WithComponent("PDHPoll")

// PdhPoll creates repeatable queries for the Windows PDH api
type PdhPoll struct {
metrics []string
Expand Down Expand Up @@ -57,6 +61,7 @@ func NewPdhPoll(loggerFunc func(string, ...interface{}), metrics ...string) (Pdh

// At the moment, the poller is limited to metrics that can be represented as a float64
func (pdh *PdhPoll) Poll() (map[string]float64, error) {
plog.Debug("polling start")
ret := winapi.PdhCollectQueryData(pdh.queryHandler)
if ret != winapi.ERROR_SUCCESS {
return nil, fmt.Errorf("collect query returned with %#v", ret)
Expand All @@ -80,6 +85,9 @@ func (pdh *PdhPoll) Poll() (map[string]float64, error) {
}
counters[pdh.metrics[i]] = perf.DoubleValue
}

plog.WithField("counters", counters).Debug("polling end")

return counters, nil
}

Expand Down
15 changes: 11 additions & 4 deletions pkg/metrics/storage/storage_sampler_pdh_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"github.com/newrelic/infrastructure-agent/pkg/log"
)

//nolint:gochecknoglobals
var plog = sslog.WithComponent("PDH Windows")

type PdhIoCountersStat struct {
ReadsPerSec float64
ReadBytesPerSec float64
Expand Down Expand Up @@ -75,7 +78,7 @@ type PdhIoCounters struct {

// If the partitions have changed, the PDH query is recreated
func (io *PdhIoCounters) updateQuery(partitions []PartitionStat) error {
//Checking if the partitions table has changed
// Checking if the partitions table has changed
changed := false
if len(io.partitions) != len(partitions) {
changed = true
Expand All @@ -88,11 +91,11 @@ func (io *PdhIoCounters) updateQuery(partitions []PartitionStat) error {
}
}
if changed || !io.started {
sslog.Debug("Creating new PDH query.")
plog.Debug("Creating new PDH query.")
io.partitions = map[string][]string{}
metrics := make([]string, 0, len(metricsNames)*len(partitions))
for _, p := range partitions {
sslog.WithField("partition", fmt.Sprintf("%#v", p)).Debug("Creating partition queries.")
plog.WithField("partition", fmt.Sprintf("%#v", p)).Debug("Creating partition queries.")
io.partitions[p.Device] = make([]string, 0, len(metrics))
for _, mn := range metricsNames {
metrics = append(metrics, fmt.Sprintf(mn, p.Device))
Expand All @@ -102,12 +105,13 @@ func (io *PdhIoCounters) updateQuery(partitions []PartitionStat) error {
if io.started {
err = io.pdh.Close()
if err != nil {
sslog.WithError(err).Debug("Closing PDH")
plog.WithError(err).Debug("Closing PDH")
}
}
io.started = false // If "NewPdhPoll" fails, the PdhPoll must be recreated in the next update
io.pdh, err = nrwin.NewPdhPoll(log.Debugf, metrics...)
if err != nil {
plog.WithError(err).Debug("NewPdhPoll failed")
return err
}
io.started = true
Expand Down Expand Up @@ -141,6 +145,9 @@ func (io *PdhIoCounters) IoCounters(partitions []PartitionStat) (map[string]IOCo
CurrentQueueLen: values[fmt.Sprintf(metricsNames[currentQueueLen], p.Device)],
}
}

plog.WithField("counters", counters).Debug("IoCounters")

return counters, nil
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/metrics/storage/storage_sampler_wmi_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
"github.com/newrelic/infrastructure-agent/pkg/config"
)

//nolint:gochecknoglobals
var vlog = sslog.WithComponent("VMI Windows")

// WmiIoCountersStat provides IOCountersStat implementation for WMI
type WmiIoCountersStat struct {
Raw Win32_PerfRawData_PerfDisk_LogicalDisk
Expand Down Expand Up @@ -87,6 +90,11 @@ func CalculateWmiSampleValues(counter *WmiIoCountersStat, lastStats *WmiIoCounte
result.ReadUtilizationPercent = &read
result.WriteUtilizationPercent = &write

vlog.
WithField("ReadUtilizationPercent", *result.ReadUtilizationPercent).
WithField("WriteUtilizationPercent", *result.WriteUtilizationPercent).
Debug("CalculateWmiSampleValues")

return result
}

Expand All @@ -112,6 +120,9 @@ func WmiIoCounters() (map[string]IOCountersStat, error) {
if err != nil {
return ret, err
}

vlog.WithField("PerfDisk_LogicalDisk_Values", formatted).Debug("WmiIoCounters")

for _, d := range formatted {
if len(d.Name) > 3 { // not get _Total or Harddrive
continue
Expand Down
Loading