#include <seastar/core/metrics.hh>
#include <seastar/core/metrics_api.hh>
+#include <seastar/core/reactor.hh>
#include <boost/range/algorithm.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/replace.hpp>
}
label shard_label("shard");
-label type_label("type");
namespace impl {
registered_metric::registered_metric(metric_id id, metric_function f, bool enabled) :
metric_value res(*this);
switch (_type) {
case data_type::HISTOGRAM:
- compat::get<histogram>(res.u) += compat::get<histogram>(c.u);
+ std::get<histogram>(res.u) += std::get<histogram>(c.u);
break;
default:
- compat::get<double>(res.u) += compat::get<double>(c.u);
+ std::get<double>(res.u) += std::get<double>(c.u);
break;
}
return res;
if (labels.find(shard_label.name()) == labels.end()) {
labels[shard_label.name()] = shard();
}
- if (labels.find(type_label.name()) == labels.end()) {
- labels[type_label.name()] = type.type_name;
- }
}
metric_definition_impl& metric_definition_impl::operator ()(bool _enabled) {
return *this;
}
+metric_definition_impl& metric_definition_impl::set_type(const sstring& type_name) {
+ type.type_name = type_name;
+ return *this;
+}
+
std::unique_ptr<metric_groups_def> create_metric_groups() {
return std::make_unique<metric_groups_impl>();
}
metric_id id(name, md._impl->name, md._impl->labels);
- get_local_impl()->add_registration(id, md._impl->type.base_type, md._impl->f, md._impl->d, md._impl->enabled);
+ get_local_impl()->add_registration(id, md._impl->type, md._impl->f, md._impl->d, md._impl->enabled);
_registration.push_back(id);
return *this;
instance_id_type shard() {
if (engine_is_ready()) {
- return to_sstring(engine().cpu_id());
+ return to_sstring(this_shard_id());
}
return sstring("0");
return _current_metrics;
}
-void impl::add_registration(const metric_id& id, data_type type, metric_function f, const description& d, bool enabled) {
+void impl::add_registration(const metric_id& id, const metric_type& type, metric_function f, const description& d, bool enabled) {
auto rm = ::seastar::make_shared<registered_metric>(id, f, enabled);
sstring name = id.full_name();
if (_value_map.find(name) != _value_map.end()) {
if (metric.find(id.labels()) != metric.end()) {
throw double_registration("registering metrics twice for metrics: " + name);
}
- if (metric.info().type != type) {
+ if (metric.info().type != type.base_type) {
throw std::runtime_error("registering metrics " + name + " registered with different type.");
}
metric[id.labels()] = rm;
} else {
- _value_map[name].info().type = type;
+ _value_map[name].info().type = type.base_type;
_value_map[name].info().d = d;
+ _value_map[name].info().inherit_type = type.type_name;
_value_map[name].info().name = id.full_name();
_value_map[name][id.labels()] = rm;
}