diff options
author | Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> | 2022-09-14 19:22:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-14 19:22:25 +0300 |
commit | 466b1fcc56d3dc4787f332d76db0623f5dad9f91 (patch) | |
tree | 7f87c0ef8da991d3568d64083dccfe782de20d01 /daemon/global_statistics.c | |
parent | c93e585f38be8ca388fe7dff0cafb284ed9f831e (diff) |
Add sqlite page cache hit and miss statistics (#13665)
* Add sqlite page cache hit/ miss statistics
* Proper function definition
Co-authored-by: Vladimir Kobal <vlad@prokk.net>
* Proper function calls
Co-authored-by: Vladimir Kobal <vlad@prokk.net>
Co-authored-by: Vladimir Kobal <vlad@prokk.net>
Diffstat (limited to 'daemon/global_statistics.c')
-rw-r--r-- | daemon/global_statistics.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/daemon/global_statistics.c b/daemon/global_statistics.c index 49c32d119d..2f0de3d9d5 100644 --- a/daemon/global_statistics.c +++ b/daemon/global_statistics.c @@ -38,6 +38,8 @@ static struct global_statistics { volatile uint64_t sqlite3_queries_failed_busy; volatile uint64_t sqlite3_queries_failed_locked; volatile uint64_t sqlite3_rows; + volatile uint64_t sqlite3_cache_hit; + volatile uint64_t sqlite3_cache_miss; } global_statistics = { .connected_clients = 0, @@ -134,6 +136,11 @@ static inline void global_statistics_copy(struct global_statistics *gs, uint8_t gs->sqlite3_queries_failed_busy = __atomic_load_n(&global_statistics.sqlite3_queries_failed_busy, __ATOMIC_RELAXED); gs->sqlite3_queries_failed_locked = __atomic_load_n(&global_statistics.sqlite3_queries_failed_locked, __ATOMIC_RELAXED); gs->sqlite3_rows = __atomic_load_n(&global_statistics.sqlite3_rows, __ATOMIC_RELAXED); + + gs->sqlite3_cache_hit = (uint64_t) sql_context_cache_stats(SQLITE_DBSTATUS_CACHE_HIT); + gs->sqlite3_cache_hit += (uint64_t) sql_metadata_cache_stats(SQLITE_DBSTATUS_CACHE_HIT); + gs->sqlite3_cache_miss = (uint64_t) sql_context_cache_stats(SQLITE_DBSTATUS_CACHE_MISS); + gs->sqlite3_cache_miss += (uint64_t) sql_metadata_cache_stats(SQLITE_DBSTATUS_CACHE_MISS); } static void global_statistics_charts(void) { @@ -581,6 +588,39 @@ static void global_statistics_charts(void) { rrdset_done(st_sqlite3_rows); } + if(gs.sqlite3_cache_hit) { + static RRDSET *st_sqlite3_cache = NULL; + static RRDDIM *rd_cache_hit = NULL; + static RRDDIM *rd_cache_miss= NULL; + + if (unlikely(!st_sqlite3_cache)) { + st_sqlite3_cache = rrdset_create_localhost( + "netdata" + , "sqlite3_cache" + , NULL + , "sqlite3" + , NULL + , "Netdata SQLite3 Cache" + , "ops/s" + , "netdata" + , "stats" + , 131103 + , localhost->rrd_update_every + , RRDSET_TYPE_LINE + ); + + rd_cache_hit = rrddim_add(st_sqlite3_cache, "cache_hit", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); + rd_cache_miss = rrddim_add(st_sqlite3_cache, "cache_miss", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); + } + else + rrdset_next(st_sqlite3_cache); + + rrddim_set_by_pointer(st_sqlite3_cache, rd_cache_hit, (collected_number)gs.sqlite3_cache_hit); + rrddim_set_by_pointer(st_sqlite3_cache, rd_cache_miss, (collected_number)gs.sqlite3_cache_miss); + + rrdset_done(st_sqlite3_cache); + } + // ---------------------------------------------------------------- } |