Skip to content

Commit

Permalink
scollectd: Allow creating metric that is disabled
Browse files Browse the repository at this point in the history
There are cases (specifically smp) that metrics are better be
unpublished by default.

To support that a varienet of the collectd helper function was added:
add_disabled_polled_metric.

Metrics that are created with this function will be disabled until they
would be set explicitly.

The add_polled helper function now gets an optional enabled param
(default to true) that state if the metrics is enable or disable.

Signed-off-by: Amnon Heiman <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
amnonh authored and avikivity committed Jul 20, 2016
1 parent 7f8ac4d commit a8392ea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/scollectd-impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public:
typedef value_list_map::value_type value_list_pair;

void add_polled(const type_instance_id & id,
const shared_ptr<value_list> & values);
const shared_ptr<value_list> & values, bool enable = true);
void remove_polled(const type_instance_id & id);
// explicitly send a type_instance value list (outside polling)
future<> send_metric(const type_instance_id & id,
Expand Down
8 changes: 5 additions & 3 deletions core/scollectd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ impl::value_list_map& impl::get_value_list_map() {
}

void impl::add_polled(const type_instance_id & id,
const shared_ptr<value_list> & values) {
const shared_ptr<value_list> & values, bool enable) {
values->set_enabled(enable);
_values[id] = values;

}

void impl::remove_polled(const type_instance_id & id) {
Expand Down Expand Up @@ -401,8 +403,8 @@ std::vector<type_instance_id> impl::get_instance_ids() {
}

void add_polled(const type_instance_id & id,
const shared_ptr<value_list> & values) {
get_impl().add_polled(id, values);
const shared_ptr<value_list> & values, bool enabled) {
get_impl().add_polled(id, values, enabled);
}

void remove_polled_metric(const type_instance_id & id) {
Expand Down
13 changes: 12 additions & 1 deletion core/scollectd.hh
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ private:
std::tuple < Args... > _values;
};

void add_polled(const type_instance_id &, const shared_ptr<value_list> &);
void add_polled(const type_instance_id &, const shared_ptr<value_list> &, bool enabled = true);

typedef std::function<void()> notify_function;
template<typename... _Args>
Expand Down Expand Up @@ -454,6 +454,17 @@ static type_instance_id add_polled_metric(const type_instance_id & id,
make_type_instance(std::forward<_Args>(args)...)));
return id;
}

template<typename ... _Args>
static type_instance_id add_disabled_polled_metric(const type_instance_id & id,
_Args&& ... args) {
typedef decltype(make_type_instance(std::forward<_Args>(args)...)) impl_type;
add_polled(id,
::make_shared<impl_type>(
make_type_instance(std::forward<_Args>(args)...)), false);
return id;
}

// "Explicit" metric sends. Sends a single value list as a message.
// Obviously not super efficient either. But maybe someone needs it sometime.
template<typename ... _Args>
Expand Down

0 comments on commit a8392ea

Please sign in to comment.