roo_monitoring
API Documentation for roo_monitoring
Loading...
Searching...
No Matches
compaction.h
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <memory>
5
6#include "log.h"
7#include "roo_io/data/output_stream_writer.h"
8#include "roo_monitoring.h"
9#include "stdint.h"
10
11namespace roo_monitoring {
12
13/// Aggregates samples for a vault file time bucket.
15 public:
16 /// Clears any accumulated data.
17 void clear();
18 /// Adds a sample into the aggregation state.
19 void add(const Sample& sample);
20
21 private:
22 friend class VaultWriter;
23
24 struct SampleAggregator {
25 SampleAggregator()
26 : weighted_total(0), weight(0), min_value(0xFFFF), max_value(0) {}
27
28 uint32_t weighted_total;
29 uint16_t weight;
30 uint16_t min_value;
31 uint16_t max_value;
32 };
33
34 std::vector<SampleAggregator> data_;
35 std::map<uint64_t, int> index_;
36};
37
38/// Writes vault files for a collection at a specific resolution.
40 public:
41 /// Creates a writer for the given collection and vault file.
42 VaultWriter(Collection* collection, VaultFileRef ref);
43 /// Returns the reference to the vault file being written.
44 const VaultFileRef& vault_ref() const { return ref_; }
45
46 /// Opens a new vault file for writing.
47 roo_io::Status openNew();
48
49 /// Opens an existing vault file, seeking to the specified entry index.
50 roo_io::Status openExisting(int write_index);
51
52 /// Closes the underlying writer.
53 void close() { writer_.close(); }
54
55 /// Returns the current write index within the vault file.
56 int write_index() const { return write_index_; }
57
58 /// Writes an empty vault file payload.
59 void writeEmptyData();
60
61 /// Writes raw log samples into the vault file.
62 void writeLogData(const std::vector<LogSample>& data);
63
64 /// Writes aggregated samples into the vault file.
65 void writeAggregatedData(const Aggregator& aggregator);
66
67 /// Returns true if the writer is in a good state.
68 bool ok() const { return writer_.ok(); }
69
70 /// Returns the current writer status.
71 roo_io::Status status() const { return writer_.status(); }
72
73 private:
74 void writeHeader();
75
76 const Collection* collection_;
77 VaultFileRef ref_;
78 int write_index_;
79 roo_io::OutputStreamWriter writer_;
80};
81
82} // namespace roo_monitoring
Aggregates samples for a vault file time bucket.
Definition compaction.h:14
void clear()
Clears any accumulated data.
void add(const Sample &sample)
Adds a sample into the aggregation state.
Collection of timeseries sharing transform and source resolution.
Represents a single data sample stored in a vault file.
Definition sample.h:6
Identifies a specific file in the monitoring vault.
Definition vault.h:16
Writes vault files for a collection at a specific resolution.
Definition compaction.h:39
int write_index() const
Returns the current write index within the vault file.
Definition compaction.h:56
roo_io::Status openExisting(int write_index)
Opens an existing vault file, seeking to the specified entry index.
void writeAggregatedData(const Aggregator &aggregator)
Writes aggregated samples into the vault file.
roo_io::Status status() const
Returns the current writer status.
Definition compaction.h:71
const VaultFileRef & vault_ref() const
Returns the reference to the vault file being written.
Definition compaction.h:44
void writeEmptyData()
Writes an empty vault file payload.
void close()
Closes the underlying writer.
Definition compaction.h:53
roo_io::Status openNew()
Opens a new vault file for writing.
void writeLogData(const std::vector< LogSample > &data)
Writes raw log samples into the vault file.
bool ok() const
Returns true if the writer is in a good state.
Definition compaction.h:68
Umbrella header for the roo_monitoring module.