Skip to content

Commit 45847c7

Browse files
committed
mon: pind_ prefix for metrics, time in state
1 parent 626affa commit 45847c7

File tree

2 files changed

+37
-33
lines changed

2 files changed

+37
-33
lines changed

pkg/monitoring/collector.go

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package monitoring
33
import (
44
"github.com/prometheus/client_golang/prometheus"
55
"strconv"
6-
"time"
76
)
87

98
type StaticCollector struct {
@@ -34,28 +33,28 @@ type PoolNodeCollector struct {
3433
func NewPoolCollector(nodesCount int) *PoolCollector {
3534
ent := &PoolCollector{}
3635

37-
ent.IdleLoad0 = prometheus.NewDesc("pool_idle_load0",
38-
"400, 600, 800 %",
36+
ent.IdleLoad0 = prometheus.NewDesc("pind_pool_idle_load0",
37+
"idle cores load, like 400, 600, 800 %",
3938
nil, nil,
4039
)
41-
ent.IdleLoad1 = prometheus.NewDesc("pool_idle_load1",
42-
"0-100 %",
40+
ent.IdleLoad1 = prometheus.NewDesc("pind_pool_idle_load1",
41+
"idle cores load, like 0-100 %",
4342
nil, nil,
4443
)
45-
ent.LoadFree0 = prometheus.NewDesc("pool_load_free0",
46-
"400, 600, 800 %",
44+
ent.LoadFree0 = prometheus.NewDesc("pind_pool_load_free0",
45+
"free cores load, like 400, 600, 800 %",
4746
nil, nil,
4847
)
49-
ent.LoadFree1 = prometheus.NewDesc("pool_load_free1",
50-
"0-100 %",
48+
ent.LoadFree1 = prometheus.NewDesc("pind_pool_load_free1",
49+
"free cores load, like 0-100 %",
5150
nil, nil,
5251
)
53-
ent.LoadUsed0 = prometheus.NewDesc("pool_load_used0",
54-
"400, 600, 800 %",
52+
ent.LoadUsed0 = prometheus.NewDesc("pind_pool_load_used0",
53+
"used cores load, like 400, 600, 800 %",
5554
nil, nil,
5655
)
57-
ent.LoadUsed1 = prometheus.NewDesc("pool_load_used1",
58-
"0-100 %",
56+
ent.LoadUsed1 = prometheus.NewDesc("pind_pool_load_used1",
57+
"used cores load, like 0-100 %",
5958
nil, nil,
6059
)
6160

@@ -68,20 +67,20 @@ func NewPoolCollector(nodesCount int) *PoolCollector {
6867
"node": strconv.Itoa(i),
6968
}
7069

71-
node.LoadFree0 = prometheus.NewDesc("node_load_free0",
72-
"400, 600, 800 %",
70+
node.LoadFree0 = prometheus.NewDesc("pind_node_load_free0",
71+
"node free cores load, like 400, 600, 800 %",
7372
nil, labels0,
7473
)
75-
node.LoadFree1 = prometheus.NewDesc("node_load_free1",
76-
"0-100 %",
74+
node.LoadFree1 = prometheus.NewDesc("pind_node_load_free1",
75+
"node free cores load, like 0-100 %",
7776
nil, labels0,
7877
)
79-
node.LoadUsed0 = prometheus.NewDesc("node_load_used0",
80-
"400, 600, 800 %",
78+
node.LoadUsed0 = prometheus.NewDesc("pind_node_load_used0",
79+
"node used cores load, like 400, 600, 800 %",
8180
nil, labels0,
8281
)
83-
node.LoadUsed1 = prometheus.NewDesc("node_load_used1",
84-
"0-100 %",
82+
node.LoadUsed1 = prometheus.NewDesc("pind_node_load_used1",
83+
"node used cores load, like 0-100 %",
8584
nil, labels0,
8685
)
8786

@@ -126,13 +125,13 @@ func (x *StaticCollector) Collect(ch chan<- prometheus.Metric) {
126125
m4 := prometheus.MustNewConstMetric(x.PoolCollector.LoadUsed0, prometheus.GaugeValue, x.State.Pool.LoadUsed0)
127126
m5 := prometheus.MustNewConstMetric(x.PoolCollector.LoadUsed1, prometheus.GaugeValue, x.State.Pool.LoadUsed1)
128127

129-
now := time.Now()
130-
mt0 := prometheus.NewMetricWithTimestamp(now, m0)
131-
mt1 := prometheus.NewMetricWithTimestamp(now, m1)
132-
mt2 := prometheus.NewMetricWithTimestamp(now, m2)
133-
mt3 := prometheus.NewMetricWithTimestamp(now, m3)
134-
mt4 := prometheus.NewMetricWithTimestamp(now, m4)
135-
mt5 := prometheus.NewMetricWithTimestamp(now, m5)
128+
t0 := x.State.Time
129+
mt0 := prometheus.NewMetricWithTimestamp(t0, m0)
130+
mt1 := prometheus.NewMetricWithTimestamp(t0, m1)
131+
mt2 := prometheus.NewMetricWithTimestamp(t0, m2)
132+
mt3 := prometheus.NewMetricWithTimestamp(t0, m3)
133+
mt4 := prometheus.NewMetricWithTimestamp(t0, m4)
134+
mt5 := prometheus.NewMetricWithTimestamp(t0, m5)
136135

137136
ch <- mt0
138137
ch <- mt1
@@ -152,10 +151,10 @@ func (x *StaticCollector) Collect(ch chan<- prometheus.Metric) {
152151
mn2 := prometheus.MustNewConstMetric(nodeCollector.LoadUsed0, prometheus.GaugeValue, node.LoadUsed0)
153152
mn3 := prometheus.MustNewConstMetric(nodeCollector.LoadUsed1, prometheus.GaugeValue, node.LoadUsed1)
154153

155-
mnt0 := prometheus.NewMetricWithTimestamp(now, mn0)
156-
mnt1 := prometheus.NewMetricWithTimestamp(now, mn1)
157-
mnt2 := prometheus.NewMetricWithTimestamp(now, mn2)
158-
mnt3 := prometheus.NewMetricWithTimestamp(now, mn3)
154+
mnt0 := prometheus.NewMetricWithTimestamp(t0, mn0)
155+
mnt1 := prometheus.NewMetricWithTimestamp(t0, mn1)
156+
mnt2 := prometheus.NewMetricWithTimestamp(t0, mn2)
157+
mnt3 := prometheus.NewMetricWithTimestamp(t0, mn3)
159158

160159
ch <- mnt0
161160
ch <- mnt1

pkg/monitoring/state.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package monitoring
22

3+
import "time"
4+
35
type State struct {
6+
Time time.Time
47
Pool *Pool
58
}
69

@@ -24,9 +27,11 @@ type PoolNode struct {
2427
}
2528

2629
func NewState() *State {
30+
now := time.Now()
2731
pool := &Pool{}
2832

2933
return &State{
30-
pool,
34+
Time: now,
35+
Pool: pool,
3136
}
3237
}

0 commit comments

Comments
 (0)