Skip to content

Commit

Permalink
Improve output of check_metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
sloria committed Sep 4, 2018
1 parent 6613e4a commit 00f2e98
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions elasticsearch_metrics/management/commands/check_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import logging
from django.core.management.base import BaseCommand, CommandError

from django.utils.termcolors import colorize

from elasticsearch_metrics.registry import registry
from elasticsearch_metrics import exceptions
from elasticsearch_metrics.management.color import color_style
Expand Down Expand Up @@ -34,8 +36,8 @@ def handle(self, *args, **options):
else:
app_labels = registry.all_metrics.keys()

out_of_sync = False
self.stdout.write("Checking for missing index templates...")
out_of_sync_count = 0
self.stdout.write("Checking for outdated index templates...")
for app_label in app_labels:
metrics = registry.get_metrics(app_label=app_label)
for metric in metrics:
Expand All @@ -45,10 +47,16 @@ def handle(self, *args, **options):
exceptions.IndexTemplateNotFoundError,
exceptions.IndexTemplateOutOfSyncError,
) as error:
self.stdout.write(error.args[0], style.ERROR)
out_of_sync = True
self.stdout.write(" " + error.args[0])
out_of_sync_count += 1

if out_of_sync:
if out_of_sync_count:
self.stdout.write(
"{} index template(s) out of sync.".format(out_of_sync_count),
style.ERROR,
)
cmd = colorize("python manage.py sync_metrics", opts=("bold",))
self.stdout.write("Run {cmd} to synchronize.".format(cmd=cmd))
sys.exit(1)
else:
self.stdout.write("All metrics in sync.", style.SUCCESS)

0 comments on commit 00f2e98

Please sign in to comment.