28 #include <string_view> 32 #include <snap/plugin.h> 43 static constexpr
int appVersion = 2;
44 static constexpr std::string_view appName =
"metrocollect"sv;
55 std::vector<MetroCollect::DiffValueType>
values;
71 void clear(
size_t metricsCount) {
72 this->computedMetrics.clear();
73 this->metricsToSend.clear();
74 this->currentMetrics =
nullptr;
75 this->nextMetrics =
nullptr;
76 this->metricsTimeout.clear();
77 this->metricsTimeout.resize(metricsCount, ((
size_t)-1));
78 this->metricsTimeoutPointer.clear();
79 this->secondaryMetrics.clear();
84 static constexpr std::array appPrefix = {
"cfm"sv};
85 static constexpr std::string_view configKeySendValues =
"SendValues"sv;
86 static constexpr std::string_view configKeySendStats =
"SendStats"sv;
87 static constexpr std::string_view configKeySamplingInterval =
"SamplingInterval"sv;
88 static constexpr std::string_view configKeyProcessingWindowLength =
"ProcessingWindowLength"sv;
89 static constexpr std::string_view configKeyProcessingWindowOverlap =
"ProcessingWindowOverlap"sv;
90 static constexpr std::string_view configKeyConvertToUnitsPerSecond =
"ConvertToUnitsPerSecond"sv;
91 static constexpr std::string_view configKeyUnchangedMetricTimeout =
"UnchangedMetricTimeout"sv;
92 static constexpr std::string_view configKeyMaxCollectDuration =
"MaxCollectDuration"sv;
93 static constexpr std::string_view configKeyMaxMetricsBuffer =
"MaxMetricsBuffer"sv;
94 static constexpr std::array configKeysInt = {configKeySamplingInterval, configKeyProcessingWindowLength, configKeyProcessingWindowOverlap, configKeyUnchangedMetricTimeout, configKeyMaxCollectDuration, configKeyMaxMetricsBuffer};
95 static constexpr std::array configKeysBool = {configKeySendValues, configKeySendStats, configKeyConvertToUnitsPerSecond};
96 static constexpr
bool defaultSendValues =
false;
97 static constexpr
bool defaultSendStats =
true;
98 static constexpr
size_t defaultUnchangedMetricTimeout = 300;
99 static constexpr std::chrono::seconds defaultMaxCollectDuration = 0s;
100 static constexpr
size_t defaultMaxMetricsBuffer = 0;
103 static constexpr std::string_view statNamespaceLastComponent =
"value"sv;
104 static constexpr std::string_view statNamespaceDescription =
"statistic"sv;
120 void setConfig(
const Plugin::Config& cfg);
128 void parseSnapMetrics(
const std::vector<Plugin::Metric>& metrics);
136 void insertAppPrefixToNamespace(std::vector<std::string>& ns);
175 const Plugin::ConfigPolicy get_config_policy() override final;
183 std::vector<Plugin::Metric> get_metric_types(Plugin::Config cfg) override final;
190 void get_metrics_in(
std::vector<Plugin::Metric> &metsIn) override final;
195 void stream_metrics() override final;
198 void metricsContollerCollectedMetricsValues(const
MetroCollect::MetricsController& metricsController, const
MetroCollect::MetricsDiffArray& metricsDiff, const
MetroCollect::MetricsDataArray& previousMetrics, const
MetroCollect::MetricsDataArray& currentMetrics) override final;
199 void metricsContollerCollectedMetricsStats(const
MetroCollect::MetricsController& metricsController, const
MetroCollect::MetricsController::MetricsStats& metricsStats) override final;
200 bool metricsContollerShouldStopCollectingMetrics(const
MetroCollect::MetricsController& metricsController) override final;
208 int main(
int argc,
char* argv[]);
static constexpr std::chrono::milliseconds defaultSamplingInterval
Default parameter option.
static constexpr bool defaultConvertToUnitsPerSecond
Default parameter option.
Interface class between MetricsController and Snap's streaming-collector plugin class.
MetroCollect::MetricsArray< MetroCollect::Statistics::Stats > requestedMetrics_
Array of requested metrics.
MetroCollect::MetricsController metricsController_
MetricsController used to collect statistics.
static constexpr size_t defaultProcessingWindowLength
Default parameter option.
size_t unchangedMetricsTimeout_
Sub-sampling period for constant metrics.
std::vector< bool > secondaryMetrics
Array to mark the most important metric stat (average)
Strcut to store Snap metric objects and metric data to make it faster to send them to Snap...
int main(int argc, char *argv[])
MetroCollect's main function.
Stats
Bitwise type te select statistics.
std::vector< size_t > metricsTimeout
Sub-sampling counters for constant metrics.
std::vector< size_t * > metricsTimeoutPointer
Array to match metrics to their sub-sampling counter (one is shared for all statistics) ...
std::vector< Plugin::Metric * > metricsToSend
Array of pointers to Snap metrics to be sent.
std::vector< Plugin::Metric > computedMetrics
Cache for Snap metrics.
static constexpr size_t defaultProcessingWindowOverlap
Default parameter option.
Simple array of metrics with a timestamp.
std::unique_ptr< TimedMetrics > currentMetrics
Earlier values that may be sent.
void clear(size_t metricsCount)
Reinitializes the receiver and allocates space for metrics.
std::chrono::system_clock::time_point timestamp
Timestamp of the metrics.
MetricsPackage statsPackage_
MetricsPackage for metrics from computed statistics.
std::unique_ptr< TimedMetrics > nextMetrics
Latest values kept to be sent on the next iteration.
Abstract delegate of MetricsController.
std::vector< MetroCollect::DiffValueType > values
Array of metrics.
Class to control the collection of metrics.
MetricsPackage valuesPackage_
MetricsPackage for metrics from raw counters variations.