MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / scan_metrics

Method scan_metrics

nodedb/src/engine/timeseries/query.rs:81–112  ·  view source on GitHub ↗

Scan all metric samples for a series within a time range.

(
        &self,
        series_id: SeriesId,
        range: &TimeRange,
    )

Source from the content-addressed store, hash-verified

79
80 /// Scan all metric samples for a series within a time range.
81 pub fn scan_metrics(
82 &self,
83 series_id: SeriesId,
84 range: &TimeRange,
85 ) -> Result<Vec<(i64, f64)>, QueryError> {
86 let segments = self.segment_index.query(series_id, range);
87 if segments.is_empty() {
88 return Ok(Vec::new());
89 }
90
91 let mut all_samples = Vec::new();
92
93 for seg in &segments {
94 if seg.kind != SegmentKind::Metric {
95 continue;
96 }
97
98 let path = self.l1_dir.join(&seg.path);
99 let data = reader::read_metric_segment(&path)?;
100
101 // Filter to exact time range.
102 for (ts, val) in data.samples {
103 if range.contains(ts) {
104 all_samples.push((ts, val));
105 }
106 }
107 }
108
109 // Sort by timestamp for ordered output.
110 all_samples.sort_by_key(|&(ts, _)| ts);
111 Ok(all_samples)
112 }
113
114 /// Aggregate metrics for a series within a time range.
115 pub fn aggregate_metrics(

Callers 6

aggregate_metricsMethod · 0.80
downsample_metricsMethod · 0.80
scan_metrics_full_rangeFunction · 0.80

Calls 6

read_metric_segmentFunction · 0.85
joinMethod · 0.80
queryMethod · 0.45
is_emptyMethod · 0.45
containsMethod · 0.45
pushMethod · 0.45

Tested by 4

scan_metrics_full_rangeFunction · 0.64