Refactor of metric handlers
Change-Id: I0657939b46fa9dd4c4cbcb3e4b81d9002c68f54b
This commit is contained in:
@@ -62,7 +62,7 @@ types documentation
|
|||||||
.. autotype:: surveil.api.datamodel.status.live_query.LiveQuery
|
.. autotype:: surveil.api.datamodel.status.live_query.LiveQuery
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
.. autotype:: surveil.api.datamodel.status.metrics.live_metric.LiveMetric
|
.. autotype:: surveil.api.datamodel.status.metrics.metric.Metric
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
.. autotype:: surveil.api.datamodel.status.metrics.time_interval.TimeInterval
|
.. autotype:: surveil.api.datamodel.status.metrics.time_interval.TimeInterval
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ from pecan import rest
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.datamodel.status import live_query
|
from surveil.api.datamodel.status import live_query
|
||||||
from surveil.api.datamodel.status.metrics import live_metric
|
from surveil.api.datamodel.status.metrics import metric as m
|
||||||
from surveil.api.handlers.status.metrics import live_metric_handler
|
from surveil.api.handlers.status.metrics import metric_handler
|
||||||
from surveil.api.handlers.status.metrics import metric_name_handler
|
from surveil.api.handlers.status.metrics import metric_name_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ from surveil.common import util
|
|||||||
class MetricsController(rest.RestController):
|
class MetricsController(rest.RestController):
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([live_metric.LiveMetric])
|
@wsme_pecan.wsexpose([m.Metric])
|
||||||
def get(self):
|
def get(self):
|
||||||
"""Returns all metrics name for a host."""
|
"""Returns all metrics name for a host."""
|
||||||
handler = metric_name_handler.MetricNameHandler(pecan.request)
|
handler = metric_name_handler.MetricNameHandler(pecan.request)
|
||||||
@@ -45,10 +45,10 @@ class MetricController(rest.RestController):
|
|||||||
self.metric_name = metric_name
|
self.metric_name = metric_name
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose(live_metric.LiveMetric)
|
@wsme_pecan.wsexpose(m.Metric)
|
||||||
def get(self):
|
def get(self):
|
||||||
"""Return the last measure for the metric name on the host."""
|
"""Return the last measure for the metric name on the host."""
|
||||||
handler = live_metric_handler.MetricHandler(pecan.request)
|
handler = metric_handler.MetricHandler(pecan.request)
|
||||||
metric = handler.get(
|
metric = handler.get(
|
||||||
pecan.request.context['host_name'],
|
pecan.request.context['host_name'],
|
||||||
self.metric_name
|
self.metric_name
|
||||||
@@ -56,14 +56,14 @@ class MetricController(rest.RestController):
|
|||||||
return metric
|
return metric
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([live_metric.LiveMetric], body=live_query.LiveQuery)
|
@wsme_pecan.wsexpose([m.Metric], body=live_query.LiveQuery)
|
||||||
def post(self, query):
|
def post(self, query):
|
||||||
"""Given a live query, returns all matching metrics.
|
"""Given a live query, returns all matching metrics.
|
||||||
|
|
||||||
:param live_query: a live query within the request body.
|
:param live_query: a live query within the request body.
|
||||||
"""
|
"""
|
||||||
handler = live_metric_handler.MetricHandler(pecan.request)
|
handler = metric_handler.MetricHandler(pecan.request)
|
||||||
metrics = handler.get_all(live_query=query,
|
metrics = handler.get_all(query=query,
|
||||||
metric_name=self.metric_name,
|
metric_name=self.metric_name,
|
||||||
host_name=pecan.request.context['host_name']
|
host_name=pecan.request.context['host_name']
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ from pecan import rest
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.datamodel.status import live_query
|
from surveil.api.datamodel.status import live_query
|
||||||
from surveil.api.datamodel.status.metrics import live_metric
|
from surveil.api.datamodel.status.metrics import metric as m
|
||||||
from surveil.api.handlers.status.metrics import live_metric_handler
|
from surveil.api.handlers.status.metrics import metric_handler
|
||||||
from surveil.api.handlers.status.metrics import metric_name_handler
|
from surveil.api.handlers.status.metrics import metric_name_handler
|
||||||
from surveil.common import util
|
from surveil.common import util
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ from surveil.common import util
|
|||||||
class MetricsController(rest.RestController):
|
class MetricsController(rest.RestController):
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([live_metric.LiveMetric])
|
@wsme_pecan.wsexpose([m.Metric])
|
||||||
def get(self):
|
def get(self):
|
||||||
"""Returns all metrics name for a host with a service."""
|
"""Returns all metrics name for a host with a service."""
|
||||||
handler = metric_name_handler.MetricNameHandler(pecan.request)
|
handler = metric_name_handler.MetricNameHandler(pecan.request)
|
||||||
@@ -48,10 +48,10 @@ class MetricController(rest.RestController):
|
|||||||
self.metric_name = metric_name
|
self.metric_name = metric_name
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose(live_metric.LiveMetric)
|
@wsme_pecan.wsexpose(m.Metric)
|
||||||
def get(self):
|
def get(self):
|
||||||
"""Return the last measure of the metric of the service of the host."""
|
"""Return the last measure of the metric of the service of the host."""
|
||||||
handler = live_metric_handler.MetricHandler(pecan.request)
|
handler = metric_handler.MetricHandler(pecan.request)
|
||||||
metric = handler.get(
|
metric = handler.get(
|
||||||
pecan.request.context['host_name'],
|
pecan.request.context['host_name'],
|
||||||
self.metric_name,
|
self.metric_name,
|
||||||
@@ -60,14 +60,14 @@ class MetricController(rest.RestController):
|
|||||||
return metric
|
return metric
|
||||||
|
|
||||||
@util.policy_enforce(['authenticated'])
|
@util.policy_enforce(['authenticated'])
|
||||||
@wsme_pecan.wsexpose([live_metric.LiveMetric], body=live_query.LiveQuery)
|
@wsme_pecan.wsexpose([m.Metric], body=live_query.LiveQuery)
|
||||||
def post(self, query):
|
def post(self, query):
|
||||||
"""Returns all matching metrics.
|
"""Returns all matching metrics.
|
||||||
|
|
||||||
:param live query: a live query
|
:param live query: a live query
|
||||||
"""
|
"""
|
||||||
handler = live_metric_handler.MetricHandler(pecan.request)
|
handler = metric_handler.MetricHandler(pecan.request)
|
||||||
metrics = handler.get_all(live_query=query,
|
metrics = handler.get_all(query=query,
|
||||||
metric_name=self.metric_name,
|
metric_name=self.metric_name,
|
||||||
host_name=pecan.request.context['host_name'],
|
host_name=pecan.request.context['host_name'],
|
||||||
service_description=pecan.request.
|
service_description=pecan.request.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import wsme.types as wtypes
|
|||||||
from surveil.api.datamodel import types
|
from surveil.api.datamodel import types
|
||||||
|
|
||||||
|
|
||||||
class LiveMetric(types.Base):
|
class Metric(types.Base):
|
||||||
|
|
||||||
metric_name = wsme.wsattr(wtypes.text, mandatory=True)
|
metric_name = wsme.wsattr(wtypes.text, mandatory=True)
|
||||||
"""Name of the metric"""
|
"""Name of the metric"""
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
# Copyright 2014 - Savoir-Faire Linux inc.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
from surveil.api.datamodel.status import live_query
|
|
||||||
from surveil.api.datamodel.status.metrics import live_metric
|
|
||||||
from surveil.api.handlers import handler
|
|
||||||
from surveil.api.handlers.status import influxdb_query
|
|
||||||
|
|
||||||
|
|
||||||
class MetricHandler(handler.Handler):
|
|
||||||
"""Fulfills a request on the metrics."""
|
|
||||||
|
|
||||||
def get(self, host_name, metric_name, service_description=None):
|
|
||||||
"""Return the last metric."""
|
|
||||||
metrics = []
|
|
||||||
cli = self.request.influxdb_client
|
|
||||||
if metric_name is None:
|
|
||||||
if service_description is None:
|
|
||||||
query = ("SHOW measurements WHERE host_name='%s' "
|
|
||||||
"AND service_description=''"
|
|
||||||
% host_name)
|
|
||||||
else:
|
|
||||||
query = ("SHOW measurements WHERE host_name='%s' "
|
|
||||||
"AND service_description='%s'"
|
|
||||||
% (host_name, service_description))
|
|
||||||
else:
|
|
||||||
if service_description is None:
|
|
||||||
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 * FROM metric_%s "
|
|
||||||
"WHERE host_name= '%s' "
|
|
||||||
"AND service_description= '%s'"
|
|
||||||
"ORDER BY time DESC "
|
|
||||||
"LIMIT 1"
|
|
||||||
% (metric_name, host_name, service_description))
|
|
||||||
|
|
||||||
response = cli.query(query)
|
|
||||||
|
|
||||||
if metric_name is None:
|
|
||||||
metric_dicts = []
|
|
||||||
|
|
||||||
for item in response[None]:
|
|
||||||
metric_dict = self._metric_dict_from_influx_item(item)
|
|
||||||
if metric_dict is not None:
|
|
||||||
metric_dicts.append(metric_dict)
|
|
||||||
|
|
||||||
for metric_dict in metric_dicts:
|
|
||||||
metric = live_metric.LiveMetric(**metric_dict)
|
|
||||||
metrics.append(metric)
|
|
||||||
|
|
||||||
else:
|
|
||||||
metrics = live_metric.LiveMetric(**self.
|
|
||||||
_metric_dict_from_influx_item(
|
|
||||||
next(response.items()[0][1]),
|
|
||||||
metric_name))
|
|
||||||
|
|
||||||
return metrics
|
|
||||||
|
|
||||||
def get_all(self, metric_name,
|
|
||||||
host_name, service_description=None,
|
|
||||||
live_query=live_query.LiveQuery()):
|
|
||||||
"""Return all metrics."""
|
|
||||||
|
|
||||||
filters = {
|
|
||||||
"is": {
|
|
||||||
"host_name": [host_name]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if service_description:
|
|
||||||
filters["is"]["service_description"] = [service_description]
|
|
||||||
|
|
||||||
influx_client = self.request.influxdb_client
|
|
||||||
query = influxdb_query.build_influxdb_query(live_query,
|
|
||||||
'metric_' + metric_name,
|
|
||||||
order_by=["time desc"],
|
|
||||||
additional_filters=filters)
|
|
||||||
response = influx_client.query(query)
|
|
||||||
|
|
||||||
metric_dicts = []
|
|
||||||
|
|
||||||
for item in response[None]:
|
|
||||||
metric_dict = self._metric_dict_from_influx_item(item, metric_name)
|
|
||||||
metric_dicts.append(metric_dict)
|
|
||||||
|
|
||||||
metrics = []
|
|
||||||
for metric_dict in metric_dicts:
|
|
||||||
metric = live_metric.LiveMetric(**metric_dict)
|
|
||||||
metrics.append(metric)
|
|
||||||
|
|
||||||
return metrics
|
|
||||||
|
|
||||||
def _metric_dict_from_influx_item(self, item, metric_name=None):
|
|
||||||
metric_dict = {"metric_name": str(metric_name)}
|
|
||||||
mappings = [
|
|
||||||
('min', str),
|
|
||||||
('max', str),
|
|
||||||
('critical', str),
|
|
||||||
('warning', str),
|
|
||||||
('value', str),
|
|
||||||
('unit', str),
|
|
||||||
]
|
|
||||||
|
|
||||||
for field in mappings:
|
|
||||||
value = item.get(field[0], None)
|
|
||||||
if value is not None:
|
|
||||||
if field[0] == 'name':
|
|
||||||
if value.startswith('metric_'):
|
|
||||||
metric_dict = {}
|
|
||||||
metric_dict[field[1]] = field[2](value[7:])
|
|
||||||
else:
|
|
||||||
metric_dict[field[0]] = field[1](value)
|
|
||||||
|
|
||||||
return metric_dict
|
|
||||||
|
|||||||
109
surveil/api/handlers/status/metrics/metric_handler.py
Normal file
109
surveil/api/handlers/status/metrics/metric_handler.py
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
# Copyright 2014 - Savoir-Faire Linux inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from surveil.api.datamodel.status import live_query as q
|
||||||
|
from surveil.api.datamodel.status.metrics import metric as m
|
||||||
|
from surveil.api.handlers import handler
|
||||||
|
from surveil.api.handlers.status import influxdb_query
|
||||||
|
|
||||||
|
|
||||||
|
class MetricHandler(handler.Handler):
|
||||||
|
"""Fulfills a request on the metrics."""
|
||||||
|
|
||||||
|
def get(self, host_name, metric_name, service_description=None):
|
||||||
|
"""Return the last metric."""
|
||||||
|
query = self._build_metric_query(
|
||||||
|
host_name,
|
||||||
|
metric_name,
|
||||||
|
service_description=service_description,
|
||||||
|
limit=1)
|
||||||
|
|
||||||
|
influx_client = self.request.influxdb_client
|
||||||
|
response = influx_client.query(query)
|
||||||
|
|
||||||
|
metrics = []
|
||||||
|
for item in response[None]:
|
||||||
|
metric_dict = self._metric_dict_from_influx_item(item, metric_name)
|
||||||
|
metric = m.Metric(**metric_dict)
|
||||||
|
metrics.append(metric)
|
||||||
|
|
||||||
|
if metric_name:
|
||||||
|
metrics = metrics[0] or ''
|
||||||
|
return metrics
|
||||||
|
|
||||||
|
def get_all(self, metric_name,
|
||||||
|
host_name, service_description=None,
|
||||||
|
query=q.LiveQuery()):
|
||||||
|
"""Return all metrics."""
|
||||||
|
query = self._build_metric_query(
|
||||||
|
host_name,
|
||||||
|
metric_name,
|
||||||
|
service_description=service_description,
|
||||||
|
query=query)
|
||||||
|
influx_client = self.request.influxdb_client
|
||||||
|
response = influx_client.query(query)
|
||||||
|
|
||||||
|
metrics = []
|
||||||
|
for item in response[None]:
|
||||||
|
metric_dict = self._metric_dict_from_influx_item(item, metric_name)
|
||||||
|
metric = m.Metric(**metric_dict)
|
||||||
|
metrics.append(metric)
|
||||||
|
|
||||||
|
return metrics
|
||||||
|
|
||||||
|
def _build_metric_query(self, host_name, metric_name,
|
||||||
|
service_description=None,
|
||||||
|
query=None, limit=None):
|
||||||
|
filters = {
|
||||||
|
"is": {
|
||||||
|
"host_name": [host_name]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
group_by = []
|
||||||
|
if service_description:
|
||||||
|
filters["is"]["service_description"] = [service_description]
|
||||||
|
else:
|
||||||
|
group_by.append('service_description')
|
||||||
|
|
||||||
|
return influxdb_query.build_influxdb_query(query,
|
||||||
|
'metric_' + metric_name,
|
||||||
|
order_by=["time desc"],
|
||||||
|
group_by=group_by,
|
||||||
|
additional_filters=filters,
|
||||||
|
limit=limit,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _metric_dict_from_influx_item(self, item, metric_name=None):
|
||||||
|
metric_dict = {"metric_name": str(metric_name)}
|
||||||
|
mappings = [
|
||||||
|
('min', str),
|
||||||
|
('max', str),
|
||||||
|
('critical', str),
|
||||||
|
('warning', str),
|
||||||
|
('value', str),
|
||||||
|
('unit', str),
|
||||||
|
]
|
||||||
|
|
||||||
|
for field in mappings:
|
||||||
|
value = item.get(field[0], None)
|
||||||
|
if value is not None:
|
||||||
|
if field[0] == 'name':
|
||||||
|
if value.startswith('metric_'):
|
||||||
|
metric_dict = {}
|
||||||
|
metric_dict[field[1]] = field[2](value[7:])
|
||||||
|
else:
|
||||||
|
metric_dict[field[0]] = field[1](value)
|
||||||
|
|
||||||
|
return metric_dict
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from surveil.api.datamodel.status.metrics import live_metric
|
from surveil.api.datamodel.status.metrics import metric as m
|
||||||
from surveil.api.handlers import handler
|
from surveil.api.handlers import handler
|
||||||
|
|
||||||
|
|
||||||
@@ -21,29 +21,22 @@ class MetricNameHandler(handler.Handler):
|
|||||||
|
|
||||||
def get(self, host_name, service_description=None):
|
def get(self, host_name, service_description=None):
|
||||||
"""Return all metrics name."""
|
"""Return all metrics name."""
|
||||||
|
service_description = service_description or ''
|
||||||
|
query = ("SHOW measurements WHERE host_name='%s' "
|
||||||
|
"AND service_description='%s'"
|
||||||
|
% (host_name, service_description))
|
||||||
|
influx_client = self.request.influxdb_client
|
||||||
|
response = influx_client.query(query)
|
||||||
|
|
||||||
metrics = []
|
metrics = []
|
||||||
cli = self.request.influxdb_client
|
|
||||||
|
|
||||||
if service_description is None:
|
|
||||||
query = ("SHOW measurements WHERE host_name='%s' "
|
|
||||||
"AND service_description=''"
|
|
||||||
% host_name)
|
|
||||||
else:
|
|
||||||
query = ("SHOW measurements WHERE host_name='%s' "
|
|
||||||
"AND service_description='%s'"
|
|
||||||
% (host_name, service_description))
|
|
||||||
|
|
||||||
response = cli.query(query)
|
|
||||||
|
|
||||||
for item in response[None]:
|
for item in response[None]:
|
||||||
metric_dict = self._metrics_name_from_influx_item(item)
|
metric_dict = self._metrics_name_from_influx_item(item)
|
||||||
if metric_dict is not None:
|
if metric_dict is not None:
|
||||||
metrics.append(live_metric.LiveMetric(**metric_dict))
|
metrics.append(m.Metric(**metric_dict))
|
||||||
|
|
||||||
return metrics
|
return metrics
|
||||||
|
|
||||||
def _metrics_name_from_influx_item(self, item):
|
def _metrics_name_from_influx_item(self, item):
|
||||||
|
|
||||||
metric_name = None
|
metric_name = None
|
||||||
mappings = [('metric_name', 'name', str), ]
|
mappings = [('metric_name', 'name', str), ]
|
||||||
for field in mappings:
|
for field in mappings:
|
||||||
|
|||||||
@@ -85,10 +85,44 @@ class TestHostMetric(functionalTest.FunctionalTest):
|
|||||||
})
|
})
|
||||||
|
|
||||||
def test_get_metric_hosts(self):
|
def test_get_metric_hosts(self):
|
||||||
|
influxdb_response = json.dumps({
|
||||||
|
"results": [
|
||||||
|
{
|
||||||
|
"series": [
|
||||||
|
{
|
||||||
|
"name": "metric_load1",
|
||||||
|
"tags": {
|
||||||
|
"host_name": "srv-monitoring-01",
|
||||||
|
"service_description": "load"
|
||||||
|
},
|
||||||
|
"columns": [
|
||||||
|
"time",
|
||||||
|
"critical",
|
||||||
|
"min",
|
||||||
|
"unit",
|
||||||
|
"value",
|
||||||
|
"warning"
|
||||||
|
],
|
||||||
|
"values": [
|
||||||
|
[
|
||||||
|
"2015-07-03T15:18:46Z",
|
||||||
|
30,
|
||||||
|
0,
|
||||||
|
"",
|
||||||
|
0.78,
|
||||||
|
15
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
with requests_mock.Mocker() as m:
|
with requests_mock.Mocker() as m:
|
||||||
m.register_uri(requests_mock.GET,
|
m.register_uri(requests_mock.GET,
|
||||||
"http://influxdb:8086/query",
|
"http://influxdb:8086/query",
|
||||||
text=self.influxdb_response)
|
text=influxdb_response)
|
||||||
|
|
||||||
response = self.get(
|
response = self.get(
|
||||||
"/v2/status/hosts/srv-monitoring-01/metrics/load1"
|
"/v2/status/hosts/srv-monitoring-01/metrics/load1"
|
||||||
@@ -97,9 +131,10 @@ class TestHostMetric(functionalTest.FunctionalTest):
|
|||||||
expected = {
|
expected = {
|
||||||
"metric_name": "load1",
|
"metric_name": "load1",
|
||||||
"min": "0",
|
"min": "0",
|
||||||
|
"unit": "",
|
||||||
"critical": "30",
|
"critical": "30",
|
||||||
"warning": "15",
|
"warning": "15",
|
||||||
"value": "0.6"
|
"value": "0.78"
|
||||||
}
|
}
|
||||||
|
|
||||||
self.assert_count_equal_backport(
|
self.assert_count_equal_backport(
|
||||||
@@ -108,7 +143,7 @@ class TestHostMetric(functionalTest.FunctionalTest):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
m.last_request.qs['q'],
|
m.last_request.qs['q'],
|
||||||
["select * from metric_load1 "
|
["select * from metric_load1 "
|
||||||
"where host_name= 'srv-monitoring-01' "
|
"where host_name='srv-monitoring-01' "
|
||||||
"group by service_description "
|
"group by service_description "
|
||||||
"order by time desc limit 1"]
|
"order by time desc limit 1"]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ class TestHostMetric(functionalTest.FunctionalTest):
|
|||||||
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
"""Test get all metric names for a service."""
|
"""Test get all metric names for a service."""
|
||||||
self.influxdb_response = json.dumps({
|
influxdb_response = json.dumps({
|
||||||
"results": [
|
"results": [
|
||||||
{
|
{
|
||||||
"series": [
|
"series": [
|
||||||
@@ -105,7 +105,7 @@ class TestHostMetric(functionalTest.FunctionalTest):
|
|||||||
with requests_mock.Mocker() as m:
|
with requests_mock.Mocker() as m:
|
||||||
m.register_uri(requests_mock.GET,
|
m.register_uri(requests_mock.GET,
|
||||||
"http://influxdb:8086/query",
|
"http://influxdb:8086/query",
|
||||||
text=self.influxdb_response)
|
text=influxdb_response)
|
||||||
|
|
||||||
response = self.get(
|
response = self.get(
|
||||||
"/v2/status/hosts/localhost/services/load/metrics"
|
"/v2/status/hosts/localhost/services/load/metrics"
|
||||||
|
|||||||
Reference in New Issue
Block a user