Skip to content

Commit

Permalink
Reuse graphite time format constant
Browse files Browse the repository at this point in the history
  • Loading branch information
stveit committed Mar 9, 2023
1 parent 3b40ba2 commit db33cb2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions python/nav/metrics/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
_logger = logging.getLogger(__name__)

MAX_TARGETS_PER_REQUEST = 100
GRAPHITE_TIME_FORMAT = "%H:%M_%Y%m%d"


def get_metric_average(target, start="-5min", end="now", ignore_unknown=True):
Expand Down Expand Up @@ -109,9 +110,9 @@ def get_metric_data(target, start="-5min", end="now"):
# What does Graphite accept of formats? Lets check if the parameters are
# datetime objects and try to force a format then
if isinstance(start, datetime):
start = start.strftime('%H:%M%Y%m%d')
start = start.strftime(GRAPHITE_TIME_FORMAT)
if isinstance(end, datetime):
end = end.strftime('%H:%M%Y%m%d')
end = end.strftime(GRAPHITE_TIME_FORMAT)

query = {
'target': target,
Expand Down
2 changes: 1 addition & 1 deletion python/nav/web/sortedstats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
from .forms import ViewForm
from . import CLASSMAP, TIMEFRAMES
from nav.metrics.errors import GraphiteUnreachableError
from nav.metrics.data import GRAPHITE_TIME_FORMAT

GRAPHITE_TIME_FORMAT = "%H:%M_%Y%m%d"
_logger = logging.getLogger(__name__)
cache = caches['sortedstats']

Expand Down

0 comments on commit db33cb2

Please sign in to comment.