@@ -42,12 +42,19 @@ def __init__(self, name, init_config, agentConfig):
42
42
"wretr" : ("rate" , "warnings.retr_rate" ),
43
43
"wredis" : ("rate" , "warnings.redis_rate" ),
44
44
"req_rate" : ("gauge" , "requests.rate" ),
45
+ "hrsp_1xx" : ("rate" , "response.1xx" ),
46
+ "hrsp_2xx" : ("rate" , "response.2xx" ),
47
+ "hrsp_3xx" : ("rate" , "response.3xx" ),
48
+ "hrsp_4xx" : ("rate" , "response.4xx" ),
49
+ "hrsp_5xx" : ("rate" , "response.5xx" ),
50
+ "hrsp_other" : ("rate" , "response.other" ),
45
51
}
46
52
47
53
def check (self , instance ):
48
54
url = instance .get ('url' )
49
55
username = instance .get ('username' )
50
56
password = instance .get ('password' )
57
+ collect_aggregates_only = instance .get ('collect_aggregates_only' , False )
51
58
52
59
self .log .debug ('Processing HAProxy data for %s' % url )
53
60
@@ -58,7 +65,7 @@ def check(self, instance):
58
65
else :
59
66
events_cb = None
60
67
61
- self ._process_data (data , self . hostname , self ._process_metrics ,
68
+ self ._process_data (data , collect_aggregates_only , self ._process_metrics ,
62
69
events_cb , url )
63
70
64
71
def _fetch_data (self , url , username , password ):
@@ -80,7 +87,7 @@ def _fetch_data(self, url, username, password):
80
87
# Split the data by line
81
88
return response .split ('\n ' )
82
89
83
- def _process_data (self , data , my_hostname , metric_cb = None , event_cb = None , url = None ):
90
+ def _process_data (self , data , collect_aggregates_only , metric_cb = None , event_cb = None , url = None ):
84
91
''' Main data-processing loop. For each piece of useful data, we'll
85
92
either save a metric, save an event or both. '''
86
93
@@ -103,32 +110,30 @@ def _process_data(self, data, my_hostname, metric_cb=None, event_cb=None, url=No
103
110
if val :
104
111
try :
105
112
# Try converting to a long, if failure, just leave it
106
- val = long (val )
107
- except :
113
+ val = float (val )
114
+ except Exception :
108
115
pass
109
116
data_dict [fields [i ]] = val
110
117
111
118
# Don't create metrics for aggregates
112
119
service = data_dict ['svname' ]
113
120
if data_dict ['svname' ] in Services .ALL :
114
- if not data_list and service == Services .FRONTEND :
115
- data_list .append (data_dict )
121
+ data_list .append (data_dict )
116
122
117
123
# Send the list of data to the metric and event callbacks
118
124
if metric_cb :
119
- metric_cb (data_list , service , my_hostname )
125
+ metric_cb (data_list , service )
120
126
if event_cb :
121
127
event_cb (data_list , url )
122
128
123
129
# Clear out the event list for the next service
124
130
data_list = []
125
- else :
131
+ elif not collect_aggregates_only :
126
132
data_list .append (data_dict )
127
133
128
134
return data
129
135
130
- def _process_metrics (self , data_list , service , my_hostname ):
131
- hosts_to_aggregate = {}
136
+ def _process_metrics (self , data_list , service ):
132
137
for data in data_list :
133
138
"""
134
139
Each element of data_list is a dictionary related to one host
0 commit comments