From a8fc4165c887c9bf5ac9662254b5cfa38a8a4592 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Je=C5=BEek?= Date: Fri, 24 Jul 2020 11:00:41 +0200 Subject: [PATCH] cache: add number of entries to cache.stats() --- NEWS | 1 + daemon/bindings/cache.c | 2 ++ daemon/bindings/cache.rst | 26 +++++++++++++++----------- daemon/lua/kres-gen.lua | 1 + lib/cache/cdb_api.h | 1 + 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index 1eb4da5d4..0dc56dfdd 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ Improvements ------------ - capabilities are no longer constrained when running as root (!1012) - cache: add percentage usage to cache.stats() (!1025) +- cache: add number of cache entries to cache.stats() (!1028) - aarch64 support again, as some systems still didn't work (!1033) Bugfixes diff --git a/daemon/bindings/cache.c b/daemon/bindings/cache.c index d2d37f24b..94f8f9b34 100644 --- a/daemon/bindings/cache.c +++ b/daemon/bindings/cache.c @@ -81,6 +81,8 @@ static int cache_stats(lua_State *L) add_stat(open); add_stat(close); add_stat(count); + cache->stats.count_entries = cache->api->count(cache->db, &cache->stats); + add_stat(count_entries); add_stat(clear); add_stat(commit); add_stat(read); diff --git a/daemon/bindings/cache.rst b/daemon/bindings/cache.rst index 73f2e089e..e295d2243 100644 --- a/daemon/bindings/cache.rst +++ b/daemon/bindings/cache.rst @@ -186,7 +186,7 @@ Configuration reference .. function:: cache.stats() - Return table with low-level statistics for each internal cache operation. + Return table with low-level statistics for internal cache operation and storage. This counts each access to cache and does not directly map to individual DNS queries or resource records. For query-level statistics see :ref:`stats module `. @@ -196,23 +196,27 @@ Configuration reference .. code-block:: lua > cache.stats() - [read_leq_miss] => 4 - [write] => 189 - [read_leq] => 9 - [read] => 4313 - [read_miss] => 1143 - [open] => 0 + [clear] => 0 [close] => 0 - [remove_miss] => 0 [commit] => 117 - [match_miss] => 2 - [match] => 21 [count] => 2 - [clear] => 0 + [count_entries] => 6187 + [match] => 21 + [match_miss] => 2 + [open] => 0 + [read] => 4313 + [read_leq] => 9 + [read_leq_miss] => 4 + [read_miss] => 1143 [remove] => 17 + [remove_miss] => 0 + [usage_percent] => 15.625 + [write] => 189 + Cache operation `read_leq` (*read less or equal*, i.e. range search) was requested 9 times, and 4 out of 9 operations were finished with *cache miss*. + Cache contains 6187 internal entries which occupy 15.625 % cache size. .. function:: cache.max_ttl([ttl]) diff --git a/daemon/lua/kres-gen.lua b/daemon/lua/kres-gen.lua index 8d02db78e..d22e82527 100644 --- a/daemon/lua/kres-gen.lua +++ b/daemon/lua/kres-gen.lua @@ -199,6 +199,7 @@ struct kr_cdb_stats { uint64_t open; uint64_t close; uint64_t count; + uint64_t count_entries; uint64_t clear; uint64_t commit; uint64_t read; diff --git a/lib/cache/cdb_api.h b/lib/cache/cdb_api.h index c04cce533..9cb784b9c 100644 --- a/lib/cache/cdb_api.h +++ b/lib/cache/cdb_api.h @@ -18,6 +18,7 @@ struct kr_cdb_stats { uint64_t open; uint64_t close; uint64_t count; + uint64_t count_entries; uint64_t clear; uint64_t commit; uint64_t read; -- 2.47.2