Memcached - Stats Items
Memcached - Monitoring Item Statistics with stats items
Section titled “Memcached - Monitoring Item Statistics with stats items”The stats items command is a crucial diagnostic tool that provides detailed statistics about items stored within each slab class. These statistics are essential for monitoring cache health, performance tuning, and capacity planning.
Syntax
Section titled “Syntax”The command is executed via a telnet connection or a Memcached client library.
stats itemsExample Output
Section titled “Example Output”stats itemsSTAT items:1:number 1STAT items:1:age 73STAT items:1:evicted 0STAT items:1:evicted_nonzero 0STAT items:1:evicted_time 0STAT items:1:outofmemory 0STAT items:1:tailrepairs 0STAT items:1:reclaimed 0STAT items:1:expired_unfetched 0STAT items:1:evicted_unfetched 0ENDInterpreting the Statistics
Section titled “Interpreting the Statistics”Each line provides a piece of information about a specific slab class, identified by the number after items:. For example, items:1:... refers to slab class 1.
number <count>: The current number of items stored in this slab class.age <seconds>: The age of the oldest, non-expired item in the LRU (Least Recently Used) queue. High age values can indicate a healthy, stable cache.evicted <count>: (Critical Metric) The number of valid items that were removed from the cache to make space for a new item because the slab class was full. A consistently increasingevictedcount is a strong indicator that you need to allocate more memory to Memcached.evicted_nonzero <count>: The number of times an eviction occurred for an item with a non-zero expiration time.evicted_time <seconds>: The time in seconds since the last item was evicted from this slab class.outofmemory <count>: Number of times a write operation failed for this slab class because it was out of memory pages. This often precedes evictions.reclaimed <count>: Number of items that were expired and then reclaimed by the LRU crawler to free up memory.expired_unfetched <count>: Number of items that expired without ever being requested by agetoperation.evicted_unfetched <count>: Number of items that were evicted without ever being requested by agetoperation. High numbers here might suggest you are caching data that is never used.
Practical Application: Monitoring and Alerting
Section titled “Practical Application: Monitoring and Alerting”In a production environment, you should not monitor these stats manually. Instead, integrate them into a modern monitoring system.
- Prometheus: Use a Memcached exporter (e.g.,
memcached_exporter) to scrape these metrics and store them in Prometheus. You can then build Grafana dashboards to visualize cache health over time. - APM Tools: Services like Datadog, New Relic, or Dynatrace often have built-in Memcached integrations that parse these stats automatically.
- Alerting: Set up alerts on key metrics. The most important one to watch is
evicted. An alert on a sustained, non-zero rate of evictions will notify you of potential performance degradation before it seriously impacts users.