row_cache: wire up collectd statistics

This commit is contained in:
Avi Kivity
2015-07-27 16:43:53 +03:00
committed by Tomasz Grabiec
parent 225cbf0ed3
commit e577ed8459
2 changed files with 41 additions and 2 deletions

View File

@@ -6,6 +6,7 @@
#include "core/memory.hh"
#include "core/do_with.hh"
#include "core/future-util.hh"
#include <seastar/core/scollectd.hh>
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::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<cache_entry>());
}
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);
}

View File

@@ -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<cache_entry, cache_entry::lru_link_type, &cache_entry::_lru_link>,
bi::constant_time_size<false> // 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<scollectd::registrations> _collectd_registrations;
private:
void setup_collectd();
public:
cache_tracker();
~cache_tracker();