From b5f8ee61a7f7e9bd291dd26b0585d03eb686c941 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 5 May 2024 13:19:16 +0200 Subject: Adding upstream version 1.46.3. Signed-off-by: Daniel Baumann --- .../go.d.plugin/modules/windows/collect_process.go | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/go/collectors/go.d.plugin/modules/windows/collect_process.go (limited to 'src/go/collectors/go.d.plugin/modules/windows/collect_process.go') diff --git a/src/go/collectors/go.d.plugin/modules/windows/collect_process.go b/src/go/collectors/go.d.plugin/modules/windows/collect_process.go new file mode 100644 index 000000000..b1c729f30 --- /dev/null +++ b/src/go/collectors/go.d.plugin/modules/windows/collect_process.go @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package windows + +import ( + "strings" + + "github.com/netdata/netdata/go/go.d.plugin/pkg/prometheus" +) + +const ( + metricProcessCPUTimeTotal = "windows_process_cpu_time_total" + metricProcessWorkingSetBytes = "windows_process_working_set_private_bytes" + metricProcessIOBytes = "windows_process_io_bytes_total" + metricProcessIOOperations = "windows_process_io_operations_total" + metricProcessPageFaults = "windows_process_page_faults_total" + metricProcessPageFileBytes = "windows_process_page_file_bytes" + metricProcessThreads = "windows_process_threads" + metricProcessCPUHandles = "windows_process_handles" +) + +func (w *Windows) collectProcess(mx map[string]int64, pms prometheus.Series) { + if !w.cache.collection[collectorProcess] { + w.cache.collection[collectorProcess] = true + w.addProcessesCharts() + } + + seen := make(map[string]bool) + px := "process_" + for _, pm := range pms.FindByName(metricProcessCPUTimeTotal) { + if name := cleanProcessName(pm.Labels.Get("process")); name != "" { + seen[name] = true + mx[px+name+"_cpu_time"] += int64(pm.Value * 1000) + } + } + for _, pm := range pms.FindByName(metricProcessWorkingSetBytes) { + if name := cleanProcessName(pm.Labels.Get("process")); name != "" { + seen[name] = true + mx[px+name+"_working_set_private_bytes"] += int64(pm.Value) + } + } + for _, pm := range pms.FindByName(metricProcessIOBytes) { + if name := cleanProcessName(pm.Labels.Get("process")); name != "" { + seen[name] = true + mx[px+name+"_io_bytes"] += int64(pm.Value) + } + } + for _, pm := range pms.FindByName(metricProcessIOOperations) { + if name := cleanProcessName(pm.Labels.Get("process")); name != "" { + seen[name] = true + mx[px+name+"_io_operations"] += int64(pm.Value) + } + } + for _, pm := range pms.FindByName(metricProcessPageFaults) { + if name := cleanProcessName(pm.Labels.Get("process")); name != "" { + seen[name] = true + mx[px+name+"_page_faults"] += int64(pm.Value) + } + } + for _, pm := range pms.FindByName(metricProcessPageFileBytes) { + if name := cleanProcessName(pm.Labels.Get("process")); name != "" { + seen[name] = true + mx[px+name+"_page_file_bytes"] += int64(pm.Value) + } + } + for _, pm := range pms.FindByName(metricProcessThreads) { + if name := cleanProcessName(pm.Labels.Get("process")); name != "" { + seen[name] = true + mx[px+name+"_threads"] += int64(pm.Value) + } + } + for _, pm := range pms.FindByName(metricProcessCPUHandles) { + if name := cleanProcessName(pm.Labels.Get("process")); name != "" { + seen[name] = true + mx[px+name+"_handles"] += int64(pm.Value) + } + } + + for proc := range seen { + if !w.cache.processes[proc] { + w.cache.processes[proc] = true + w.addProcessToCharts(proc) + } + } + for proc := range w.cache.processes { + if !seen[proc] { + delete(w.cache.processes, proc) + w.removeProcessFromCharts(proc) + } + } +} + +func cleanProcessName(name string) string { + return strings.ReplaceAll(name, " ", "_") +} -- cgit v1.2.3