@@ -2,65 +2,129 @@ package monitoring
2
2
3
3
import (
4
4
"github.com/prometheus/client_golang/prometheus"
5
+ "strconv"
5
6
"time"
6
7
)
7
8
8
9
type StaticCollector struct {
10
+ PoolCollector * PoolCollector
11
+
12
+ State * State
13
+ }
14
+
15
+ type PoolCollector struct {
9
16
IdleLoad0 * prometheus.Desc
10
17
IdleLoad1 * prometheus.Desc
11
18
LoadFree0 * prometheus.Desc
12
19
LoadFree1 * prometheus.Desc
13
20
LoadUsed0 * prometheus.Desc
14
21
LoadUsed1 * prometheus.Desc
15
22
16
- State * State
23
+ Nodes [] * PoolNodeCollector
17
24
}
18
25
19
- func NewStaticCollector () * StaticCollector {
20
- ent := & StaticCollector {}
26
+ type PoolNodeCollector struct {
27
+ Index int
28
+ LoadFree0 * prometheus.Desc
29
+ LoadFree1 * prometheus.Desc
30
+ LoadUsed0 * prometheus.Desc
31
+ LoadUsed1 * prometheus.Desc
32
+ }
21
33
22
- ent .IdleLoad0 = prometheus .NewDesc ("idle_load0" ,
34
+ func NewPoolCollector (nodesCount int ) * PoolCollector {
35
+ ent := & PoolCollector {}
36
+
37
+ ent .IdleLoad0 = prometheus .NewDesc ("pool_idle_load0" ,
23
38
"400, 600, 800 %" ,
24
39
nil , nil ,
25
40
)
26
- ent .IdleLoad1 = prometheus .NewDesc ("idle_load1 " ,
41
+ ent .IdleLoad1 = prometheus .NewDesc ("pool_idle_load1 " ,
27
42
"0-100 %" ,
28
43
nil , nil ,
29
44
)
30
- ent .LoadFree0 = prometheus .NewDesc ("load_free0 " ,
45
+ ent .LoadFree0 = prometheus .NewDesc ("pool_load_free0 " ,
31
46
"400, 600, 800 %" ,
32
47
nil , nil ,
33
48
)
34
- ent .LoadFree1 = prometheus .NewDesc ("load_free1 " ,
49
+ ent .LoadFree1 = prometheus .NewDesc ("pool_load_free1 " ,
35
50
"0-100 %" ,
36
51
nil , nil ,
37
52
)
38
- ent .LoadUsed0 = prometheus .NewDesc ("load_used0 " ,
53
+ ent .LoadUsed0 = prometheus .NewDesc ("pool_load_used0 " ,
39
54
"400, 600, 800 %" ,
40
55
nil , nil ,
41
56
)
42
- ent .LoadUsed1 = prometheus .NewDesc ("load_used1 " ,
57
+ ent .LoadUsed1 = prometheus .NewDesc ("pool_load_used1 " ,
43
58
"0-100 %" ,
44
59
nil , nil ,
45
60
)
46
61
47
- ent .State = NewState ()
62
+ for i := 0 ; i < nodesCount ; i ++ {
63
+ node := & PoolNodeCollector {
64
+ Index : i ,
65
+ }
66
+
67
+ labels0 := prometheus.Labels {
68
+ "node" : strconv .Itoa (i ),
69
+ }
70
+
71
+ node .LoadFree0 = prometheus .NewDesc ("node_load_free0" ,
72
+ "400, 600, 800 %" ,
73
+ nil , labels0 ,
74
+ )
75
+ node .LoadFree1 = prometheus .NewDesc ("node_load_free1" ,
76
+ "0-100 %" ,
77
+ nil , labels0 ,
78
+ )
79
+ node .LoadUsed0 = prometheus .NewDesc ("node_load_used0" ,
80
+ "400, 600, 800 %" ,
81
+ nil , labels0 ,
82
+ )
83
+ node .LoadUsed1 = prometheus .NewDesc ("node_load_used1" ,
84
+ "0-100 %" ,
85
+ nil , labels0 ,
86
+ )
87
+
88
+ ent .Nodes = append (ent .Nodes , node )
89
+ }
90
+
91
+ return ent
92
+ }
93
+
94
+ func NewStaticCollector (nodesCount int ) * StaticCollector {
95
+ pool := NewPoolCollector (nodesCount )
96
+
97
+ ent := & StaticCollector {
98
+ PoolCollector : pool ,
99
+ }
48
100
49
101
return ent
50
102
}
51
103
52
104
func (x * StaticCollector ) Describe (ch chan <- * prometheus.Desc ) {
53
- ch <- x .IdleLoad0
54
- ch <- x .IdleLoad1
105
+ ch <- x .PoolCollector .IdleLoad0
106
+ ch <- x .PoolCollector .IdleLoad1
107
+ ch <- x .PoolCollector .LoadFree0
108
+ ch <- x .PoolCollector .LoadFree1
109
+ ch <- x .PoolCollector .LoadUsed0
110
+ ch <- x .PoolCollector .LoadUsed1
111
+
112
+ for _ , node := range x .PoolCollector .Nodes {
113
+ ch <- node .LoadFree0
114
+ ch <- node .LoadFree1
115
+ ch <- node .LoadUsed0
116
+ ch <- node .LoadUsed1
117
+ }
118
+
55
119
}
56
120
57
121
func (x * StaticCollector ) Collect (ch chan <- prometheus.Metric ) {
58
- m0 := prometheus .MustNewConstMetric (x .IdleLoad0 , prometheus .GaugeValue , x .State .IdleLoad0 )
59
- m1 := prometheus .MustNewConstMetric (x .IdleLoad1 , prometheus .GaugeValue , x .State .IdleLoad1 )
60
- m2 := prometheus .MustNewConstMetric (x .LoadFree0 , prometheus .GaugeValue , x .State .LoadFree0 )
61
- m3 := prometheus .MustNewConstMetric (x .LoadFree1 , prometheus .GaugeValue , x .State .LoadFree1 )
62
- m4 := prometheus .MustNewConstMetric (x .LoadUsed0 , prometheus .GaugeValue , x .State .LoadUsed0 )
63
- m5 := prometheus .MustNewConstMetric (x .LoadUsed1 , prometheus .GaugeValue , x .State .LoadUsed1 )
122
+ m0 := prometheus .MustNewConstMetric (x .PoolCollector . IdleLoad0 , prometheus .GaugeValue , x .State . Pool .IdleLoad0 )
123
+ m1 := prometheus .MustNewConstMetric (x .PoolCollector . IdleLoad1 , prometheus .GaugeValue , x .State . Pool .IdleLoad1 )
124
+ m2 := prometheus .MustNewConstMetric (x .PoolCollector . LoadFree0 , prometheus .GaugeValue , x .State . Pool .LoadFree0 )
125
+ m3 := prometheus .MustNewConstMetric (x .PoolCollector . LoadFree1 , prometheus .GaugeValue , x .State . Pool .LoadFree1 )
126
+ m4 := prometheus .MustNewConstMetric (x .PoolCollector . LoadUsed0 , prometheus .GaugeValue , x .State . Pool .LoadUsed0 )
127
+ m5 := prometheus .MustNewConstMetric (x .PoolCollector . LoadUsed1 , prometheus .GaugeValue , x .State . Pool .LoadUsed1 )
64
128
65
129
now := time .Now ()
66
130
mt0 := prometheus .NewMetricWithTimestamp (now , m0 )
@@ -76,4 +140,26 @@ func (x *StaticCollector) Collect(ch chan<- prometheus.Metric) {
76
140
ch <- mt3
77
141
ch <- mt4
78
142
ch <- mt5
143
+
144
+ l0 := len (x .PoolCollector .Nodes )
145
+ for i := 0 ; i < l0 ; i ++ {
146
+ node := x .State .Pool .Nodes [i ]
147
+
148
+ nodeCollector := x .PoolCollector .Nodes [i ]
149
+
150
+ mn0 := prometheus .MustNewConstMetric (nodeCollector .LoadFree0 , prometheus .GaugeValue , node .LoadFree0 )
151
+ mn1 := prometheus .MustNewConstMetric (nodeCollector .LoadFree1 , prometheus .GaugeValue , node .LoadFree1 )
152
+ mn2 := prometheus .MustNewConstMetric (nodeCollector .LoadUsed0 , prometheus .GaugeValue , node .LoadUsed0 )
153
+ mn3 := prometheus .MustNewConstMetric (nodeCollector .LoadUsed1 , prometheus .GaugeValue , node .LoadUsed1 )
154
+
155
+ mnt0 := prometheus .NewMetricWithTimestamp (now , mn0 )
156
+ mnt1 := prometheus .NewMetricWithTimestamp (now , mn1 )
157
+ mnt2 := prometheus .NewMetricWithTimestamp (now , mn2 )
158
+ mnt3 := prometheus .NewMetricWithTimestamp (now , mn3 )
159
+
160
+ ch <- mnt0
161
+ ch <- mnt1
162
+ ch <- mnt2
163
+ ch <- mnt3
164
+ }
79
165
}
0 commit comments