29 SnapStreamInterface::SnapStreamInterface() :
30 metricsController_(*this)
77 for (
const auto& metric : metrics) {
80 fieldName.push_back(metric.ns()[i].get_value());
81 auto fieldIndexes = this->requestedMetrics_.indexesOfFieldName(fieldName);
83 for (
size_t i : fieldIndexes)
97 bool isSecondaryMetric =
false;
102 fieldInfo.name.push_back(suffix);
103 Plugin::Namespace ns(fieldInfo.name);
104 for (
const auto& dynamicIndex: fieldInfo.dynamicIndexes)
128 bool shouldSend =
true;
131 package.
currentMetrics = std::make_unique<MetricsPackage::TimedMetrics>();
173 Plugin::ConfigPolicy policy;
174 std::vector<std::string> ns;
175 std::vector<std::string> baseNamespace;
191 std::vector<Plugin::Metric> metrics;
195 for (
auto& fieldInfo : fieldsInfo) {
197 Plugin::Namespace ns{fieldInfo.name};
198 for (
const auto& dynamicIndex: fieldInfo.dynamicIndexes)
202 metrics.emplace_back(ns, fieldInfo.unit, fieldInfo.description);
216 if (metsIn.size() == 0)
219 this->
setConfig(metsIn.front().get_config());
226 *isSecondaryMetric =
false;
250 array.
values[index] = metricsDiff[metricIndex];
261 for (
const auto& val : statsMetrics.indexedValues()) {
262 array.
values[index] = val.value;
270 return this->context_cancelled();
275 int main(
int argc,
char* argv[]) {
277 meta.concurrency_count = 1;
278 meta.exclusive =
false;
279 meta.strategy = Plugin::Strategy::Sticky;
280 meta.cache_ttl = 1ms;
282 Plugin::start_stream_collector(argc, argv, &plugin, meta);
MetricsSource::SourceInterests sourceInterests() const noexcept
Returns the source interests.
static constexpr std::string_view configKeyConvertToUnitsPerSecond
Snap plugin configuration key.
static constexpr std::chrono::milliseconds defaultSamplingInterval
Default parameter option.
static constexpr bool defaultConvertToUnitsPerSecond
Default parameter option.
Struct to store all final metric stats.
std::vector< Plugin::Metric > get_metric_types(Plugin::Config cfg) override final
Returns all metrics that can be fetched by the plugin to Snap.
const std::chrono::system_clock::time_point & endTime() const noexcept
Get time of latest metrics.
void setConfig(const Plugin::Config &cfg)
Configures the plugin and the controller accordingly, unspecified values are reset to default...
void setRequestedMetrics(const MetricsArray< Statistics::Stats > &requestedMetrics) noexcept
Sets the list of request metrics.
Interface class between MetricsController and Snap's streaming-collector plugin class.
MetroCollect::MetricsArray< MetroCollect::Statistics::Stats > requestedMetrics_
Array of requested metrics.
std::vector< std::string > FieldName
Type used for field names (an array of strings)
static constexpr std::array configKeysBool
Array of boolean-valued configuration keys.
static constexpr std::array appPrefix
Snap metric name prefix.
MetroCollect::MetricsController metricsController_
MetricsController used to collect statistics.
static constexpr size_t defaultProcessingWindowLength
Default parameter option.
static constexpr std::string_view statNamespaceDescription
Snap metric name description.
static constexpr std::array< int, configKeysInt.size()> configValuesInt
Array of integer-valued configuration default values.
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...
static constexpr std::string_view configKeyProcessingWindowOverlap
Snap plugin configuration key.
bool sendValues() const noexcept
Returns whether the controller alerts the delegate after collecting new values.
static Stats statsRequiredForStat(Stats stat)
Returns the stats which are required to compute this stat.
static constexpr bool defaultSendStats
Snap plugin configuration default value.
static constexpr size_t defaultUnchangedMetricTimeout
Snap plugin configuration default value.
static constexpr std::string_view statNamespaceLastComponent
Snap metric name category.
Stats
Bitwise type te select statistics.
void setSamplingInterval(std::chrono::milliseconds interval) noexcept
Sets the metrics sampling interval.
void setSendStats(bool sendStats) noexcept
Sets whether the controller alerts the delegate after computing statistics.
const std::chrono::system_clock::time_point & endTime() const noexcept
Get time of latest metrics.
void collectMetrics()
Launch metric collection loop.
void setConvertToUnitsPerSeconds(bool convertToUnitsPerSecond) noexcept
Sets whether to convert metric differences to units per second.
void stream_metrics() override final
Stream metrics to Snap.
void get_metrics_in(std::vector< Plugin::Metric > &metsIn) override final
Gets the user's requested metrics from Snap.
const std::vector< size_t > & requestedMetrics() const noexcept
Returns the list of request metrics.
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) ...
static constexpr std::string_view configKeySendStats
Snap plugin configuration key.
static constexpr std::string_view configKeySendValues
Snap plugin configuration key.
std::vector< Plugin::Metric * > metricsToSend
Array of pointers to Snap metrics to be sent.
static constexpr size_t count
Number of available statistics.
int main(int argc, char *argv[])
MetroCollect's main function.
static constexpr std::array< Stats, count > allStats
Array of all available statistics.
void sendMetrics(MetricsPackage &package, std::function< void(MetricsPackage::TimedMetrics &)> copyMetrics)
Filters and sends metrics form a package to Snap.
std::vector< Plugin::Metric > computedMetrics
Cache for Snap metrics.
static constexpr std::array configKeysInt
Array of integer-valued configuration keys.
void metricsContollerCollectedMetricsStats(const MetroCollect::MetricsController &metricsController, const MetroCollect::MetricsController::MetricsStats &metricsStats) override final
Function called every time the MetricsController has computed statistics.
void createRequestedMetrics(MetricsPackage &package, std::string suffix, std::function< bool(MetroCollect::Statistics::Stats, bool *)> condition)
Configures a MetricsPackage object according to requested metrics.
static constexpr size_t defaultProcessingWindowOverlap
Default parameter option.
void forEach(Function func)
Execute a function for each stats array.
static constexpr std::string_view appName
Snap plugin name.
static constexpr std::string_view configKeyProcessingWindowLength
Snap plugin configuration key.
void parseSnapMetrics(const std::vector< Plugin::Metric > &metrics)
Generate requestedMetrics array from list of Snap metrics.
Simple array of metrics with a timestamp.
void setProcessingWindow(size_t length, size_t overlap) noexcept
Sets the processing window parameters used to compute statistics.
const MetricsSource::FieldInfo fieldInfoAtIndex(size_t index) const noexcept
Get details about a specific metric field.
static Stats statsFromName(const std::string_view &statName)
Convert a stat name to a stat value.
Class to fetch metrics from the kernel and store them.
bool sendStats() const noexcept
Returns whether the controller alerts the delegate after computing statistics.
const Plugin::ConfigPolicy get_config_policy() override final
Returns the plugin configuration keys and default values to Snap.
const std::vector< MetricsSource::FieldInfo > allFieldsInfo() const noexcept
Get details about all fields.
std::unique_ptr< TimedMetrics > currentMetrics
Earlier values that may be sent.
void setSendValues(bool sendValues) noexcept
Sets whether the controller alerts the delegate after collecting new values.
static constexpr bool defaultSendValues
Snap plugin configuration default value.
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.
static constexpr std::array< std::string_view, count > names
Names of available statistics.
void fillMetricsPackage(MetricsPackage &package)
Initializes a MetricsPackage sub-sampling counters.
void insertAppPrefixToNamespace(std::vector< std::string > &ns)
Inserts plugin name prefix into Snap namespace.
bool metricsContollerShouldStopCollectingMetrics(const MetroCollect::MetricsController &metricsController) override final
Function called after each iteration to ask the delegate whether the controller should stop collectin...
std::vector< MetroCollect::DiffValueType > values
Array of metrics.
MetricsStatsArray< DiffValueType > min
Array of minimums.
Class to control the collection of metrics.
static constexpr std::string_view configKeyUnchangedMetricTimeout
Snap plugin configuration key.
Class to compute and store metric values variations.
static constexpr std::array< bool, configKeysBool.size()> configValuesBool
Array of boolean-valued configuration default values.
MetricsPackage valuesPackage_
MetricsPackage for metrics from raw counters variations.
size_t size() const noexcept
Returns the size of the underlying array.
static constexpr int appVersion
Snap plugin version.
static constexpr std::string_view configKeySamplingInterval
Snap plugin configuration key.
void metricsContollerCollectedMetricsValues(const MetroCollect::MetricsController &metricsController, const MetroCollect::MetricsDiffArray &metricsDiff, const MetroCollect::MetricsDataArray &previousMetrics, const MetroCollect::MetricsDataArray ¤tMetrics) override final
Function called every time the MetricsController has collected new values.