From 27e239543105a6dc1530927a89bc5f6369715dc7 Mon Sep 17 00:00:00 2001 From: Dan Rowe Date: Wed, 4 Dec 2013 09:44:05 -0500 Subject: [PATCH 1/3] Add GRAPH_URL config option so that GRAPHITE_HOST is just the Graphite Host or ip. --- src/analyzer/alerters.py | 4 ++-- src/analyzer/analyzer.py | 2 +- src/horizon/worker.py | 2 +- src/settings.py.example | 6 +++++- src/webapp/static/js/skyline.js | 6 +++--- src/webapp/webapp.py | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/analyzer/alerters.py b/src/analyzer/alerters.py index edf076b0..04f42096 100644 --- a/src/analyzer/alerters.py +++ b/src/analyzer/alerters.py @@ -39,7 +39,7 @@ def alert_smtp(alert, metric): msg['Subject'] = '[skyline alert] ' + metric[1] msg['From'] = sender msg['To'] = recipient - link = '%s/render/?width=588&height=308&target=%s' % (settings.GRAPHITE_HOST, metric[1]) + link = settings.GRAPH_URL % (metric[1]) body = 'Anomalous value: %s
Next alert in: %s seconds ' % (metric[0], alert[2], link, link) msg.attach(MIMEText(body, 'html')) s = SMTP('127.0.0.1') @@ -57,7 +57,7 @@ def alert_hipchat(alert, metric): import hipchat hipster = hipchat.HipChat(token=settings.HIPCHAT_OPTS['auth_token']) rooms = settings.HIPCHAT_OPTS['rooms'][alert[0]] - link = '%s/render/?width=588&height=308&target=%s' % (settings.GRAPHITE_HOST, metric[1]) + link = settings.GRAPH_URL % (metric[1]) for room in rooms: hipster.method('rooms/message', method='POST', parameters={'room_id': room, 'from': 'Skyline', 'color': settings.HIPCHAT_OPTS['color'], 'message': 'Anomaly: %s : %s' % (link, metric[1], metric[0])}) diff --git a/src/analyzer/analyzer.py b/src/analyzer/analyzer.py index 77258e67..51bf4d95 100644 --- a/src/analyzer/analyzer.py +++ b/src/analyzer/analyzer.py @@ -47,7 +47,7 @@ def check_if_parent_is_alive(self): def send_graphite_metric(self, name, value): if settings.GRAPHITE_HOST != '': sock = socket.socket() - sock.connect((settings.GRAPHITE_HOST.replace('http://', ''), settings.CARBON_PORT)) + sock.connect((settings.GRAPHITE_HOST, settings.CARBON_PORT)) sock.sendall('%s %s %i\n' % (name, value, time())) sock.close() return True diff --git a/src/horizon/worker.py b/src/horizon/worker.py index 705e0acc..6bdd44ff 100644 --- a/src/horizon/worker.py +++ b/src/horizon/worker.py @@ -48,7 +48,7 @@ def in_skip_list(self, metric_name): def send_graphite_metric(self, name, value): if settings.GRAPHITE_HOST != '': sock = socket.socket() - sock.connect((settings.GRAPHITE_HOST.replace('http://', ''), settings.CARBON_PORT)) + sock.connect((settings.GRAPHITE_HOST, settings.CARBON_PORT)) sock.sendall('%s %s %i\n' % (name, value, time())) sock.close() return True diff --git a/src/settings.py.example b/src/settings.py.example index c128fe88..32cfe4b2 100644 --- a/src/settings.py.example +++ b/src/settings.py.example @@ -32,7 +32,11 @@ MINI_DURATION = 3600 # If you have a Graphite host set up, set this metric to get graphs on # Skyline and Horizon. Include http://. -GRAPHITE_HOST = 'http://your_graphite_host.com' +GRAPHITE_HOST = 'your_graphite_host.com' + +# The Graph url used to link to Graphite (Or another graphite dashboard) +# %s will be replaced by the metric name +GRAPH_URL = 'http://' + GRAPHITE_HOST + '/render/?width=1400&from=-1hour&target=%s' # If you have a Graphite host set up, set its Carbon port. CARBON_PORT = 2003 diff --git a/src/webapp/static/js/skyline.js b/src/webapp/static/js/skyline.js index 81e8e1e9..2c3ca93e 100644 --- a/src/webapp/static/js/skyline.js +++ b/src/webapp/static/js/skyline.js @@ -1,4 +1,4 @@ -var GRAPHITE_HOST, +var GRAPH_URL, OCULUS_HOST, FULL_NAMESPACE, mini_graph, @@ -17,7 +17,7 @@ var handle_data = function(data) { for (i in data) { metric = data[i]; name = metric[1] - var src = GRAPHITE_HOST + '/render/?width=1400&from=-1hour&target=' + name; + var src = GRAPH_URL.replace('%s', name); // Add a space after the metric name to make each unique to_append = "
" + name + "
  " if (OCULUS_HOST != ''){ @@ -150,7 +150,7 @@ $(function(){ // Get the variables from settings.py data = JSON.parse(data); FULL_NAMESPACE = data['FULL_NAMESPACE']; - GRAPHITE_HOST = data['GRAPHITE_HOST']; + GRAPH_URL = data['GRAPH_URL']; OCULUS_HOST = data['OCULUS_HOST']; // Get initial data after getting the host variables diff --git a/src/webapp/webapp.py b/src/webapp/webapp.py index 5004e9a3..6751d761 100644 --- a/src/webapp/webapp.py +++ b/src/webapp/webapp.py @@ -25,7 +25,7 @@ def index(): @app.route("/app_settings") def app_settings(): - app_settings = {'GRAPHITE_HOST': settings.GRAPHITE_HOST, + app_settings = {'GRAPH_URL': settings.GRAPH_URL, 'OCULUS_HOST': settings.OCULUS_HOST, 'FULL_NAMESPACE': settings.FULL_NAMESPACE, } From 3047b8221564ad1e0def5ad81cea168f8cd9de08 Mon Sep 17 00:00:00 2001 From: Dan Rowe Date: Wed, 4 Dec 2013 09:47:10 -0500 Subject: [PATCH 2/3] update language of GRAPHITE_HOST a little, could still use some love --- src/settings.py.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings.py.example b/src/settings.py.example index 32cfe4b2..8ba7d63c 100644 --- a/src/settings.py.example +++ b/src/settings.py.example @@ -31,7 +31,7 @@ FULL_DURATION = 86400 MINI_DURATION = 3600 # If you have a Graphite host set up, set this metric to get graphs on -# Skyline and Horizon. Include http://. +# Skyline and Horizon. Don't include http:// since this is used for carbon host as well. GRAPHITE_HOST = 'your_graphite_host.com' # The Graph url used to link to Graphite (Or another graphite dashboard) From ac07cd05c2ee193176872e5122d23f096780d0fc Mon Sep 17 00:00:00 2001 From: Dan Rowe Date: Wed, 4 Dec 2013 09:56:44 -0500 Subject: [PATCH 3/3] whitespace cleanup for pep8 --- src/settings.py.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/settings.py.example b/src/settings.py.example index 8ba7d63c..5a65a1f0 100644 --- a/src/settings.py.example +++ b/src/settings.py.example @@ -34,9 +34,9 @@ MINI_DURATION = 3600 # Skyline and Horizon. Don't include http:// since this is used for carbon host as well. GRAPHITE_HOST = 'your_graphite_host.com' -# The Graph url used to link to Graphite (Or another graphite dashboard) +# The Graph url used to link to Graphite (Or another graphite dashboard) # %s will be replaced by the metric name -GRAPH_URL = 'http://' + GRAPHITE_HOST + '/render/?width=1400&from=-1hour&target=%s' +GRAPH_URL = 'http://' + GRAPHITE_HOST + '/render/?width=1400&from=-1hour&target=%s' # If you have a Graphite host set up, set its Carbon port. CARBON_PORT = 2003