Skip to content

Commit

Permalink
[feature] Added option to specify trace labels
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy committed Apr 4, 2024
1 parent c9be866 commit c00fe96
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions openwisp_monitoring/monitoring/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ def trace_type(self):
def trace_order(self):
return self.config_dict.get('trace_order', [])

@property
def trace_labels(self):
return self.config_dict.get('trace_labels', {})

@property
def calculate_total(self):
return self.config_dict.get('calculate_total', False)
Expand Down
4 changes: 3 additions & 1 deletion openwisp_monitoring/monitoring/static/monitoring/js/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@
// loop over traces to put them on the chart
for (var i=0; i<data.traces.length; i++) {
key = data.traces[i][0];
label = data.traces[i][0].replace(/_/g, ' ');
// label for the trace, use trace_labels if available, otherwise
// replace underscores with spaces in the key name
label = data.trace_labels && data.trace_labels[data.traces[i][0]] || data.traces[i][0].replace(/_/g, ' ');

if (data.summary_labels){
if (data.trace_order) {
Expand Down
2 changes: 2 additions & 0 deletions openwisp_monitoring/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def _get_charts_data(self, charts, time, timezone, start_date, end_date):
chart_dict['calculate_total'] = chart.calculate_total
if chart.connect_points:
chart_dict['connect_points'] = chart.connect_points
if chart.trace_labels:
chart_dict['trace_labels'] = chart.trace_labels
except InvalidChartConfigException:
logger.exception(f'Skipped chart for metric {chart.metric}')
continue
Expand Down

0 comments on commit c00fe96

Please sign in to comment.