@@ -1724,6 +1724,22 @@ void PrintPrometheusMetrics(uint64_t uptime, const Metrics& m, DflyCmd* dfly_cmd
1724
1724
&resp->body ());
1725
1725
AppendMetricWithoutLabels (" evicted_keys_total" , " " , m.events .evicted_keys , MetricType::COUNTER,
1726
1726
&resp->body ());
1727
+ // Per-DB expired/evicted totals
1728
+ {
1729
+ string perdb_str;
1730
+ AppendMetricHeader (" expired_keys_total" , " " , MetricType::COUNTER, &perdb_str);
1731
+ AppendMetricHeader (" evicted_keys_total" , " " , MetricType::COUNTER, &perdb_str);
1732
+ for (size_t i = 0 ; i < m.db_stats .size (); ++i) {
1733
+ const auto & s = m.db_stats [i];
1734
+ if (s.events .expired_keys > 0 )
1735
+ AppendMetricValue (" expired_keys_total" , s.events .expired_keys , {" db" }, {StrCat (" db" , i)},
1736
+ &perdb_str);
1737
+ if (s.events .evicted_keys > 0 )
1738
+ AppendMetricValue (" evicted_keys_total" , s.events .evicted_keys , {" db" }, {StrCat (" db" , i)},
1739
+ &perdb_str);
1740
+ }
1741
+ absl::StrAppend (&resp->body (), perdb_str);
1742
+ }
1727
1743
// Memory stats
1728
1744
if (legacy) {
1729
1745
AppendMetricWithoutLabels (" memory_fiberstack_vms_bytes" ,
@@ -1915,6 +1931,11 @@ void PrintPrometheusMetrics(uint64_t uptime, const Metrics& m, DflyCmd* dfly_cmd
1915
1931
1916
1932
AppendMetricValue (" db_keys_expiring" , m.db_stats [i].expire_count , {" db" }, {StrCat (" db" , i)},
1917
1933
&db_key_expire_metrics);
1934
+
1935
+ AppendMetricValue (" keyspace_hits_total" , m.db_stats [i].events .hits , {" db" }, {StrCat (" db" , i)},
1936
+ &resp->body ());
1937
+ AppendMetricValue (" keyspace_misses_total" , m.db_stats [i].events .misses , {" db" },
1938
+ {StrCat (" db" , i)}, &resp->body ());
1918
1939
}
1919
1940
1920
1941
absl::StrAppend (&resp->body (), db_key_metrics, db_key_expire_metrics, db_capacity_metrics,
@@ -2644,7 +2665,8 @@ void ServerFamily::ResetStat(Namespace* ns) {
2644
2665
registry->ResetCallStats (index);
2645
2666
EngineShard* shard = EngineShard::tlocal ();
2646
2667
if (shard) {
2647
- ns->GetDbSlice (shard->shard_id ()).ResetEvents ();
2668
+ auto & db_slice = ns->GetDbSlice (shard->shard_id ());
2669
+ db_slice.ResetEvents ();
2648
2670
}
2649
2671
facade::ResetStats ();
2650
2672
ServerState::tlocal ()->exec_freq_count .clear ();
@@ -3244,7 +3266,12 @@ string ServerFamily::FormatInfoMetrics(const Metrics& m, std::string_view sectio
3244
3266
const auto & stats = m.db_stats [i];
3245
3267
bool show = (i == 0 ) || (stats.key_count > 0 );
3246
3268
if (show) {
3269
+ size_t total = stats.events .hits + stats.events .misses ;
3270
+ double hit_ratio =
3271
+ (total > 0 ) ? static_cast <double >(stats.events .hits ) / (total)*100.0 : 0.0 ;
3247
3272
string val = StrCat (" keys=" , stats.key_count , " ,expires=" , stats.expire_count ,
3273
+ " ,hits=" , stats.events .hits , " ,misses=" , stats.events .misses ,
3274
+ " ,hit_ratio=" , absl::StrFormat (" %.2f" , hit_ratio),
3248
3275
" ,avg_ttl=-1" ); // TODO
3249
3276
append (StrCat (" db" , i), val);
3250
3277
}
0 commit comments