
:guide-id: metrics-for-troubleshooting-cache
:guide-parent: 
:guide-title: Local caching metrics
:guide-summary: Use metrics to monitor health for local caching.
:guide-priority: 999
:guide-tile-visible: false
:version: 26.4.0

include::../attributes.adoc[]

[[metrics-for-troubleshooting-cache]]
= Local caching metrics

ifeval::["" == "true"]
WARNING: This {section} is describing a feature which is currently in preview.
ifeval::["" == ""]
Please provide your feedback while we’re continuing to work on this.
endif::[]
ifeval::["" != ""]
Please provide your feedback by link:[joining this discussion] while we’re continuing to work on this.
endif::[]
endif::[]


====
*Global tags*

`cache=<name>`:: The cache name.
====

== Size

Monitor the number of entries in your local cache.

|===
|Metric |Description

m| cache_size
| The number of cached entries.

|===

== Data Access

The following metrics monitor the cache accesses, such as lookup and evictions.

=== Reads

====
*Tags*

`result=hit|miss`:: The result of the read/lookup operation.
If the value is `hit`, the entry was found in the cache.
====

The read requests can be monitored using a single metric.

|===
|Metric |Description

m| cache_gets_total
| The total number of cache lookups.

|===

====
*Hit Ratio for read operation*

An expression can be used to compute the hit ratio for a cache in systems such as Prometheus.
For example, the hit ratio for read operations can be expressed as:

----
cache_gets_total{result="hit"} / cache_gets_total

----

====

=== Evictions

When a cache is limited, eviction is the process of removing the least used entries to make space available for new entries to be cached.

|===
|Metric |Description

m|cache_evictions_count
| The number of times the cache was evicted.

|===


