Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration dashboard's graph with statsd
- Loading branch information
Showing
9 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
33 changes: 33 additions & 0 deletions
33
src/ralph/dashboards/management/commands/push_graphs_to_statsd.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
import logging | ||
import textwrap | ||
|
||
from django.conf import settings | ||
from django.core.management.base import BaseCommand | ||
from django.utils.text import slugify | ||
|
||
from ralph.dashboards.models import Graph | ||
from ralph.lib.metrics import statsd | ||
|
||
logger = logging.getLogger(__name__) | ||
PREFIX = settings.STATSD_GRAPHS_PREFIX | ||
STATSD_PATH = '{}.{{}}.{{}}'.format(PREFIX) | ||
|
||
|
||
def normalize(s): | ||
s = slugify(s) | ||
return s.replace('-', '_') | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Push to statsd data generated by graphs.""" | ||
help = textwrap.dedent(__doc__).strip() | ||
|
||
def handle(self, *args, **kwargs): | ||
graphs = Graph.objects.filter(push_to_statsd=True) | ||
for graph in graphs: | ||
graph_data = graph.get_data() | ||
graph_name = normalize(graph.name) | ||
for label, value in zip(graph_data['labels'], graph_data['series']): | ||
path = STATSD_PATH.format(graph_name, normalize(label)) | ||
statsd.gauge(path, value) |
19 changes: 19 additions & 0 deletions
19
src/ralph/dashboards/migrations/0003_graph_push_to_statsd.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('dashboards', '0002_auto_20170509_1404'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='graph', | ||
name='push_to_statsd', | ||
field=models.BooleanField(default=False, help_text="Push graph's data to statsd."), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters