@@ -16,6 +16,7 @@ package utils
16
16
17
17
import (
18
18
"fmt"
19
+ "reflect"
19
20
"strings"
20
21
21
22
"github.com/golang/glog"
@@ -33,6 +34,7 @@ func NewAgentMetrics(ai *AgentInfo) AgentMetrics {
33
34
}
34
35
name := ai .NodeName
35
36
37
+ // Basic Counter metrics
36
38
am .ErrorCount = prometheus .NewCounter (prometheus.CounterOpts {
37
39
Namespace : "ncagent" ,
38
40
Name : "error_count_total" ,
@@ -46,15 +48,7 @@ func NewAgentMetrics(ai *AgentInfo) AgentMetrics {
46
48
Help : "Total number of reports (keepalive messages) from the agent." ,
47
49
})
48
50
49
- if counter , ok := tryRegisterCounter (am .ErrorCount ); ! ok {
50
- // use existing counter
51
- am .ErrorCount = counter
52
- }
53
- if counter , ok := tryRegisterCounter (am .ReportCount ); ! ok {
54
- // use existing counter
55
- am .ReportCount = counter
56
- }
57
-
51
+ // GaugeVec metrics for HTTP probes
58
52
am .ProbeConnectionResult = prometheus .NewGaugeVec (
59
53
prometheus.GaugeOpts {
60
54
Namespace : "ncagent" ,
@@ -75,7 +69,7 @@ func NewAgentMetrics(ai *AgentInfo) AgentMetrics {
75
69
prometheus.GaugeOpts {
76
70
Namespace : "ncagent" ,
77
71
Name : "http_probe_total_time_ms" ,
78
- Help : "The duration of total http request." ,
72
+ Help : "The total duration of http request." ,
79
73
},
80
74
[]string {"agent" , "url" },
81
75
)
@@ -84,8 +78,8 @@ func NewAgentMetrics(ai *AgentInfo) AgentMetrics {
84
78
Namespace : "ncagent" ,
85
79
Name : "http_probe_content_transfer_time_ms" ,
86
80
Help : fmt .Sprint (
87
- "The duration of content transfer time , from the first " ,
88
- "reponse byte till the end (in ms)." ,
81
+ "The duration of content transfer, from the first " ,
82
+ "response byte till the end (in ms)." ,
89
83
),
90
84
},
91
85
[]string {"agent" , "url" },
@@ -123,41 +117,20 @@ func NewAgentMetrics(ai *AgentInfo) AgentMetrics {
123
117
[]string {"agent" , "url" },
124
118
)
125
119
126
- if gauge , ok := tryRegisterGaugeVec (am .ProbeConnectionResult ); ! ok {
127
- // use existing gauge
128
- am .ProbeConnectionResult = gauge
129
- }
130
- if gauge , ok := tryRegisterGaugeVec (am .ProbeHTTPCode ); ! ok {
131
- // use existing gauge
132
- am .ProbeHTTPCode = gauge
133
- }
134
- if gauge , ok := tryRegisterGaugeVec (am .ProbeTotal ); ! ok {
135
- // use existing gauge
136
- am .ProbeTotal = gauge
137
- }
138
- if gauge , ok := tryRegisterGaugeVec (am .ProbeContentTransfer ); ! ok {
139
- // use existing gauge
140
- am .ProbeContentTransfer = gauge
141
- }
142
- if gauge , ok := tryRegisterGaugeVec (am .ProbeTCPConnection ); ! ok {
143
- // use existing gauge
144
- am .ProbeTCPConnection = gauge
145
- }
146
- if gauge , ok := tryRegisterGaugeVec (am .ProbeTCPConnection ); ! ok {
147
- // use existing gauge
148
- am .ProbeTCPConnection = gauge
149
- }
150
- if gauge , ok := tryRegisterGaugeVec (am .ProbeDNSLookup ); ! ok {
151
- // use existing gauge
152
- am .ProbeDNSLookup = gauge
153
- }
154
- if gauge , ok := tryRegisterGaugeVec (am .ProbeConnect ); ! ok {
155
- // use existing gauge
156
- am .ProbeConnect = gauge
157
- }
158
- if gauge , ok := tryRegisterGaugeVec (am .ProbeServerProcessing ); ! ok {
159
- // use existing gauge
160
- am .ProbeServerProcessing = gauge
120
+ // Let's register all the metrics now
121
+ params := reflect .ValueOf (& am ).Elem ()
122
+ for i := 0 ; i < params .NumField (); i ++ {
123
+ if e , ok := params .Field (i ).Interface ().(* prometheus.GaugeVec ); ok {
124
+ if exists , ok := tryRegisterGaugeVec (e ); ! ok {
125
+ params .Field (i ).Set (reflect .ValueOf (exists ))
126
+ }
127
+ } else if e , ok := params .Field (i ).Interface ().(prometheus.Counter ); ok {
128
+ if exists , ok := tryRegisterCounter (e ); ! ok {
129
+ params .Field (i ).Set (reflect .ValueOf (exists ))
130
+ }
131
+ } else {
132
+ glog .V (5 ).Infof ("Skipping %v since it's not prometheus metric." , params .Type ().Field (i ).Name )
133
+ }
161
134
}
162
135
163
136
return am
@@ -194,7 +167,7 @@ func tryRegisterGaugeVec(m *prometheus.GaugeVec) (*prometheus.GaugeVec, bool) {
194
167
return m , true
195
168
}
196
169
197
- // UpdateAgentBaseMetrics function updates basic metrcis with reports and
170
+ // UpdateAgentBaseMetrics function updates basic metrics with reports and
198
171
// error counters
199
172
func UpdateAgentBaseMetrics (am AgentMetrics , report , error bool ) {
200
173
if report {
@@ -207,7 +180,7 @@ func UpdateAgentBaseMetrics(am AgentMetrics, report, error bool) {
207
180
}
208
181
}
209
182
210
- // UpdateAgentProbeMetrics functions updates HTTP probe metrics.
183
+ // UpdateAgentProbeMetrics function updates HTTP probe metrics.
211
184
func UpdateAgentProbeMetrics (ai AgentInfo , am AgentMetrics ) {
212
185
213
186
suffix := "private_network"
0 commit comments