26 #include <string_view> 30 #include <snap/plugin.h> 38 static constexpr
int appVersion = 1;
39 static constexpr std::string_view appName =
"anycollect"sv;
42 static constexpr std::array appPrefix = {
"cfm"sv,
"anycollect"sv};
43 static constexpr std::string_view configKeyConfigFile =
"ConfigFile"sv;
44 static constexpr std::string_view configKeySamplingInterval =
"SamplingInterval"sv;
45 static constexpr std::string_view configKeySendAllMetrics =
"SendAllMetrics"sv;
46 static constexpr std::string_view configKeyMaxCollectDuration =
"MaxCollectDuration"sv;
47 static constexpr std::string_view configKeyMaxMetricsBuffer =
"MaxMetricsBuffer"sv;
48 static constexpr std::array configKeysInt = {configKeySamplingInterval, configKeyMaxCollectDuration, configKeyMaxMetricsBuffer};
49 static constexpr std::array configKeysBool = {configKeySendAllMetrics};
50 static constexpr
bool defaultSendAllMetrics =
false;
51 static constexpr std::chrono::seconds defaultMaxCollectDuration = 0s;
52 static constexpr
size_t defaultMaxMetricsBuffer = 0;
54 static constexpr std::array<int, configKeysBool.size()> configValuesBool = {SnapInterface::defaultSendAllMetrics};
55 static std::hash<std::string>
hasher;
70 void insertAppPrefixToNamespace(std::vector<std::string>& ns);
77 void setConfig(
const Plugin::Config& cfg);
84 void formatName(std::vector<std::string>& name);
92 size_t computeNameKey(
const Metric& m);
100 size_t computeNameKey(
const Plugin::Metric& m);
108 Plugin::Metric convertToSnapMetric(
const Metric& metric);
122 const Plugin::ConfigPolicy get_config_policy() override final;
130 std::vector<Plugin::
Metric> get_metric_types(Plugin::
Config cfg) override final;
137 void get_metrics_in(
std::vector<Plugin::
Metric> &metsIn) override final;
142 void stream_metrics() override final;
145 void contollerCollectedMetrics(const
Controller& controller, const
std::vector<const
Metric*>& metrics) override final;
146 bool contollerShouldStopCollectingMetrics(const
Controller& controller) override final;
155 int main(
int argc,
char* argv[]);
static constexpr std::chrono::seconds defaultSamplingInterval
Default parameter option.
std::set< size_t > unwantedMetrics_
Array of keys of non requested metrics.
std::map< size_t, Plugin::Metric > metrics_
Map associating keys to their metric.
static std::hash< std::string > hasher
Object used to compute keys (string hashes)
Struct used to represent the JSON configuration file.
AnyCollect::Controller controller_
Controller used to collect statistics.
std::vector< Plugin::Metric * > metricsToSend_
Array of pointers to Snap metrics to be sent.
int main(int argc, char *argv[])
AnyCollect's main function.
Class used to represent a metric object (with a name, unit, tags, a value and a timestamp) ...
Abstract delegate of Controller.
std::set< size_t > requestedMetrics_
Array of keys of requested metrics.
bool sendAllMetrics_
Whether to send all metrics, regardless of which are requested.