Commit e1225404 authored by Daniele Venzano's avatar Daniele Venzano

Fix pylint warnings

parent ec91058e
......@@ -59,9 +59,6 @@ def load_configuration(test_conf=None):
# Master options
argparser.add_argument('--api-listen-uri', help='ZMQ API listen address', default='tcp://*:4850')
argparser.add_argument('--influxdb-dbname', help='Name of the InfluxDB database to use for storing metrics', default='zoe')
argparser.add_argument('--influxdb-url', help='URL of the InfluxDB service (ex. http://localhost:8086)', default='http://localhost:8086')
argparser.add_argument('--influxdb-enable', action="store_true", help='Enable metric output toward influxDB')
argparser.add_argument('--kairosdb-enable', action="store_true", help='Enable metric input from KairosDB')
argparser.add_argument('--kairosdb-url', help='URL of the KairosDB service (ex. http://localhost:8086)', default='http://localhost:8090')
......
......@@ -20,9 +20,9 @@ import re
import threading
import time
import zoe_master.backends.base
from zoe_lib.config import get_conf
from zoe_lib.state import Service
import zoe_master.backends.base
from zoe_master.backends.docker.api_client import DockerClient
from zoe_master.backends.docker.config import DockerConfig, DockerHostConfig # pylint: disable=unused-import
from zoe_master.backends.docker.threads import DockerStateSynchronizer
......
# Copyright (c) 2016, Daniele Venzano
#
# 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.
"""InfluxDB implementation of the metrics system."""
import logging
import time
import requests
import zoe_master.metrics.base
from zoe_lib.config import get_conf
log = logging.getLogger(__name__)
class InfluxDBMetricSender(zoe_master.metrics.base.BaseMetricSender):
"""Sends metrics to InfluxDB."""
RETRIES = 5
def __init__(self, state):
super().__init__(state)
influxdb_url = get_conf().influxdb_url
influxdb_dbname = get_conf().influxdb_dbname
self._influxdb_endpoint = influxdb_url + '/write?precision=ms&db=' + influxdb_dbname
self._retries = self.RETRIES
self._start()
def _send_buffer(self):
error = False
if self._influxdb_endpoint is not None and len(self._buffer) > 0:
payload = '\n'.join(self._buffer)
try:
req = requests.post(self._influxdb_endpoint, data=payload)
except Exception:
log.exception('error writing metrics to influxdb, will retry {} times'.format(self._retries))
error = True
else:
if req.status_code != 204:
log.error('error writing metrics to influxdb, will retry {} times'.format(self._retries))
error = True
if error:
if self._retries <= 0:
self._retries = self.RETRIES
self._buffer.clear()
else:
self._retries -= 1
else:
self._buffer.clear()
def metric_api_call(self, time_start, action):
"""Compute and emit the run time of an API call."""
time_end = time.time()
diff = zoe_master.metrics.base.time_diff_ms(time_start, time_end)
point_str = "api_latency"
point_str += ",api_call=" + action
point_str += ',' + 'deployment' + '=' + self.deployment_name
point_str += " value=" + str(diff)
point_str += " " + str(int(time_end * 1000))
self._queue.put(point_str)
......@@ -84,8 +84,8 @@ class KairosDBInMetrics:
]
self._add_metric(query, "docker_container_mem", tags_memory, aggregators_memory, limit=0)
r = requests.post(self.metrics_url, json=query)
return self._extract_data(r)
req = requests.post(self.metrics_url, json=query)
return self._extract_data(req)
def _extract_data(self, response):
if response.status_code != 200:
......
# Copyright (c) 2016, Daniele Venzano
#
# 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.
"""Default metrics output to the logging system."""
import logging
import zoe_master.metrics.base
log = logging.getLogger(__name__)
class LogMetricSender(zoe_master.metrics.base.BaseMetricSender):
"""Send metrics to the configured logging sink."""
def __init__(self, state):
super().__init__(state)
self._start()
def _send_buffer(self):
"""
Sends the buffered data.
Needs to be redefined in child classes to support other metrics databases. Is called in thread context.
"""
if len(self._buffer) == 0:
return
for point in self._buffer:
log.debug(point)
self._buffer.clear()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment