Skip to content

Commit

Permalink
[Metrics] Frontend-exporter fault tolerance quick fix (#429)
Browse files Browse the repository at this point in the history
* Fix dict unpacking lint error

* Format Code

* Update yapf

* Update yapf and reformat code

* Check yapf version in shell script

* Change `echo` to `cat`

* Add python version check; almost ready

* Format code with python version 2.7.12

* Frontend-exporter fault tolerance

* Address Comment

* Address Comment

* Add logging basic config
  • Loading branch information
simon-mo authored and dcrankshaw committed Mar 13, 2018
1 parent 8fb0086 commit 42a4680
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions monitoring/front_end_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from prometheus_client import start_http_server
from prometheus_client.core import GaugeMetricFamily, REGISTRY
import argparse
import logging

parser = argparse.ArgumentParser(
description='Spin up a node exporter for query_frontend.')
Expand All @@ -16,14 +17,24 @@
help='The name of docker container in clipper_network')
args = parser.parse_args()

query_frontend_id = args.query_frontend_name
logging.basicConfig(
format='%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s',
datefmt='%y-%m-%d:%H:%M:%S',
level=logging.INFO)
logger = logging.getLogger(__name__)

query_frontend_id = args.query_frontend_name
ADDRESS = 'http://{}/metrics'.format(query_frontend_id)
logger.info("Scraping {}".format(ADDRESS))


def load_metric():
res = requests.get(ADDRESS)
return res.json()
try:
res = requests.get(ADDRESS)
return res.json()
except Exception as e:
logger.warning("Scrape Failed! Error: {}\n".format(e))
return dict()


def multi_dict_unpacking(lst):
Expand All @@ -38,6 +49,10 @@ def multi_dict_unpacking(lst):


def parse_metric(metrics):
if len(metrics) == 0:
# Return empty dictionary if it's empty
return metrics

wo_type = list(itertools.chain.from_iterable(metrics.values()))
wo_type_flattened = list(itertools.chain([flatten(d) for d in wo_type]))
wo_type_joined = multi_dict_unpacking(wo_type_flattened)
Expand Down

0 comments on commit 42a4680

Please sign in to comment.