Skip to content

Commit f07bc4e

Browse files
committed
process metrics reset
1 parent 13a6f26 commit f07bc4e

File tree

6 files changed

+399
-74
lines changed

6 files changed

+399
-74
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
PROGRAM_NAME="boshi_exporter"
4-
VERSION="0.0.4"
4+
VERSION="0.0.5"
55

66
DIST_DIR=".dist"
77

collectors/collector.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,10 @@ func NewBoshInstanceCollector(programName, programVersion string, metricsContext
3030
}, nil
3131
}
3232

33-
func (b *BoshInstanceCollector) collectAll(metrics Metrics, ch chan<- prometheus.Metric) {
34-
for _, c := range metrics.Collectors() {
35-
c.Collect(ch)
36-
}
37-
}
38-
39-
func (b *BoshInstanceCollector) describeAll(metrics Metrics, ch chan<- *prometheus.Desc) {
40-
for _, c := range metrics.Collectors() {
41-
c.Describe(ch)
42-
}
43-
}
44-
4533
func (b *BoshInstanceCollector) Describe(ch chan<- *prometheus.Desc) {
46-
b.describeAll(b.baseMetrics, ch)
47-
b.describeAll(b.monitMetrics, ch)
48-
b.describeAll(b.systemMetrics, ch)
34+
b.describeAllMetrics(b.baseMetrics, ch)
35+
b.describeAllMetrics(b.monitMetrics, ch)
36+
b.describeAllMetrics(b.systemMetrics, ch)
4937
}
5038

5139
func (b *BoshInstanceCollector) Collect(ch chan<- prometheus.Metric) {
@@ -66,7 +54,19 @@ func (b *BoshInstanceCollector) Collect(ch chan<- prometheus.Metric) {
6654
b.systemMetrics.Emit(systemStat)
6755
}
6856

69-
b.collectAll(b.baseMetrics, ch)
70-
b.collectAll(b.monitMetrics, ch)
71-
b.collectAll(b.systemMetrics, ch)
57+
b.collectAllMetrics(b.baseMetrics, ch)
58+
b.collectAllMetrics(b.monitMetrics, ch)
59+
b.collectAllMetrics(b.systemMetrics, ch)
60+
}
61+
62+
func (b *BoshInstanceCollector) collectAllMetrics(metrics Metrics, ch chan<- prometheus.Metric) {
63+
for _, c := range metrics.Collectors() {
64+
c.Collect(ch)
65+
}
66+
}
67+
68+
func (b *BoshInstanceCollector) describeAllMetrics(metrics Metrics, ch chan<- *prometheus.Desc) {
69+
for _, c := range metrics.Collectors() {
70+
c.Describe(ch)
71+
}
7272
}

collectors/metrics_monit.go

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,18 @@ const (
1414
monitProcessNameLabel = "process_name"
1515
monitProcessPidLabel = "process_pid"
1616
monitProcessParentPidLabel = "process_parent_pid"
17+
monitCPUModeLabel = "mode"
1718
)
1819

