31 sendAllMetrics_(false)
37 return std::string(s);
43 std::string configPath;
59 for (
auto& part : name) {
60 bool wasCapitalized =
false;
61 for (
size_t i = 0; i < part.size(); i++) {
62 if (!std::isalnum(part[i]) && part[i] !=
'_') {
63 if (i > 0 && part[i - 1] !=
'_') {
70 else if (std::isupper(part[i])) {
71 if (i > 0 && part[i - 1] !=
'_' && std::islower(part[i - 1]) && !wasCapitalized) {
75 part[i] = std::tolower(part[i]);
76 wasCapitalized =
true;
78 wasCapitalized =
false;
80 while (part.back() ==
'_')
81 part.erase(part.size() - 1, 1);
82 while (part.front() ==
'_')
89 std::vector<std::string> name = m.
name();
91 for (
const auto& n : name)
98 for (
size_t i = 2; i < m.ns().size(); i++)
99 nameHash.append(m.ns()[i].get_value());
104 std::vector<std::string> name = metric.
name();
107 Plugin::Namespace ns{name};
108 Plugin::Metric snapMetric{ns, metric.
unit(),
""};
109 for (
const auto& tag : metric.
tags())
110 snapMetric.add_tag(tag);
111 snapMetric.set_data(metric.
value());
112 snapMetric.set_timestamp(metric.
timestamp());
118 Plugin::ConfigPolicy policy;
119 std::vector<std::string> ns;
120 std::vector<std::string> baseNamespace;
141 std::vector<Plugin::Metric> metrics;
145 for (
auto& m : availableMetrics)
150 Plugin::Namespace ns{name};
151 metrics.emplace_back(ns,
"",
"");
157 if (metsIn.size() == 0)
160 this->
setConfig(metsIn.front().get_config());
163 for (
const auto& m : metsIn) {
173 for (
const auto& m : availableMetrics) {
192 for (
const auto& metric : metrics) {
193 auto itr = this->
metrics_.find(metric->key());
195 itr->second.set_data(metric->value());
196 itr->second.set_timestamp(metric->timestamp());
217 return this->context_cancelled();
222 int main(
int argc,
char* argv[]) {
224 meta.concurrency_count = 1;
225 meta.exclusive =
false;
226 meta.strategy = Plugin::Strategy::Sticky;
227 meta.cache_ttl = 1ms;
229 Plugin::start_stream_collector(argc, argv, &plugin, meta);
std::vector< Plugin::Metric > get_metric_types(Plugin::Config cfg) override final
Returns all metrics that can be fetched by the plugin to Snap.
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.
static constexpr bool defaultSendAllMetrics
Snap plugin configuration default value.
const Plugin::ConfigPolicy get_config_policy() override final
Returns the plugin configuration keys and default values to Snap.
void setSamplingInterval(std::chrono::seconds interval) noexcept
Sets the metrics sampling interval.
void contollerCollectedMetrics(const Controller &controller, const std::vector< const Metric *> &metrics) override final
Function called every time the Controller has collected metrics.
static constexpr std::chrono::seconds defaultSamplingInterval
Default parameter option.
static constexpr std::array< int, configKeysBool.size()> configValuesBool
Array of boolean-valued configuration default values.
const std::string & unit() const noexcept
Returns the unit of the metric.
std::set< size_t > unwantedMetrics_
Array of keys of non requested metrics.
const std::vector< std::string > & name() const noexcept
Returns the name of the metric.
std::map< size_t, Plugin::Metric > metrics_
Map associating keys to their metric.
static constexpr std::array configKeysInt
Array of integer-valued configuration keys.
static std::hash< std::string > hasher
Object used to compute keys (string hashes)
void stream_metrics() override final
Stream metrics to Snap.
void insertAppPrefixToNamespace(std::vector< std::string > &ns)
Inserts plugin name prefix into Snap namespace.
SnapInterface()
Construct a new Snap Interface object.
void formatName(std::vector< std::string > &name)
Formats a metric name to be compatible with Snap requirements.
std::chrono::system_clock::time_point timestamp() const noexcept
Returns the timestamp of the metric.
static constexpr std::string_view appName
Snap plugin name.
AnyCollect::Controller controller_
Controller used to collect statistics.
bool contollerShouldStopCollectingMetrics(const Controller &controller) override final
Function called after each iteration to ask the delegate whether the controller should stop collectin...
std::vector< Plugin::Metric * > metricsToSend_
Array of pointers to Snap metrics to be sent.
void collectMetrics() noexcept
Launch metric collection loop.
const std::map< std::string, std::string > & tags() const noexcept
Returns the tags of the metric.
void get_metrics_in(std::vector< Plugin::Metric > &metsIn) override final
Gets the user's requested metrics from Snap.
static constexpr std::array< int, configKeysInt.size()> configValuesInt
Array of integer-valued configuration default values.
static constexpr std::string_view configKeySamplingInterval
Snap plugin configuration key.
size_t computeNameKey(const Metric &m)
Computes a key based solely on a metric's name.
Class used to represent a metric object (with a name, unit, tags, a value and a timestamp) ...
std::set< size_t > requestedMetrics_
Array of keys of requested metrics.
Plugin::Metric convertToSnapMetric(const Metric &metric)
Converts a metric object into a Snap metric object.
void setConfig(const Plugin::Config &cfg)
Configures the plugin and the controller accordingly, unspecified values are reset to default...
std::vector< const Metric * > availableMetrics() noexcept
Returns the array of all currently matching metrics on the system, without their values.
bool sendAllMetrics_
Whether to send all metrics, regardless of which are requested.
static constexpr int appVersion
Snap plugin version.
double value() const noexcept
Returns the value of the metric.
static constexpr std::array appPrefix
Snap metric name prefix.
static constexpr std::string_view configKeyConfigFile
Snap plugin configuration key.
static constexpr std::string_view configKeySendAllMetrics
Snap plugin configuration key.
static constexpr std::array configKeysBool
Array of boolean-valued configuration keys.