From e577ed8459372199e0ec20e3918c515f90df1a8a Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Mon, 27 Jul 2015 16:43:53 +0300 Subject: [PATCH] row_cache: wire up collectd statistics --- row_cache.cc | 31 +++++++++++++++++++++++++++++-- row_cache.hh | 12 ++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/row_cache.cc b/row_cache.cc index 4a561cc6ed..a2e117da48 100644 --- a/row_cache.cc +++ b/row_cache.cc @@ -6,6 +6,7 @@ #include "core/memory.hh" #include "core/do_with.hh" #include "core/future-util.hh" +#include static logging::logger logger("cache"); @@ -21,23 +22,49 @@ cache_tracker::cache_tracker() // compacting memory allocator to avoid problems with memory // fragmentation. clear(); - }) -{ } + }) { + setup_collectd(); +} cache_tracker::~cache_tracker() { clear(); } +void +cache_tracker::setup_collectd() { + _collectd_registrations = std::make_unique(scollectd::registrations({ + scollectd::add_polled_metric(scollectd::type_instance_id("cache" + , scollectd::per_cpu_plugin_instance + , "queue_length", "total_rows") + , scollectd::make_typed(scollectd::data_type::GAUGE, _lru_len) + ), + scollectd::add_polled_metric(scollectd::type_instance_id("cache" + , scollectd::per_cpu_plugin_instance + , "total_operations", "hits") + , scollectd::make_typed(scollectd::data_type::DERIVE, _hits) + ), + scollectd::add_polled_metric(scollectd::type_instance_id("cache" + , scollectd::per_cpu_plugin_instance + , "total_operations", "misses") + , scollectd::make_typed(scollectd::data_type::DERIVE, _misses) + ), + })); +} + void cache_tracker::clear() { + _lru_len = 0; _lru.clear_and_dispose(std::default_delete()); } void cache_tracker::touch(cache_entry& e) { + ++_hits; _lru.erase(_lru.iterator_to(e)); _lru.push_front(e); } void cache_tracker::insert(cache_entry& entry) { + ++_misses; + ++_lru_len; _lru.push_front(entry); } diff --git a/row_cache.hh b/row_cache.hh index 5574f6f80e..2ca2b0b93d 100644 --- a/row_cache.hh +++ b/row_cache.hh @@ -12,6 +12,12 @@ #include "mutation_reader.hh" #include "mutation_partition.hh" +namespace scollectd { + +struct registrations; + +} + namespace bi = boost::intrusive; // Intrusive set entry which holds partition data. @@ -71,7 +77,13 @@ class cache_tracker final { bi::member_hook, bi::constant_time_size // we need this to have bi::auto_unlink on hooks. > _lru; + size_t _lru_len = 0; + uint64_t _hits = 0; + uint64_t _misses = 0; memory::reclaimer _reclaimer; + std::unique_ptr _collectd_registrations; +private: + void setup_collectd(); public: cache_tracker(); ~cache_tracker();