1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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, " ", "_")
}
|