-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instrument producer_plugin for Prometheus #537
Changes from 10 commits
56a11f1
be41cdb
ae8eee9
40a0507
c7f9628
de6fe8c
0d5f7dd
525a454
b7bf037
bd01758
a1f8820
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -832,6 +832,10 @@ class read_write { | |
|
||
} // namespace chain_apis | ||
|
||
struct chain_plugin_metrics { | ||
//runtime_metric | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this will be cleaned up with the chain_plugin PR to the feature branch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, changes for that are coming in the instrument chain plugin pr |
||
}; | ||
|
||
class chain_plugin : public plugin<chain_plugin> { | ||
public: | ||
APPBASE_PLUGIN_REQUIRES() | ||
|
@@ -878,6 +882,8 @@ class chain_plugin : public plugin<chain_plugin> { | |
// return variant of trx for logging, trace is modified to minimize log output | ||
fc::variant get_log_trx(const transaction& trx) const; | ||
|
||
const chain_plugin_metrics& metrics() const; | ||
|
||
private: | ||
static void log_guard_exception(const chain::guard_exception& e); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,37 +61,73 @@ namespace eosio { | |
const prometheus::TextSerializer _serializer; | ||
std::shared_ptr<Registry> _registry; | ||
|
||
std::vector<std::tuple<Family<Gauge>&, Gauge&, runtime_metric&>> _runtime_metrics; | ||
|
||
std::vector<std::tuple<Family<Gauge>&, Gauge&, const runtime_metric&>> _gauges; | ||
std::vector<std::tuple<Family<Counter>&, Counter&, const runtime_metric&>> _counters; | ||
|
||
// metrics for prometheus_plugin itself | ||
std::unique_ptr<prometheus_plugin_metrics> _metrics; | ||
|
||
// hold onto other plugin metrics | ||
std::shared_ptr<net_plugin_metrics> net_plugin_metrics_ptr; | ||
|
||
prometheus_plugin_impl() { } | ||
|
||
void add_plugin_metric(runtime_metric& plugin_metric) { | ||
void add_gauge_metric(const runtime_metric& plugin_metric) { | ||
auto& gauge_family = BuildGauge() | ||
.Name(plugin_metric.family) | ||
.Help("") | ||
.Register(*_registry); | ||
auto& gauge = gauge_family.Add({}); | ||
_runtime_metrics.push_back(std::tuple<Family<Gauge>&, Gauge&, runtime_metric&>(gauge_family, gauge, plugin_metric)); | ||
ilog("Added metric ${f}:${l}", ("f", plugin_metric.family) ("l", plugin_metric.label)); | ||
|
||
_gauges.push_back( | ||
std::tuple<Family<Gauge>&, Gauge&, const runtime_metric&>(gauge_family, gauge, plugin_metric)); | ||
|
||
ilog("Added gauge metric ${f}:${l}", ("f", plugin_metric.family) ("l", plugin_metric.label)); | ||
} | ||
|
||
void add_plugin_metrics(std::shared_ptr<net_plugin_metrics> metrics) { | ||
add_plugin_metric(metrics->num_clients); | ||
add_plugin_metric(metrics->num_peers); | ||
add_plugin_metric(metrics->dropped_trxs); | ||
void add_counter_metric(const runtime_metric& plugin_metric) { | ||
auto &counter_family = BuildCounter() | ||
.Name(plugin_metric.family) | ||
.Help("") | ||
.Register(*_registry); | ||
auto &counter = counter_family.Add({}); | ||
_counters.push_back( | ||
std::tuple<Family<Counter>&, Counter&, const runtime_metric&>(counter_family, counter, plugin_metric)); | ||
|
||
ilog("Added counter metric ${f}:${l}", ("f", plugin_metric.family) ("l", plugin_metric.label)); | ||
} | ||
|
||
void add_plugin_metric(const runtime_metric& plugin_metric) { | ||
switch(plugin_metric.type) { | ||
case metric_type::gauge: | ||
add_gauge_metric(plugin_metric); | ||
break; | ||
case metric_type::counter: | ||
add_counter_metric(plugin_metric); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
template <typename T> | ||
void add_plugin_metrics(T& pm) { | ||
pm.enable(true); | ||
for (const auto& m : pm.metrics) { | ||
add_plugin_metric(m); | ||
} | ||
} | ||
|
||
void update_plugin_metrics() { | ||
for (auto& rtm : _runtime_metrics) { | ||
for (auto& rtm : _gauges) { | ||
auto new_val = static_cast<double>(std::get<2>(rtm).value); | ||
std::get<1>(rtm).Set(new_val); | ||
} | ||
|
||
for (auto& rtm : _counters) { | ||
auto new_val = static_cast<double>(std::get<2>(rtm).value); | ||
std::get<1>(rtm).Increment(new_val-std::get<1>(rtm).Value()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you decide this was not needed? |
||
} | ||
} | ||
|
||
void initialize_metrics() { | ||
|
@@ -103,11 +139,17 @@ namespace eosio { | |
|
||
net_plugin* np = app().find_plugin<net_plugin>(); | ||
if (nullptr != np) { | ||
net_plugin_metrics_ptr = np->metrics(); | ||
add_plugin_metrics(net_plugin_metrics_ptr); | ||
add_plugin_metrics<net_plugin_metrics>(np->metrics()); | ||
} else { | ||
dlog("net_plugin not found -- metrics not added"); | ||
} | ||
|
||
producer_plugin* pp = app().find_plugin<producer_plugin>(); | ||
if (nullptr != pp) { | ||
add_plugin_metrics<producer_plugin_metrics>(pp->metrics()); | ||
} else { | ||
dlog("producer_plugin not found -- metrics not added"); | ||
} | ||
} | ||
|
||
std::string scrape() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be initialized.