1920
type MonitMetrics struct {
2021
MonitInfo *prometheus.GaugeVec
2122
MonitUptime *prometheus.GaugeVec
2223

2324
SysStatusInfo *prometheus.GaugeVec
24-
SysUptimeSeconds *prometheus.GaugeVec
2525
SysLoadAvg1 *prometheus.GaugeVec
2626
SysLoadAvg5 *prometheus.GaugeVec
2727
SysLoadAvg15 *prometheus.GaugeVec
28-
SysCPUUserRatio *prometheus.GaugeVec
29-
SysCPUSystemRatio *prometheus.GaugeVec
30-
SysCPUWaitRatio *prometheus.GaugeVec
28+
SysCPURatio *prometheus.GaugeVec
3129
SysMemoryUsedBytes *prometheus.GaugeVec
3230
SysMemoryUsageRatio *prometheus.GaugeVec
3331
SysSwapUsedBytes *prometheus.GaugeVec
@@ -59,62 +57,67 @@ func NewMonitMetrics(metricsContext *config.MetricsContext, spec *fetchers.Insta
5957
ConstLabels: *constantLabels,
6058
}
6159
}
62-
monitInfoLabels := []string{monitVersionLabel}
63-
var monitLabels []string
64-
sysInfoLabels := []string{monitMonitoringStatusLabel, monitServiceStatusLabel}
65-
var sysLabels []string
66-
procInfoLabels := []string{monitProcessNameLabel, monitProcessPidLabel}
67-
procLabels := []string{monitProcessNameLabel, monitMonitoringStatusLabel, monitServiceStatusLabel, monitProcessPidLabel, monitProcessParentPidLabel}
60+
procInfoLabels := []string{monitProcessNameLabel, monitMonitoringStatusLabel, monitServiceStatusLabel, monitProcessPidLabel, monitProcessParentPidLabel}
61+
procLabels := []string{monitProcessNameLabel, monitProcessPidLabel}
6862
return &MonitMetrics{
6963
// Monit metrics
70-
MonitInfo: promauto.NewGaugeVec(opts("monit_info", "The Monit daemon information", instanceLabels), monitInfoLabels),
71-
MonitUptime: promauto.NewGaugeVec(opts("uptime_seconds", "Monit uptime since last start (seconds)", instanceLabels), monitLabels),
64+
MonitInfo: promauto.NewGaugeVec(opts("info", "The Monit daemon information", instanceLabels), []string{monitVersionLabel}),
65+
MonitUptime: promauto.NewGaugeVec(opts("uptime_seconds", "Monit uptime since last start (seconds)", instanceLabels), []string{}),
7266

7367
// System metrics
74-
SysStatusInfo: promauto.NewGaugeVec(opts("system_status_info", "System status info (e.g., running, monitored)", instanceLabels), sysInfoLabels),
75-
SysUptimeSeconds: promauto.NewGaugeVec(opts("system_uptime_seconds", "System uptime since last boot (seconds)", instanceLabels), sysLabels),
76-
SysLoadAvg1: promauto.NewGaugeVec(opts("system_load_avg_1m", "System 1-minute load average", instanceLabels), sysLabels),
77-
SysLoadAvg5: promauto.NewGaugeVec(opts("system_load_avg_5m", "System 5-minute load average", instanceLabels), sysLabels),
78-
SysLoadAvg15: promauto.NewGaugeVec(opts("system_load_avg_15m", "System 15-minute load average", instanceLabels), sysLabels),
79-
SysCPUUserRatio: promauto.NewGaugeVec(opts("system_cpu_user_ratio", "System CPU time spent in user mode fraction (1=100%)", instanceLabels), sysLabels),
80-
SysCPUSystemRatio: promauto.NewGaugeVec(opts("system_cpu_system_ratio", "System CPU time spent in kernel/system mode fraction (1=100%)", instanceLabels), sysLabels),
81-
SysCPUWaitRatio: promauto.NewGaugeVec(opts("system_cpu_wait_ratio", "System CPU time spent waiting for I/O fraction (1=100%)", instanceLabels), sysLabels),
82-
SysMemoryUsedBytes: promauto.NewGaugeVec(opts("system_memory_used_bytes", "System memory used in bytes", instanceLabels), sysLabels),
83-
SysMemoryUsageRatio: promauto.NewGaugeVec(opts("system_memory_usage_ratio", "System memory used as a fraction of total (1=100%)", instanceLabels), sysLabels),
84-
SysSwapUsedBytes: promauto.NewGaugeVec(opts("system_swap_used_bytes", "System swap used in bytes", instanceLabels), sysLabels),
85-
SysSwapUsageRatio: promauto.NewGaugeVec(opts("system_swap_usage_ratio", "System swap used as a fraction of total (1=100%)", instanceLabels), sysLabels),
86-
SysCollectedTimestampSeconds: promauto.NewGaugeVec(opts("system_collected_timestamp_seconds", "System data collection time as Unix timestamp (seconds).", instanceLabels), sysLabels),
68+
SysStatusInfo: promauto.NewGaugeVec(opts("system_status_info", "System status info (e.g., running, monitored)", instanceLabels), []string{monitMonitoringStatusLabel, monitServiceStatusLabel}),
69+
SysLoadAvg1: promauto.NewGaugeVec(opts("system_load1", "System 1-minute load average", instanceLabels), []string{}),
70+
SysLoadAvg5: promauto.NewGaugeVec(opts("system_load5", "System 5-minute load average", instanceLabels), []string{}),
71+
SysLoadAvg15: promauto.NewGaugeVec(opts("system_load15", "System 15-minute load average", instanceLabels), []string{}),
72+
SysCPURatio: promauto.NewGaugeVec(opts("system_cpu_ratio", "System CPU time spent in the mode fraction (1=100%)", instanceLabels), []string{monitCPUModeLabel}),
73+
SysMemoryUsedBytes: promauto.NewGaugeVec(opts("system_memory_used_bytes", "System memory used in bytes", instanceLabels), []string{}),
74+
SysMemoryUsageRatio: promauto.NewGaugeVec(opts("system_memory_usage_ratio", "System memory used as a fraction of total (1=100%)", instanceLabels), []string{}),
75+
SysSwapUsedBytes: promauto.NewGaugeVec(opts("system_swap_used_bytes", "System swap used in bytes", instanceLabels), []string{}),
76+
SysSwapUsageRatio: promauto.NewGaugeVec(opts("system_swap_usage_ratio", "System swap used as a fraction of total (1=100%)", instanceLabels), []string{}),
77+
SysCollectedTimestampSeconds: promauto.NewGaugeVec(opts("system_collected_timestamp_seconds", "System data collection time as Unix timestamp (seconds).", instanceLabels), []string{}),
8778

8879
// Process metrics
89-
ProcStatusInfo: promauto.NewGaugeVec(opts("process_status_info", "Monit process and monitoring status information", instanceLabels), procLabels),
90-
ProcUptime: promauto.NewGaugeVec(opts("process_uptime_seconds", "Monit process uptime since last start (seconds)", instanceLabels), procInfoLabels),
91-
ProcChildrenCount: promauto.NewGaugeVec(opts("process_children_count", "Number of child processes", instanceLabels), procInfoLabels),
92-
ProcMemoryUsedBytes: promauto.NewGaugeVec(opts("process_memory_used_bytes", "Process memory used in bytes", instanceLabels), procInfoLabels),
93-
ProcMemoryUsedBytesTotal: promauto.NewGaugeVec(opts("process_memory_used_bytes_total", "Total process (with subprocesses) memory used in bytes", instanceLabels), procInfoLabels),
94-
ProcMemoryUsageRatio: promauto.NewGaugeVec(opts("process_memory_usage_ratio", "Process memory usage fraction (1=100%)", instanceLabels), procInfoLabels),
95-
ProcMemoryUsageRatioTotal: promauto.NewGaugeVec(opts("process_memory_usage_ratio_total", "Total process (with subprocesses) memory usage fraction (1=100%)", instanceLabels), procInfoLabels),
96-
ProcCPUUsageRatio: promauto.NewGaugeVec(opts("process_cpu_usage_ratio", "Process CPU usage fraction (1=100%)", instanceLabels), procInfoLabels),
97-
ProcCPUUsageRatioTotal: promauto.NewGaugeVec(opts("process_cpu_usage_ratio_total", "Total process (with subprocesses) CPU usage fraction (1=100%)", instanceLabels), procInfoLabels),
98-
ProcCollectedTimestampSeconds: promauto.NewGaugeVec(opts("process_collected_timestamp_seconds", "Process data collection time as Unix timestamp (seconds).", instanceLabels), procInfoLabels),
80+
ProcStatusInfo: promauto.NewGaugeVec(opts("process_status_info", "Monit process and monitoring status information", instanceLabels), procInfoLabels),
81+
ProcUptime: promauto.NewGaugeVec(opts("process_uptime_seconds", "Monit process uptime since last start (seconds)", instanceLabels), procLabels),
82+
ProcChildrenCount: promauto.NewGaugeVec(opts("process_children_count", "Number of child processes", instanceLabels), procLabels),
83+
ProcMemoryUsedBytes: promauto.NewGaugeVec(opts("process_memory_used_bytes", "Process memory used in bytes", instanceLabels), procLabels),
84+
ProcMemoryUsedBytesTotal: promauto.NewGaugeVec(opts("process_memory_used_bytes_total", "Total process (with subprocesses) memory used in bytes", instanceLabels), procLabels),
85+
ProcMemoryUsageRatio: promauto.NewGaugeVec(opts("process_memory_usage_ratio", "Process memory usage fraction (1=100%)", instanceLabels), procLabels),
86+
ProcMemoryUsageRatioTotal: promauto.NewGaugeVec(opts("process_memory_usage_ratio_total", "Total process (with subprocesses) memory usage fraction (1=100%)", instanceLabels), procLabels),
87+
ProcCPUUsageRatio: promauto.NewGaugeVec(opts("process_cpu_usage_ratio", "Process CPU usage fraction (1=100%)", instanceLabels), procLabels),
88+
ProcCPUUsageRatioTotal: promauto.NewGaugeVec(opts("process_cpu_usage_ratio_total", "Total process (with subprocesses) CPU usage fraction (1=100%)", instanceLabels), procLabels),
89+
ProcCollectedTimestampSeconds: promauto.NewGaugeVec(opts("process_collected_timestamp_seconds", "Process data collection time as Unix timestamp (seconds).", instanceLabels), procLabels),
9990
}
10091
}
10192

