28 template<
typename Clock,
typename Duration>
30 const std::chrono::time_point<Clock, Duration> &time_point) {
31 const time_t time = Clock::to_time_t(time_point);
33 localtime_r(&time, &tm);
34 return stream << std::put_time(&tm,
"%c");
39 std::string name = m.
name()[0];
40 for (
size_t i = 1; i < m.
name().size(); i++)
41 name +=
"/" + m.
name()[i];
43 for (
const auto& [k, v] : m.
tags())
44 tags +=
"'" + k +
"'='" + v +
"', ";
45 std::cout << std::setw(54) << std::left << name;
46 std::cout << std::setw(20) << std::right << std::setprecision(18) << m.
value() <<
" ";
47 std::cout << std::setw(16) << std::left << m.
unit();
48 std::cout << std::setw(54) << std::left << tags;
49 std::cout << std::endl;
58 for (
const auto& m : metrics)
60 std::cout << std::endl <<
"----------------" << std::endl << std::endl;
73 int main(
int argc,
char* argv[]) {
75 std::string configPath =
"";
79 samplingInterval = std::chrono::seconds(std::atol(argv[1]));
void loadConfigFromFile(const std::string &configPath)
Configures sources, expressions and matchers according to config file.
int main(int argc, char *argv[])
AnyCollect's main function.
void setSamplingInterval(std::chrono::seconds interval) noexcept
Sets the metrics sampling interval.
void contollerCollectedMetrics(const AnyCollect::Controller &, const std::vector< const AnyCollect::Metric *> &) override
Function called every time the Controller has collected metrics.
static constexpr std::chrono::seconds defaultSamplingInterval
Default parameter option.
bool contollerShouldStopCollectingMetrics(const AnyCollect::Controller &) override
Function called after each iteration to ask the delegate whether the controller should stop collectin...
const std::string & unit() const noexcept
Returns the unit of the metric.
const std::vector< std::string > & name() const noexcept
Returns the name of the metric.
void printMetric(const AnyCollect::Metric &m)
std::ostream & operator<<(std::ostream &stream, const std::chrono::time_point< Clock, Duration > &time_point)
void collectMetrics() noexcept
Launch metric collection loop.
const std::map< std::string, std::string > & tags() const noexcept
Returns the tags of the metric.
Class used to represent a metric object (with a name, unit, tags, a value and a timestamp) ...
Abstract delegate of Controller.
double value() const noexcept
Returns the value of the metric.