Skip to content

Commit

Permalink
Merge pull request #109 from innogames/grapite_cron_logging
Browse files Browse the repository at this point in the history
Improve logging of cache_graphite command
  • Loading branch information
kofrezo committed Aug 6, 2020
2 parents e5001df + 3559e7d commit 9d27a1a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions serveradmin/graphite/management/commands/cache_graphite.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import json
from datetime import datetime
from os import mkdir
from os.path import isdir
import time
Expand Down Expand Up @@ -36,13 +37,18 @@ class Command(BaseCommand):

def handle(self, *args, **kwargs):
"""The entry point of the command"""

start = time.time()

sprite_params = settings.GRAPHITE_SPRITE_PARAMS
sprite_dir = settings.MEDIA_ROOT + '/graph_sprite'
if not isdir(sprite_dir):
mkdir(sprite_dir)

# We will make sure to generate a single sprite for a single hostname.
for collection in Collection.objects.filter(overview=True):
collection_start = time.time()

collection_dir = sprite_dir + '/' + collection.name
if not isdir(collection_dir):
mkdir(collection_dir)
Expand All @@ -57,6 +63,14 @@ def handle(self, *args, **kwargs):
self.generate_sprite(collection_dir, graph_table, server)
self.cache_numerics(collection, server)

collection_duration = time.time() - collection_start
print('[{}] Collection {} finished after {} seconds'.format(
datetime.now(), collection.name, collection_duration))

duration = time.time() - start
print('[{}] Finished after {} seconds'.format(datetime.now(),
duration))

def generate_sprite(self, collection_dir, graph_table, server):
"""Generate sprites for the given server using the given collection"""
graphs = [v2 for k1, v1 in graph_table for k2, v2 in v1]
Expand Down

0 comments on commit 9d27a1a

Please sign in to comment.