roo_monitoring
API Documentation for roo_monitoring
Loading...
Searching...
No Matches
roo_monitoring.h
Go to the documentation of this file.
1#pragma once
2
3/// Umbrella header for the roo_monitoring module.
4///
5/// Provides data collection, transformation, and vault APIs.
6
7#include <Arduino.h>
8
9#include <set>
10
11#include "roo_io/fs/filesystem.h"
13#include "roo_monitoring/log.h"
18
19namespace roo_monitoring {
20
21/// Collection of timeseries sharing transform and source resolution.
22///
23/// Group streams that are commonly queried/plotted together.
25 public:
26 Collection(roo_io::Filesystem& fs, String name,
28
29 roo_io::Filesystem& fs() const { return fs_; }
30 const String& name() const { return name_; }
31 Resolution resolution() const { return resolution_; }
32 const Transform& transform() const { return transform_; }
33
34 void getVaultFilePath(const VaultFileRef& ref, String* path) const;
35
36 private:
37 friend class Writer;
38 friend class WriteTransaction;
39
40 roo_io::Filesystem& fs_;
41 String name_;
42 String base_dir_;
43 Resolution resolution_;
44 Transform transform_;
45};
46
47class LogReader;
48class LogFileReader;
49class VaultWriter;
50
51/// Write interface for a monitoring collection.
52class Writer {
53 public:
55
57
59
60 const Collection& collection() const { return *collection_; }
61
62 /// Periodically flushes logged data into vault files.
63 void flushAll();
64
65 IoState io_state() const { return io_state_; }
66
67 void flushSome();
68
69 bool isFlushInProgress() { return flush_in_progress_; }
70
71 private:
72 friend class WriteTransaction;
73
74 /// Writes logs to vault and returns past-end index written.
75 int16_t writeToVault(roo_io::Mount& fs, LogReader& reader, VaultFileRef ref);
76
77 Status compactVaultOneLevel();
78
79 Collection* collection_;
80 String log_dir_;
81 CachedLogDir cache_;
82 LogWriter writer_;
83 IoState io_state_;
84
85 VaultFileRef compaction_head_;
86 int16_t compaction_head_index_end_;
87 bool is_hot_range_;
88
89 bool flush_in_progress_;
90};
91
92/// Represents a single write operation to a monitoring collection.
93///
94/// Intended as a transient RAII object; commit happens on destruction.
96 public:
97 WriteTransaction(Writer* writer);
99
100 void write(int64_t timestamp, uint64_t stream_id, float data);
101
102 private:
103 const Transform* transform_;
104 LogWriter* writer_;
105};
106
107/// Iterator that scans monitoring data at a given resolution.
108///
109/// Starts at a specified timestamp and reads across vault files. Missing vault
110/// ranges yield empty samples.
112 public:
113 /// Creates iterator over `collection` at `resolution`, starting at `start`.
114 ///
115 /// Start timestamp is rounded down to resolution boundary.
116 VaultIterator(const Collection* collection, int64_t start,
117 Resolution resolution);
118
119 /// Returns current iterator timestamp.
120 int64_t cursor() const;
121
122 /// Advances by one resolution step and fills `sample`.
123 void next(std::vector<Sample>* sample);
124
125 private:
126 const Collection* collection_;
127 VaultFileRef current_ref_;
128 VaultFileReader current_;
129};
130
131} // namespace roo_monitoring
In-memory cache of log directory entries.
Definition log.h:35
Collection of timeseries sharing transform and source resolution.
roo_io::Filesystem & fs() const
Resolution resolution() const
const String & name() const
void getVaultFilePath(const VaultFileRef &ref, String *path) const
const Transform & transform() const
Reader for a single log file.
Definition log.h:67
Reader that walks across a sequence of log files.
Definition log.h:114
Writer for log files at a fixed resolution.
Definition log.h:156
Maps application-domain floats to 16-bit stored values.
Definition transform.h:10
Sequential reader for a single vault file.
Definition vault.h:106
Identifies a specific file in the monitoring vault.
Definition vault.h:16
Iterator that scans monitoring data at a given resolution.
int64_t cursor() const
Returns current iterator timestamp.
void next(std::vector< Sample > *sample)
Advances by one resolution step and fills sample.
Writes vault files for a collection at a specific resolution.
Definition compaction.h:39
Represents a single write operation to a monitoring collection.
void write(int64_t timestamp, uint64_t stream_id, float data)
Write interface for a monitoring collection.
const Collection & collection() const
void flushAll()
Periodically flushes logged data into vault files.
IoState io_state() const
Umbrella header for the roo_monitoring module.
Resolution
Time resolution used for log and vault files.
Definition resolution.h:8