Skip to content

Commit a907335

Browse files
authored
captool: add series value dumping capability (#997)
* Add series value dumping capability * Add fetch index to dump output
1 parent a3396aa commit a907335

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lading/src/bin/captool.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ struct Args {
2222
#[clap(short, long)]
2323
metric: Option<String>,
2424

25+
/// dump a metric's values. Requires --metric.
26+
#[clap(short, long)]
27+
dump_values: bool,
28+
2529
/// Path to line-delimited capture file
2630
capture_path: String,
2731
}
@@ -88,7 +92,7 @@ async fn main() -> Result<(), Error> {
8892
return Ok(());
8993
}
9094

91-
if let Some(metric) = args.metric {
95+
if let Some(metric) = &args.metric {
9296
// key is hash of the metric name and all the sorted, concatenated labels
9397
// value is a tuple of
9498
// - hashset of "key:value" strings (aka, concatenated labels)
@@ -100,7 +104,7 @@ async fn main() -> Result<(), Error> {
100104
// Use a BTreeSet to ensure that the tags are sorted
101105
lines
102106
.iter()
103-
.filter(|line| line.metric_name == metric)
107+
.filter(|line| &line.metric_name == metric)
104108
.for_each(|line| {
105109
let mut sorted_labels: BTreeSet<String> = BTreeSet::new();
106110
for (key, value) in line.labels.iter() {
@@ -133,6 +137,20 @@ async fn main() -> Result<(), Error> {
133137
}
134138
}
135139

140+
if args.dump_values {
141+
if let Some(metric) = &args.metric {
142+
lines
143+
.iter()
144+
.filter(|line| &line.metric_name == metric)
145+
.for_each(|line| {
146+
println!("{}: {}", line.fetch_index, line.value);
147+
});
148+
} else {
149+
error!("--dump-values requires --metric");
150+
return Err(Error::InvalidArgs);
151+
}
152+
}
153+
136154
info!("Bye. :)");
137155
Ok(())
138156
}

lading_capture/src/json.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ impl LineValue {
3838
}
3939
}
4040

41+
impl std::fmt::Display for LineValue {
42+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43+
match self {
44+
LineValue::Int(int) => write!(f, "{int}"),
45+
LineValue::Float(float) => write!(f, "{float}"),
46+
}
47+
}
48+
}
49+
4150
#[derive(Debug, Serialize, Deserialize)]
4251
/// The structure of a capture file line.
4352
pub struct Line<'a> {

0 commit comments

Comments
 (0)