diff --git a/internal/collector/performancecounter/performancecounter.go b/internal/collector/performancecounter/performancecounter.go index 5b5a7740e..e5367d07b 100644 --- a/internal/collector/performancecounter/performancecounter.go +++ b/internal/collector/performancecounter/performancecounter.go @@ -108,6 +108,7 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error { counters := make([]string, 0, len(object.Counters)) for j, counter := range object.Counters { counters = append(counters, counter.Name) + if counter.Metric == "" { c.config.Objects[i].Counters[j].Metric = sanitizeMetricName(fmt.Sprintf("%s_perfdata_%s_%s", types.Namespace, object.Object, counter.Name)) } @@ -142,6 +143,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error { collectedCounterValue, ok := collectedInstanceCounters[counter.Name] if !ok { c.logger.Warn(fmt.Sprintf("counter %s not found in collected data", counter.Name)) + continue } diff --git a/internal/collector/performancecounter/types.go b/internal/collector/performancecounter/types.go index 017439527..3fe91c0a3 100644 --- a/internal/collector/performancecounter/types.go +++ b/internal/collector/performancecounter/types.go @@ -27,8 +27,8 @@ type Object struct { } type Counter struct { - Name string `json:"name" yaml:"name"` - Type string `json:"type" yaml:"type"` + Name string `json:"name" yaml:"name"` + Type string `json:"type" yaml:"type"` Metric string `json:"metric" yaml:"metric"` Labels map[string]string `json:"labels" yaml:"labels"` } diff --git a/tools/end-to-end-test.ps1 b/tools/end-to-end-test.ps1 index e4d05fb07..1b0886671 100644 --- a/tools/end-to-end-test.ps1 +++ b/tools/end-to-end-test.ps1 @@ -26,7 +26,7 @@ $exporter_proc = Start-Process ` -PassThru ` -FilePath ..\windows_exporter.exe ` -ArgumentList "--log.level=debug","--web.disable-exporter-metrics","--collectors.enabled=[defaults],cpu_info,textfile,process,pagefile,perfdata,scheduled_task,tcp,udp,time,system,service,logical_disk,printer,os,net,memory,logon,cache","--collector.process.include=explorer.exe","--collector.scheduled_task.include=.*GAEvents","--collector.service.include=Themes","--collector.textfile.directories=$($textfile_dir)",@" ---collector.perfdata.objects="[{\"object\":\"Processor Information\",\"instance_label\":\"core\",\"instances\":[\"*\"],\"counters\":{\"% Processor Time\":{},\"% Privileged Time\":{}}},{\"object\":\"Memory\",\"counters\":{\"Cache Faults/sec\":{\"type\":\"counter\"}}}]" +--collector.performancecounter.objects="[{\"object\":\"Processor Information\",\"instances\":[\"*\"],\"instance_label\":\"core\",\"counters\":[{\"name\":\"% Processor Time\",\"metric\":\"windows_perfdata_processor_information_processor_time\",\"labels\":{\"state\":\"active\"}},{\"name\":\"% Idle Time\",\"metric\":\"windows_perfdata_processor_information_processor_time\",\"labels\":{\"state\":\"idle\"}}]},{\"object\":\"Memory\",\"counters\":[{\"name\":\"Cache Faults/sec\",\"type\":\"counter\"}]}]" "@ ` -WindowStyle Hidden ` -RedirectStandardOutput "$($temp_dir)/windows_exporter.log" `