github.com/netdata/go.d.plugin@v0.58.1/modules/windows/collect_cpu.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package windows 4 5 import ( 6 "github.com/netdata/go.d.plugin/pkg/prometheus" 7 ) 8 9 const ( 10 metricCPUTimeTotal = "windows_cpu_time_total" 11 metricCPUInterruptsTotal = "windows_cpu_interrupts_total" 12 metricCPUDPCsTotal = "windows_cpu_dpcs_total" 13 metricCPUCStateTotal = "windows_cpu_cstate_seconds_total" 14 ) 15 16 func (w *Windows) collectCPU(mx map[string]int64, pms prometheus.Series) { 17 if !w.cache.collection[collectorCPU] { 18 w.cache.collection[collectorCPU] = true 19 w.addCPUCharts() 20 } 21 22 seen := make(map[string]bool) 23 for _, pm := range pms.FindByName(metricCPUTimeTotal) { 24 core := pm.Labels.Get("core") 25 mode := pm.Labels.Get("mode") 26 if core == "" || mode == "" { 27 continue 28 } 29 30 seen[core] = true 31 mx["cpu_"+mode+"_time"] += int64(pm.Value * precision) 32 mx["cpu_core_"+core+"_"+mode+"_time"] += int64(pm.Value * precision) 33 } 34 35 for _, pm := range pms.FindByName(metricCPUInterruptsTotal) { 36 core := pm.Labels.Get("core") 37 if core == "" { 38 continue 39 } 40 41 seen[core] = true 42 mx["cpu_core_"+core+"_interrupts"] += int64(pm.Value) 43 } 44 45 for _, pm := range pms.FindByName(metricCPUDPCsTotal) { 46 core := pm.Labels.Get("core") 47 if core == "" { 48 continue 49 } 50 51 seen[core] = true 52 mx["cpu_core_"+core+"_dpcs"] += int64(pm.Value) 53 } 54 55 for _, pm := range pms.FindByName(metricCPUCStateTotal) { 56 core := pm.Labels.Get("core") 57 state := pm.Labels.Get("state") 58 if core == "" || state == "" { 59 continue 60 } 61 62 seen[core] = true 63 mx["cpu_core_"+core+"_cstate_"+state] += int64(pm.Value * precision) 64 } 65 66 for core := range seen { 67 if !w.cache.cores[core] { 68 w.cache.cores[core] = true 69 w.addCPUCoreCharts(core) 70 } 71 } 72 for core := range w.cache.cores { 73 if !seen[core] { 74 delete(w.cache.cores, core) 75 w.removeCPUCoreCharts(core) 76 } 77 } 78 }