Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/node_exporter/collectors.go
5341 views
1
package node_exporter // nolint:golint
2
3
import (
4
"fmt"
5
"sort"
6
7
"gopkg.in/alecthomas/kingpin.v2"
8
)
9
10
// CollectorState represents the default state of the collector, where it can
11
// either be enabled or disabled
12
type CollectorState bool
13
14
const (
15
// CollectorStateDisabled represents a disabled collector that will not run
16
// and collect metrics.
17
CollectorStateDisabled CollectorState = false
18
19
// CollectorStateEnabled represents an enabled collector that _will_ run
20
// and collect metrics.
21
CollectorStateEnabled CollectorState = true
22
)
23
24
// Collector is a specific collector that node_exporter runs.
25
type Collector string
26
27
// Collection of collectors defined by node_exporter
28
const (
29
CollectorARP = "arp"
30
CollectorBCache = "bcache"
31
CollectorBTRFS = "btrfs"
32
CollectorBonding = "bonding"
33
CollectorBootTime = "boottime"
34
CollectorBuddyInfo = "buddyinfo"
35
CollectorCPU = "cpu"
36
CollectorCPUFreq = "cpufreq"
37
CollectorConntrack = "conntrack"
38
CollectorDMI = "dmi"
39
CollectorDRBD = "drbd"
40
CollectorDRM = "drm"
41
CollectorDevstat = "devstat"
42
CollectorDiskstats = "diskstats"
43
CollectorEDAC = "edac"
44
CollectorEntropy = "entropy"
45
CollectorEthtool = "ethtool"
46
CollectorExec = "exec"
47
CollectorFibrechannel = "fibrechannel"
48
CollectorFileFD = "filefd"
49
CollectorFilesystem = "filesystem"
50
CollectorHWMon = "hwmon"
51
CollectorIPVS = "ipvs"
52
CollectorInfiniband = "infiniband"
53
CollectorInterrupts = "interrupts"
54
CollectorKSMD = "ksmd"
55
CollectorLnstat = "lnstat"
56
CollectorLoadAvg = "loadavg"
57
CollectorLogind = "logind"
58
CollectorMDADM = "mdadm"
59
CollectorMeminfo = "meminfo"
60
CollectorMeminfoNuma = "meminfo_numa"
61
CollectorMountstats = "mountstats"
62
CollectorNFS = "nfs"
63
CollectorNFSD = "nfsd"
64
CollectorNTP = "ntp"
65
CollectorNVME = "nvme"
66
CollectorNetclass = "netclass"
67
CollectorNetdev = "netdev"
68
CollectorNetstat = "netstat"
69
CollectorNetworkRoute = "network_route"
70
CollectorOS = "os"
71
CollectorPerf = "perf"
72
CollectorPowersuppply = "powersupplyclass"
73
CollectorPressure = "pressure"
74
CollectorProcesses = "processes"
75
CollectorQDisc = "qdisc"
76
CollectorRAPL = "rapl"
77
CollectorRunit = "runit"
78
CollectorSchedstat = "schedstat"
79
CollectorSockstat = "sockstat"
80
CollectorSoftnet = "softnet"
81
CollectorStat = "stat"
82
CollectorSupervisord = "supervisord"
83
CollectorSystemd = "systemd"
84
CollectorTCPStat = "tcpstat"
85
CollectorTapestats = "tapestats"
86
CollectorTextfile = "textfile"
87
CollectorThermal = "thermal"
88
CollectorThermalzone = "thermal_zone"
89
CollectorTime = "time"
90
CollectorTimex = "timex"
91
CollectorUDPQueues = "udp_queues"
92
CollectorUname = "uname"
93
CollectorVMStat = "vmstat"
94
CollectorWiFi = "wifi"
95
CollectorXFS = "xfs"
96
CollectorZFS = "zfs"
97
CollectorZoneinfo = "zoneinfo"
98
CollectorCGroups = "cgroups"
99
CollectorSELinux = "selinux"
100
CollectorSlabInfo = "slabinfo"
101
CollectorSysctl = "sysctl"
102
)
103
104
// Collectors holds a map of known collector names to their default
105
// state.
106
var Collectors = map[string]CollectorState{
107
CollectorARP: CollectorStateEnabled,
108
CollectorBCache: CollectorStateEnabled,
109
CollectorBTRFS: CollectorStateEnabled,
110
CollectorBonding: CollectorStateEnabled,
111
CollectorBootTime: CollectorStateEnabled,
112
CollectorBuddyInfo: CollectorStateDisabled,
113
CollectorCGroups: CollectorStateDisabled,
114
CollectorCPU: CollectorStateEnabled,
115
CollectorCPUFreq: CollectorStateEnabled,
116
CollectorConntrack: CollectorStateEnabled,
117
CollectorDMI: CollectorStateEnabled,
118
CollectorDRBD: CollectorStateDisabled,
119
CollectorDRM: CollectorStateDisabled,
120
CollectorDevstat: CollectorStateDisabled,
121
CollectorDiskstats: CollectorStateEnabled,
122
CollectorEDAC: CollectorStateEnabled,
123
CollectorEntropy: CollectorStateEnabled,
124
CollectorEthtool: CollectorStateDisabled,
125
CollectorExec: CollectorStateEnabled,
126
CollectorFibrechannel: CollectorStateEnabled,
127
CollectorFileFD: CollectorStateEnabled,
128
CollectorFilesystem: CollectorStateEnabled,
129
CollectorHWMon: CollectorStateEnabled,
130
CollectorIPVS: CollectorStateEnabled,
131
CollectorInfiniband: CollectorStateEnabled,
132
CollectorInterrupts: CollectorStateDisabled,
133
CollectorKSMD: CollectorStateDisabled,
134
CollectorLnstat: CollectorStateDisabled,
135
CollectorLoadAvg: CollectorStateEnabled,
136
CollectorLogind: CollectorStateDisabled,
137
CollectorMDADM: CollectorStateEnabled,
138
CollectorMeminfo: CollectorStateEnabled,
139
CollectorMeminfoNuma: CollectorStateDisabled,
140
CollectorMountstats: CollectorStateDisabled,
141
CollectorNFS: CollectorStateEnabled,
142
CollectorNFSD: CollectorStateEnabled,
143
CollectorNTP: CollectorStateDisabled,
144
CollectorNVME: CollectorStateEnabled,
145
CollectorNetclass: CollectorStateEnabled,
146
CollectorNetdev: CollectorStateEnabled,
147
CollectorNetstat: CollectorStateEnabled,
148
CollectorNetworkRoute: CollectorStateDisabled,
149
CollectorOS: CollectorStateEnabled,
150
CollectorPerf: CollectorStateDisabled,
151
CollectorPowersuppply: CollectorStateEnabled,
152
CollectorPressure: CollectorStateEnabled,
153
CollectorProcesses: CollectorStateDisabled,
154
CollectorQDisc: CollectorStateDisabled,
155
CollectorRAPL: CollectorStateEnabled,
156
CollectorRunit: CollectorStateDisabled,
157
CollectorSchedstat: CollectorStateEnabled,
158
CollectorSELinux: CollectorStateEnabled,
159
CollectorSlabInfo: CollectorStateDisabled,
160
CollectorSockstat: CollectorStateEnabled,
161
CollectorSoftnet: CollectorStateEnabled,
162
CollectorStat: CollectorStateEnabled,
163
CollectorSupervisord: CollectorStateDisabled,
164
CollectorSysctl: CollectorStateDisabled,
165
CollectorSystemd: CollectorStateDisabled,
166
CollectorTCPStat: CollectorStateDisabled,
167
CollectorTapestats: CollectorStateEnabled,
168
CollectorTextfile: CollectorStateEnabled,
169
CollectorThermal: CollectorStateEnabled,
170
CollectorThermalzone: CollectorStateEnabled,
171
CollectorTime: CollectorStateEnabled,
172
CollectorTimex: CollectorStateEnabled,
173
CollectorUDPQueues: CollectorStateEnabled,
174
CollectorUname: CollectorStateEnabled,
175
CollectorVMStat: CollectorStateEnabled,
176
CollectorWiFi: CollectorStateDisabled,
177
CollectorXFS: CollectorStateEnabled,
178
CollectorZFS: CollectorStateEnabled,
179
CollectorZoneinfo: CollectorStateDisabled,
180
}
181
182
// MapCollectorsToFlags takes in a map of collector keys and their states and
183
// converts them into flags that node_exporter expects. Collectors that are not
184
// defined will be ignored, which will be the case for collectors that are not
185
// supported on the host system.
186
func MapCollectorsToFlags(cs map[string]CollectorState) (flags []string) {
187
for collector, state := range cs {
188
flag := fmt.Sprintf("collector.%s", collector)
189
190
// Skip the flag if it's not defined in kingpin
191
if kingpin.CommandLine.GetFlag(flag) == nil {
192
continue
193
}
194
195
switch state {
196
case CollectorStateEnabled:
197
flags = append(flags, "--"+flag)
198
case CollectorStateDisabled:
199
flags = append(flags, "--no-"+flag)
200
}
201
}
202
203
sort.Strings(flags)
204
return
205
}
206
207
// DisableUnavailableCollectors disables collectors that are not available on
208
// the host machine.
209
func DisableUnavailableCollectors(cs map[string]CollectorState) {
210
for collector := range cs {
211
flag := fmt.Sprintf("collector.%s", collector)
212
213
// If kingpin doesn't have the flag, the collector is unavailable.
214
if kingpin.CommandLine.GetFlag(flag) == nil {
215
cs[collector] = CollectorStateDisabled
216
}
217
}
218
}
219
220