diff --git a/prometheus-http-client/src/lib.rs b/prometheus-http-client/src/lib.rs index aa8fbd7..bd26e24 100644 --- a/prometheus-http-client/src/lib.rs +++ b/prometheus-http-client/src/lib.rs @@ -1,6 +1,6 @@ #![deny(missing_docs)] -//! Minimal API for getting time series data from prometheus +//! Minimal API for getting time series data from prometheus, and making small plots. //! //! To use it, instantiate one of the request objects, //! e.g. QueryRequest or QueryRangeRequest. When it's helpful a builder is provided. @@ -16,7 +16,7 @@ //! `serde::Deserialize` in the `PromData` that results from the call. //! //! When `plot` feature is active, the plot module can be used to plot the timeseries data. -//! This is mostly intended to be used as previews in alert messages. +//! This was designed to be used to generate previews in alert messages. use chrono::{DateTime, Utc}; use serde::{Serialize, de::DeserializeOwned}; diff --git a/prometheus-http-client/src/plot.rs b/prometheus-http-client/src/plot.rs index 8e299d1..5e89235 100644 --- a/prometheus-http-client/src/plot.rs +++ b/prometheus-http-client/src/plot.rs @@ -39,6 +39,8 @@ pub struct PlotStyle { pub utc_offset_hours: i32, /// Optional title override - used when prometheus aggregations remove __name__ pub title: Option, + /// The stroke width for data lines (default: 1) + pub line_width: u32, } impl Default for PlotStyle { @@ -69,6 +71,7 @@ impl Default for PlotStyle { skip_labels: vec!["job".into(), "instance".into()], utc_offset_hours: 0, title: None, + line_width: 1, } } } @@ -91,6 +94,12 @@ impl PlotStyle { self.utc_offset_hours = offset; self } + + /// Set the stroke width for data lines + pub fn with_line_width(mut self, width: u32) -> Self { + self.line_width = width; + self + } } /// A shaded region appearing on the plot to indicate values that would trigger an alert @@ -214,15 +223,16 @@ impl PlotStyle { for (idx, (mut metric, vals)) in specific_labels.into_iter().zip(ts.into_iter()).enumerate() { let color = &self.data_colors[idx % self.data_colors.len()]; + let style = ShapeStyle::from(color).stroke_width(self.line_width); let name = metric.remove("__name__").unwrap_or_default(); let label = format!("{name} {metric:?}"); - let series = ctx.draw_series(LineSeries::new(vals, color))?; + let series = ctx.draw_series(LineSeries::new(vals, style))?; if show_legend { series .label(label) - .legend(move |(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], color)); + .legend(move |(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], style)); } }