diff --git a/examples/example_dashboards.yaml b/examples/example_dashboards.yaml index de16d10..b4f0770 100644 --- a/examples/example_dashboards.yaml +++ b/examples/example_dashboards.yaml @@ -8,10 +8,8 @@ - source: http://heimdall:9001 # Prometheus source uri for this plot query: 'sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m]))' # The PromQL query for this plot meta: # metadata for this plot - name_label: instance # Grab a trace name from the query tags + name_format: "`${labels.instance}`" # javascript template literal to format the trace name #d3_tick_format: "~%" # d3 tick format override for this plot's yaxis - #name_prefix: "Prefix" # A prefix for this sublots trace names - #name_suffix: "Suffix" # A suffix for this subplots trace names #named_axis: "y" # yaxis name to use for this subplots traces span: # The span for this range query end: now # Where the span ends. RFC3339 format with special handling for the now keyword @@ -32,16 +30,14 @@ sum by (instance)(irate(node_cpu_seconds_total{mode="system",job="nodestats"}[5m])) / sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m])) meta: d3_tick_format: "~%" - name_label: instance - name_prefix: "System" + name_format: "`${labels.instance} system`" named_axis: "y" - source: http://heimdall:9001 query: | sum by (instance)(irate(node_cpu_seconds_total{mode="user",job="nodestats"}[5m])) / sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m])) meta: d3_tick_format: "~%" - name_label: instance - name_suffix: "User" + name_format: "`${labels.instance} user`" named_axis: "y" - title: Node memory query_type: Scalar @@ -49,4 +45,4 @@ - source: http://heimdall:9001 query: 'node_memory_MemFree_bytes{job="nodestats"}' meta: - name_label: instance + name_format: "`${labels.instance}`" diff --git a/flake.nix b/flake.nix index c91bad9..bce900c 100644 --- a/flake.nix +++ b/flake.nix @@ -63,9 +63,7 @@ sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m])) ''; meta = { - name_label = "instance"; - name_prefix = "trace name prefix"; - name_suffix = "trace name suffix"; + name_function = "`\${labels.instance}`"; named_axis = "y"; # yaxis formatting for this subplot d3_tick_format = "~s"; diff --git a/src/query.rs b/src/query.rs index ee9bba2..ba246fc 100644 --- a/src/query.rs +++ b/src/query.rs @@ -117,9 +117,7 @@ pub struct DataPoint { #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PlotMeta { - name_prefix: Option, - name_suffix: Option, - name_label: Option, + name_format: Option, named_axis: Option, d3_tick_format: Option, } diff --git a/static/lib.js b/static/lib.js index 7bb274f..f73796b 100644 --- a/static/lib.js +++ b/static/lib.js @@ -160,19 +160,17 @@ class TimeseriesGraph extends HTMLElement { yaxis: yaxis, yhoverformat: meta["d3_tick_format"], }; - const namePrefix = meta["name_prefix"]; - const nameSuffix = meta["name_suffix"]; - const nameLabel = meta["name_label"]; var name = ""; - if (namePrefix) { - name = namePrefix + "-"; - }; - if (nameLabel && labels[nameLabel]) { - name = name + labels[nameLabel]; - }; - if (nameSuffix) { - name = name + " - " + nameSuffix; - }; + const formatter = meta.name_format + if (formatter) { + name = eval(formatter); + } else { + var names = []; + for (const value of labels) { + names.push(value); + } + name = names.join(" "); + } if (name) { trace.name = name; } for (const point of series) { trace.x.push(new Date(point.timestamp * 1000));