10293
func (m *MonitMetrics) Emit(stat *fetchers.MonitStat) {
94+
m.MonitInfo.Reset()
10395
m.MonitInfo.With(prometheus.Labels{monitVersionLabel: stat.Version}).Set(1)
10496
m.MonitUptime.With(prometheus.Labels{}).Set(stat.Uptime.Seconds())
97+
m.SysStatusInfo.Reset()
10598
m.SysStatusInfo.With(prometheus.Labels{monitMonitoringStatusLabel: stat.System.MonitoringStatus, monitServiceStatusLabel: stat.System.Status}).Set(1)
10699
m.SysLoadAvg1.With(prometheus.Labels{}).Set(stat.System.LoadAvg1)
107100
m.SysLoadAvg5.With(prometheus.Labels{}).Set(stat.System.LoadAvg5)
108101
m.SysLoadAvg15.With(prometheus.Labels{}).Set(stat.System.LoadAvg15)
109-
m.SysCPUUserRatio.With(prometheus.Labels{}).Set(stat.System.CPUUserPercent / 100)
110-
m.SysCPUSystemRatio.With(prometheus.Labels{}).Set(stat.System.CPUSystemPercent / 100)
111-
m.SysCPUWaitRatio.With(prometheus.Labels{}).Set(stat.System.CPUWaitPercent / 100)
102+
m.SysCPURatio.With(prometheus.Labels{monitCPUModeLabel: "user"}).Set(stat.System.CPUUserPercent / 100)
103+
m.SysCPURatio.With(prometheus.Labels{monitCPUModeLabel: "system"}).Set(stat.System.CPUSystemPercent / 100)
104+
m.SysCPURatio.With(prometheus.Labels{monitCPUModeLabel: "iowait"}).Set(stat.System.CPUIOWaitPercent / 100)
112105
m.SysMemoryUsedBytes.With(prometheus.Labels{}).Set(float64(stat.System.MemoryUsedBytes))
113106
m.SysMemoryUsageRatio.With(prometheus.Labels{}).Set(stat.System.MemoryUsedPercent / 100)
114107
m.SysSwapUsedBytes.With(prometheus.Labels{}).Set(float64(stat.System.SwapUsedBytes))
115108
m.SysSwapUsageRatio.With(prometheus.Labels{}).Set(stat.System.SwapUsedPercent / 100)
116109
m.SysCollectedTimestampSeconds.With(prometheus.Labels{}).Set(float64(stat.System.DataCollected.Unix()))
117110

111+
m.ProcStatusInfo.Reset()
112+
m.ProcUptime.Reset()
113+
m.ProcChildrenCount.Reset()
114+
m.ProcMemoryUsedBytes.Reset()
115+
m.ProcMemoryUsedBytesTotal.Reset()
116+
m.ProcMemoryUsageRatio.Reset()
117+
m.ProcMemoryUsageRatioTotal.Reset()
118+
m.ProcCPUUsageRatio.Reset()
119+
m.ProcCPUUsageRatioTotal.Reset()
120+
m.ProcCollectedTimestampSeconds.Reset()
118121
for name, status := range stat.Processes {
119122
procInfoLabels := prometheus.Labels{
120123
monitProcessNameLabel: name,
@@ -124,7 +127,6 @@ func (m *MonitMetrics) Emit(stat *fetchers.MonitStat) {
124127
monitProcessParentPidLabel: status.ParentPID,
125128
}
126129
m.ProcStatusInfo.With(procInfoLabels).Set(1)
127-
128130
procLabels := prometheus.Labels{
129131
monitProcessNameLabel: name,
130132
monitProcessPidLabel: status.PID,

fetchers/monit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type MonitSystemStatus struct {
4949
LoadAvg15 float64 // 15-minute load average
5050
CPUUserPercent float64 // CPU time spent in user mode (%)
5151
CPUSystemPercent float64 // CPU time spent in kernel/system mode (%)
52-
CPUWaitPercent float64 // CPU time spent waiting for I/O (%)
52+
CPUIOWaitPercent float64 // CPU time spent waiting for I/O (%)
5353
MemoryUsedBytes uint64 // memory used in bytes
5454
MemoryUsedPercent float64 // memory used as a percentage of total
5555
SwapUsedBytes uint64 // swap used in bytes
@@ -228,7 +228,7 @@ func (s *MonitSystemStatus) parseMetricEntry(key, val string) {
228228
case "cpu":
229229
// val example: "2.0%us 4.0%sy 0.0%wa"
230230
_, _ = fmt.Sscanf(val, "%f%%us %f%%sy %f%%wa",
231-
&s.CPUUserPercent, &s.CPUSystemPercent, &s.CPUWaitPercent)
231+
&s.CPUUserPercent, &s.CPUSystemPercent, &s.CPUIOWaitPercent)
232232

233233
case "memory usage":
234234
// val example: "227240 kB [23.0%]"

0 commit comments

Comments
 (0)