Status Metric : Change select max,min,... to select *
Change-Id: I6c4d77c50f909002cc78c13e665c8ca8b1987af7
This commit is contained in:
parent
c650fa428a
commit
cf1d775a10
@ -19,7 +19,7 @@ def build_influxdb_query(metric_name,
|
||||
service_description=None
|
||||
):
|
||||
group_by = []
|
||||
query = ['SELECT max,min,warning,critical,value,unit FROM metric_%s'
|
||||
query = ['SELECT * FROM metric_%s'
|
||||
% metric_name]
|
||||
begin = time_delta.begin
|
||||
end = time_delta.end
|
||||
|
@ -26,15 +26,13 @@ class MetricHandler(handler.Handler):
|
||||
cli = self.request.influxdb_client
|
||||
|
||||
if service_description is None:
|
||||
query = ("SELECT max,min,warning,critical,value,unit "
|
||||
"FROM metric_%s "
|
||||
query = ("SELECT * FROM metric_%s "
|
||||
"WHERE host_name= '%s' "
|
||||
"GROUP BY service_description "
|
||||
"ORDER BY time DESC "
|
||||
"LIMIT 1" % (metric_name, host_name))
|
||||
else:
|
||||
query = ("SELECT max,min,warning,critical,value,unit "
|
||||
"FROM metric_%s "
|
||||
query = ("SELECT * FROM metric_%s "
|
||||
"WHERE host_name= '%s' "
|
||||
"AND service_description= '%s'"
|
||||
"ORDER BY time DESC "
|
||||
@ -42,7 +40,7 @@ class MetricHandler(handler.Handler):
|
||||
|
||||
response = cli.query(query)
|
||||
metric = live_metric.LiveMetric(
|
||||
**self._metric_dict_from_influx_item(response.items()[0],
|
||||
**self._metric_dict_from_influx_item(next(response.items()[0][1]),
|
||||
metric_name)
|
||||
)
|
||||
|
||||
@ -63,7 +61,7 @@ class MetricHandler(handler.Handler):
|
||||
|
||||
metric_dicts = []
|
||||
|
||||
for item in response.items():
|
||||
for item in response[None]:
|
||||
metric_dict = self._metric_dict_from_influx_item(item, metric_name)
|
||||
metric_dicts.append(metric_dict)
|
||||
|
||||
@ -75,8 +73,6 @@ class MetricHandler(handler.Handler):
|
||||
return metrics
|
||||
|
||||
def _metric_dict_from_influx_item(self, item, metric_name):
|
||||
points = item[1]
|
||||
first_point = next(points)
|
||||
metric_dict = {"metric_name": str(metric_name)}
|
||||
mappings = [
|
||||
('min', str),
|
||||
@ -88,7 +84,7 @@ class MetricHandler(handler.Handler):
|
||||
]
|
||||
|
||||
for field in mappings:
|
||||
value = first_point.get(field[0], None)
|
||||
value = item.get(field[0], None)
|
||||
if value is not None:
|
||||
metric_dict[field[0]] = field[1](value)
|
||||
|
||||
|
@ -76,7 +76,7 @@ class TestHostMetric(functionalTest.FunctionalTest):
|
||||
"20",
|
||||
"0",
|
||||
"6",
|
||||
"10"]
|
||||
"10"],
|
||||
]}
|
||||
]
|
||||
}
|
||||
@ -104,7 +104,7 @@ class TestHostMetric(functionalTest.FunctionalTest):
|
||||
expected)
|
||||
self.assertEqual(
|
||||
httpretty.last_request().querystring['q'],
|
||||
["SELECT max,min,warning,critical,value,unit FROM metric_load1 "
|
||||
["SELECT * FROM metric_load1 "
|
||||
"WHERE host_name= 'srv-monitoring-01' "
|
||||
"GROUP BY service_description "
|
||||
"ORDER BY time DESC LIMIT 1"]
|
||||
@ -128,7 +128,12 @@ class TestHostMetric(functionalTest.FunctionalTest):
|
||||
"30",
|
||||
"0",
|
||||
"0.6",
|
||||
"15"]]}]}]
|
||||
"15"],
|
||||
["2015-04-19T01:09:25Z",
|
||||
"40",
|
||||
"4",
|
||||
"10",
|
||||
"10"]]}]}]
|
||||
|
||||
})
|
||||
httpretty.register_uri(httpretty.GET,
|
||||
@ -136,7 +141,7 @@ class TestHostMetric(functionalTest.FunctionalTest):
|
||||
body=self.influxdb_response)
|
||||
|
||||
time = {'begin': '2015-04-19T00:09:24Z',
|
||||
'end': '2015-04-19T02:09:24Z'}
|
||||
'end': '2015-04-19T02:09:25Z'}
|
||||
|
||||
response = self.post_json("/v2/status/hosts/srv-monitoring-01/"
|
||||
"services/load/metrics/load1",
|
||||
@ -147,6 +152,12 @@ class TestHostMetric(functionalTest.FunctionalTest):
|
||||
"critical": "30",
|
||||
"warning": "15",
|
||||
"value": "0.6"
|
||||
},
|
||||
{"metric_name": 'load1',
|
||||
"min": "4",
|
||||
"critical": "40",
|
||||
"warning": "10",
|
||||
"value": "10"
|
||||
}]
|
||||
|
||||
self.assert_count_equal_backport(
|
||||
@ -154,9 +165,9 @@ class TestHostMetric(functionalTest.FunctionalTest):
|
||||
expected)
|
||||
self.assertEqual(
|
||||
httpretty.last_request().querystring['q'],
|
||||
["SELECT max,min,warning,critical,value,unit FROM metric_load1 "
|
||||
["SELECT * FROM metric_load1 "
|
||||
"WHERE time >= '2015-04-19T00:09:24Z' "
|
||||
"AND time <= '2015-04-19T02:09:24Z' "
|
||||
"AND time <= '2015-04-19T02:09:25Z' "
|
||||
"AND host_name ='srv-monitoring-01' "
|
||||
"AND service_description ='load' "
|
||||
"ORDER BY time DESC"
|
||||
|
@ -27,7 +27,7 @@ class InfluxdbTimeQueryTest(base.BaseTestCase):
|
||||
result = influxdb_time_query.build_influxdb_query(query_metric_name,
|
||||
query_time
|
||||
)
|
||||
expected = ("SELECT max,min,value,warning,critical,unit "
|
||||
expected = ("SELECT * "
|
||||
"FROM metric_pl "
|
||||
"WHERE time >= '2015-01-29T21:50:44Z' "
|
||||
"AND time <= '2015-01-29T22:50:44Z' "
|
||||
@ -46,7 +46,7 @@ class InfluxdbTimeQueryTest(base.BaseTestCase):
|
||||
query_time,
|
||||
query_host_name
|
||||
)
|
||||
expected = ("SELECT max,min,value,warning,critical,unit "
|
||||
expected = ("SELECT * "
|
||||
"FROM metric_pl "
|
||||
"WHERE time >= '2015-01-29T21:50:44Z' "
|
||||
"AND time <= '2015-01-29T22:50:44Z' "
|
||||
@ -69,7 +69,7 @@ class InfluxdbTimeQueryTest(base.BaseTestCase):
|
||||
query_host_name,
|
||||
query_service_description
|
||||
)
|
||||
expected = ("SELECT max,min,value,warning,critical,unit "
|
||||
expected = ("SELECT * "
|
||||
"FROM metric_pl "
|
||||
"WHERE time >= '2015-01-29T21:50:44Z' "
|
||||
"AND time <= '2015-01-29T22:50:44Z' "
|
||||
|
Loading…
x
Reference in New Issue
Block a user