forked from ahupowerdns/metronome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statstorage.hh
60 lines (56 loc) · 1.58 KB
/
statstorage.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include <string>
#include <vector>
#include <limits>
#include <tuple>
#include <ctime>
#include <regex.h>
//! make your own instance, not thread safe
class StatStorage
{
public:
StatStorage(const std::string& root);
~StatStorage();
void store(const std::string& name, uint32_t timestamp, float value);
struct Datum
{
uint32_t timestamp;
float value;
bool operator<(double t) const
{
return timestamp < t;
}
bool operator==(const Datum &rhs) const
{
return std::tie(rhs.timestamp, rhs.value) == std::tie(timestamp, value);
}
};
void store(const std::string& name, const std::vector<Datum>& data);
std::vector<Datum> retrieve(const std::string& name, time_t begin, time_t end, int number=-1);
std::vector<Datum> retrieve(const std::string& name);
std::vector<std::string> getMetrics();
private:
std::string d_root;
regex_t d_preg;
struct Val {
uint32_t timestamp;
float value;
bool operator<(const Val& rhs) const
{
return timestamp < rhs.timestamp;
}
bool operator<(int64_t rhs) const
{
return timestamp < rhs;
}
} __attribute__((packed));
unsigned int getWeekNum(uint32_t t);
std::string makeFilename(const std::string& name, uint32_t timestamp);
std::vector<Val> retrieveVals(const std::string& name, uint32_t begin, uint32_t end);
std::vector<Val> retrieveVals(const std::string& name);
void retrieveAllFromFile(const std::string& fname, std::vector<StatStorage::Val>* values);
};
inline bool operator<(double t, const StatStorage::Datum& d)
{
return t < d.timestamp;
}