{"slug":"cache-monitoring","title":"Cache Monitoring","description":"Effective monitoring is essential for maintaining optimal Redis performance and availability. This guide covers monitoring tools, key metrics, alerting, and troubleshooting for DanubeData managed Redi...","section":"Features","url":"https://docs.danubedata.ro/cache-monitoring","markdown_url":"https://docs.danubedata.ro/cache-monitoring.md","breadcrumbs":[{"title":"Features","slug":null},{"title":"Cache","slug":"cache-overview"},{"title":"Monitoring","slug":"cache-monitoring"}],"headings":[{"level":1,"title":"Cache Monitoring","id":"cache-monitoring"},{"level":2,"title":"Overview","id":"overview"},{"level":2,"title":"Key Metrics","id":"key-metrics"},{"level":3,"title":"Memory Metrics","id":"memory-metrics"},{"level":4,"title":"Used Memory","id":"used-memory"},{"level":4,"title":"Hit Rate","id":"hit-rate"},{"level":4,"title":"Evicted Keys","id":"evicted-keys"},{"level":3,"title":"Performance Metrics","id":"performance-metrics"},{"level":4,"title":"Operations Per Second","id":"operations-per-second"},{"level":4,"title":"Latency","id":"latency"},{"level":4,"title":"Slow Queries","id":"slow-queries"},{"level":3,"title":"Connection Metrics","id":"connection-metrics"},{"level":4,"title":"Connected Clients","id":"connected-clients"},{"level":4,"title":"Rejected Connections","id":"rejected-connections"},{"level":3,"title":"Replication Metrics","id":"replication-metrics"},{"level":4,"title":"Replication Lag","id":"replication-lag"},{"level":2,"title":"Dashboard Monitoring","id":"dashboard-monitoring"},{"level":3,"title":"Overview Dashboard","id":"overview-dashboard"},{"level":3,"title":"Real-time Graphs","id":"real-time-graphs"},{"level":3,"title":"Customizing View","id":"customizing-view"},{"level":2,"title":"Command-Line Monitoring","id":"command-line-monitoring"},{"level":3,"title":"INFO Command","id":"info-command"},{"level":3,"title":"Key Statistics","id":"key-statistics"},{"level":3,"title":"Real-time Monitoring","id":"real-time-monitoring"},{"level":3,"title":"Slow Query Log","id":"slow-query-log"},{"level":2,"title":"Performance Analysis","id":"performance-analysis"},{"level":3,"title":"Memory Analysis","id":"memory-analysis"},{"level":3,"title":"Command Statistics","id":"command-statistics"},{"level":3,"title":"Key Space Analysis","id":"key-space-analysis"},{"level":2,"title":"Instance Logs","id":"instance-logs"},{"level":2,"title":"Automatic Health Monitoring","id":"automatic-health-monitoring"},{"level":2,"title":"Alerting","id":"alerting"},{"level":3,"title":"Available Alerts","id":"available-alerts"},{"level":3,"title":"Setting Up Alerts","id":"setting-up-alerts"},{"level":3,"title":"Alert Examples","id":"alert-examples"},{"level":2,"title":"Monitoring Scripts","id":"monitoring-scripts"},{"level":3,"title":"Health Check Script","id":"health-check-script"},{"level":3,"title":"Metrics Collection Script","id":"metrics-collection-script"},{"level":2,"title":"Best Practices","id":"best-practices"},{"level":3,"title":"Monitoring Strategy","id":"monitoring-strategy"},{"level":3,"title":"Performance Baselines","id":"performance-baselines"},{"level":3,"title":"Troubleshooting Workflow","id":"troubleshooting-workflow"},{"level":2,"title":"Common Issues and Solutions","id":"common-issues-and-solutions"},{"level":3,"title":"High Memory Usage","id":"high-memory-usage"},{"level":3,"title":"Low Hit Rate","id":"low-hit-rate"},{"level":3,"title":"High Latency","id":"high-latency"},{"level":3,"title":"Connection Exhaustion","id":"connection-exhaustion"},{"level":2,"title":"Related Documentation","id":"related-documentation"}],"format":"markdown","word_count":1568,"content":"# Cache Monitoring\n\nEffective monitoring is essential for maintaining optimal Redis performance and availability. This guide covers monitoring tools, key metrics, alerting, and troubleshooting for DanubeData managed Redis instances.\n\n## Overview\n\nDanubeData provides comprehensive monitoring for Redis instances:\n\n- **Real-time Metrics**: CPU, memory, connections, operations\n- **Performance Tracking**: Hit rates, latency, throughput\n- **Historical Data**: 15 days of retention\n- **Custom Alerts**: Email notifications for critical events\n- **Slow Query Logging**: Identify performance bottlenecks\n- **API Access**: Cache metrics are also available over the public API for your own integrations\n\n## Key Metrics\n\n### Memory Metrics\n\n#### Used Memory\n\nTotal memory used by Redis:\n\n- **What it shows**: Current RAM consumption\n- **Healthy range**: 60-80% of allocated memory\n- **Alert at**: > 90%\n\n**Command**:\n```bash\nINFO memory | grep used_memory_human\n# used_memory_human:2.50G\n```\n\n#### Hit Rate\n\nCache hit ratio:\n\n- **Formula**: hits / (hits + misses) × 100\n- **Healthy range**: > 90%\n- **Alert at**: < 80%\n\n**Command**:\n```bash\nINFO stats | grep keyspace\n# keyspace_hits:1000000\n# keyspace_misses:50000\n# Hit rate: 95.2%\n```\n\n#### Evicted Keys\n\nKeys removed due to memory pressure:\n\n- **What it shows**: Memory eviction activity\n- **Healthy range**: 0-10 keys/sec\n- **Alert at**: > 100 keys/sec\n\n**Command**:\n```bash\nINFO stats | grep evicted_keys\n```\n\n### Performance Metrics\n\n#### Operations Per Second\n\nTotal commands processed:\n\n- **What it shows**: Workload intensity\n- **Healthy range**: Varies by instance size\n- **Monitor for**: Sudden spikes or drops\n\n**Command**:\n```bash\nINFO stats | grep instantaneous_ops_per_sec\n# instantaneous_ops_per_sec:5432\n```\n\n#### Latency\n\nAverage command execution time:\n\n- **What it shows**: Response time\n- **Healthy range**: < 1ms\n- **Alert at**: > 10ms\n\n**Command**:\n```bash\nredis-cli --latency -h redis-123456.danubedata.ro -a password\n# min: 0, max: 1, avg: 0.08 (96 samples)\n```\n\n#### Slow Queries\n\nCommands exceeding threshold:\n\n- **Default threshold**: 10ms\n- **Monitor**: Count and patterns\n- **Alert at**: > 10 slow queries/minute\n\n**Command**:\n```bash\nSLOWLOG GET 10\n```\n\n### Connection Metrics\n\n#### Connected Clients\n\nActive client connections:\n\n- **Healthy range**: < max_connections\n- **Alert at**: > 80% of max_connections\n\n**Command**:\n```bash\nINFO clients | grep connected_clients\n# connected_clients:245\n```\n\n#### Rejected Connections\n\nConnections refused due to limits:\n\n- **Healthy**: 0\n- **Alert at**: > 0\n\n**Command**:\n```bash\nINFO stats | grep rejected_connections\n```\n\n### Replication Metrics\n\n#### Replication Lag\n\nTime/bytes behind primary:\n\n- **Healthy**: < 1 second\n- **Alert at**: > 5 seconds\n\n**Command**:\n```bash\n# On primary\nINFO replication\n\n# On replica\nINFO replication | grep master_last_io_seconds_ago\n```\n\n## Dashboard Monitoring\n\n### Overview Dashboard\n\nNavigate to your Redis instance dashboard to view:\n\n- **Resource Usage**: CPU, memory, network\n- **Performance**: Ops/sec, latency, hit rate\n- **Connections**: Active, total, rejected\n- **Replication**: Lag, status, connected replicas\n\n### Real-time Graphs\n\nAvailable graphs (1 hour to 30 days):\n\n1. **Memory Usage**: Used vs allocated\n2. **Operations Per Second**: Total command throughput\n3. **Hit Rate**: Cache effectiveness\n4. **Connected Clients**: Connection count\n5. **Network I/O**: Bytes in/out\n6. **CPU Usage**: Processor utilization\n\n### Customizing View\n\n1. Click **Metrics** tab\n2. Select time range (1h, 6h, 24h, 7d, 30d)\n3. Choose metrics to display\n4. Set refresh interval (10s, 30s, 1m)\n\n## Command-Line Monitoring\n\n### INFO Command\n\nGet comprehensive server information:\n\n```bash\n# All info\nredis-cli INFO\n\n# Specific section\nredis-cli INFO memory\nredis-cli INFO stats\nredis-cli INFO replication\nredis-cli INFO cpu\nredis-cli INFO clients\n```\n\n### Key Statistics\n\n```bash\n# Database statistics\nredis-cli INFO keyspace\n# db0:keys=10000,expires=5000,avg_ttl=3600000\n\n# Memory details\nredis-cli INFO memory | grep -E 'used_memory_human|used_memory_peak_human|mem_fragmentation_ratio'\n\n# Commands processed\nredis-cli INFO stats | grep total_commands_processed\n\n# Hit rate calculation\nredis-cli INFO stats | grep -E 'keyspace_hits|keyspace_misses'\n```\n\n### Real-time Monitoring\n\n```bash\n# Monitor all commands in real-time\nredis-cli MONITOR\n\n# Continuous stats\nredis-cli --stat\n------- data ------ --------------------- load -------------------- - child -\nkeys       mem      clients blocked requests            connections\n10000      2.50G    245     0       1000000 (+0)        5000\n10000      2.50G    245     0       1000050 (+50)       5000\n\n# Latency monitoring\nredis-cli --latency\nmin: 0, max: 2, avg: 0.15 (1234 samples)\n\n# Big keys analysis\nredis-cli --bigkeys\n```\n\n### Slow Query Log\n\nMonitor slow commands:\n\n```bash\n# Get last 10 slow queries\nSLOWLOG GET 10\n\n# Get slow query count\nSLOWLOG LEN\n\n# Reset slow log\nSLOWLOG RESET\n\n# Example output:\n1) 1) (integer) 123      # Query ID\n   2) (integer) 1634567890  # Timestamp\n   3) (integer) 15000     # Execution time (microseconds)\n   4) 1) \"KEYS\"          # Command\n      2) \"*\"\n```\n\n## Performance Analysis\n\n### Memory Analysis\n\n```bash\n# Memory breakdown\nredis-cli INFO memory\n\n# Key categories:\n# used_memory: Total allocated by Redis\n# used_memory_rss: Actual RAM used (OS perspective)\n# used_memory_peak: Maximum memory used\n# mem_fragmentation_ratio: RSS/used (ideal: 1.0-1.5)\n\n# Sample objects\nredis-cli --memkeys --memkeys-samples 10000\n```\n\n### Command Statistics\n\n```bash\n# Command stats\nredis-cli INFO commandstats\n\n# Output:\n# cmdstat_get:calls=1000000,usec=500000,usec_per_call=0.50\n# cmdstat_set:calls=500000,usec=300000,usec_per_call=0.60\n\n# Most frequent commands\nredis-cli INFO commandstats | sort -t= -k2 -nr | head -10\n```\n\n### Key Space Analysis\n\n```bash\n# Keys by database\nredis-cli INFO keyspace\n\n# Sample keys\nredis-cli --scan --pattern 'user:*' | head -20\n\n# Key types distribution\nfor key in $(redis-cli --scan | head -1000); do\n    redis-cli TYPE $key\ndone | sort | uniq -c\n```\n\n## Instance Logs\n\nBeyond metrics, every cache instance's logs are searchable from the **Logs** page under the **Observability** section in your sidebar — or jump straight in from the instance page:\n\n- Search and filter by level, keyword, or a regex pattern across any of your instances\n- Live-tail logs as they happen, with automatic reconnect if your connection drops\n- Drag to zoom into any window on the volume chart to jump to the matching log lines\n\n## Automatic Health Monitoring\n\nDanubeData continuously watches the health of your running cache instances:\n\n- The moment a problem opens (for example a crash loop or out-of-memory), your whole team is notified by email and in the Notification Center, with the reason included\n- A warning banner appears directly on the affected cache instance page\n- Alerts clear themselves automatically once the instance recovers\n- If you have a webhook configured, health alerts flow through it too\n\n## Alerting\n\n### Available Alerts\n\nConfigure alerts for:\n\n- **High Memory Usage**: > 90%\n- **Low Hit Rate**: < 80%\n- **High Eviction Rate**: > 100 keys/sec\n- **Connection Limit**: > 80% of max\n- **Replication Lag**: > 5 seconds\n- **Instance Down**: Health check failure\n- **Persistence Failure**: RDB/AOF save failed\n\nYou'll also receive a follow-up notification automatically when a metric returns to normal, so you know the moment an issue resolves.\n\n### Setting Up Alerts\n\n1. Navigate to Redis instance\n2. Click **Settings** > **Alerts**\n3. Click **Add Alert**\n4. Configure:\n   - **Metric**: Select metric to monitor\n   - **Condition**: Threshold and comparison\n   - **Duration**: How long condition must persist\n   - **Notification**: Email recipients\n5. Click **Save Alert**\n\n### Alert Examples\n\n**High Memory Alert**:\n```\nMetric: Memory Usage\nCondition: > 90%\nDuration: 5 minutes\nAction: Email admin@example.com\n```\n\n**Low Hit Rate Alert**:\n```\nMetric: Hit Rate\nCondition: < 80%\nDuration: 15 minutes\nAction: Email team@example.com\n```\n\n**Replication Lag Alert**:\n```\nMetric: Replication Lag\nCondition: > 5 seconds\nDuration: 2 minutes\nAction: Email ops@example.com\n```\n\n## Monitoring Scripts\n\n### Health Check Script\n\n```python\nimport redis\nimport sys\n\ndef check_redis_health(host, password):\n    try:\n        r = redis.Redis(host=host, password=password, ssl=True)\n        \n        # Basic connectivity\n        if not r.ping():\n            print(\"ERROR: Cannot ping Redis\")\n            return False\n        \n        # Memory check\n        info = r.info('memory')\n        memory_used_pct = (info['used_memory'] / info['maxmemory']) * 100\n        if memory_used_pct > 90:\n            print(f\"WARNING: Memory usage at {memory_used_pct:.1f}%\")\n        \n        # Hit rate check\n        stats = r.info('stats')\n        hits = stats['keyspace_hits']\n        misses = stats['keyspace_misses']\n        hit_rate = (hits / (hits + misses)) * 100 if (hits + misses) > 0 else 0\n        if hit_rate < 80:\n            print(f\"WARNING: Hit rate at {hit_rate:.1f}%\")\n        \n        # Connection check\n        clients = r.info('clients')\n        if clients['connected_clients'] > 8000:  # Assuming max 10000\n            print(f\"WARNING: High connection count: {clients['connected_clients']}\")\n        \n        print(\"HEALTHY: All checks passed\")\n        return True\n        \n    except Exception as e:\n        print(f\"ERROR: {e}\")\n        return False\n\nif __name__ == '__main__':\n    result = check_redis_health('redis-123456.danubedata.ro', 'password')\n    sys.exit(0 if result else 1)\n```\n\n### Metrics Collection Script\n\n```bash\n#!/bin/bash\n# collect_redis_metrics.sh\n\nHOST=\"redis-123456.danubedata.ro\"\nPASS=\"your_password\"\nOUTPUT=\"/var/log/redis/metrics.log\"\n\nwhile true; do\n    TIMESTAMP=$(date +%s)\n    \n    # Get metrics\n    MEMORY=$(redis-cli -h $HOST -a $PASS --no-auth-warning INFO memory | grep used_memory: | cut -d: -f2)\n    OPS=$(redis-cli -h $HOST -a $PASS --no-auth-warning INFO stats | grep instantaneous_ops_per_sec | cut -d: -f2)\n    CLIENTS=$(redis-cli -h $HOST -a $PASS --no-auth-warning INFO clients | grep connected_clients | cut -d: -f2)\n    \n    # Log metrics\n    echo \"$TIMESTAMP,$MEMORY,$OPS,$CLIENTS\" >> $OUTPUT\n    \n    sleep 60\ndone\n```\n\n## Best Practices\n\n### Monitoring Strategy\n\n1. **Monitor Key Metrics**: Focus on memory, hit rate, latency\n2. **Set Appropriate Alerts**: Not too sensitive, not too lenient\n3. **Regular Review**: Weekly review of trends\n4. **Baseline Performance**: Know your normal patterns\n5. **Proactive Monitoring**: Catch issues before they impact users\n\n### Performance Baselines\n\nEstablish baselines for:\n\n- **Peak Traffic**: Ops/sec during busy periods\n- **Average Latency**: Typical response times\n- **Memory Growth**: Daily/weekly memory increase\n- **Hit Rate**: Expected cache effectiveness\n- **Connection Patterns**: Normal connection count\n\n### Troubleshooting Workflow\n\n1. **Identify Symptom**: What is the observed issue?\n2. **Check Dashboard**: Review recent metrics\n3. **Run Commands**: Use Redis CLI for details\n4. **Review Logs**: Check for errors or warnings\n5. **Analyze Patterns**: Look for correlations\n6. **Test Fix**: Implement and verify solution\n7. **Document**: Record issue and resolution\n\n## Common Issues and Solutions\n\n### High Memory Usage\n\n**Detection**:\n```bash\nredis-cli INFO memory | grep used_memory_human\n```\n\n**Solutions**:\n- Set expiration on keys\n- Review eviction policy\n- Implement data cleanup\n- Upgrade to larger instance\n\n### Low Hit Rate\n\n**Detection**:\n```bash\nredis-cli INFO stats | grep keyspace\n```\n\n**Solutions**:\n- Review cache key patterns\n- Increase TTL for stable data\n- Pre-warm cache\n- Review application caching logic\n\n### High Latency\n\n**Detection**:\n```bash\nredis-cli --latency\n```\n\n**Solutions**:\n- Check slow query log\n- Review command patterns\n- Use pipelining\n- Upgrade instance\n- Check network latency\n\n### Connection Exhaustion\n\n**Detection**:\n```bash\nredis-cli INFO clients | grep connected_clients\n```\n\n**Solutions**:\n- Implement connection pooling\n- Fix connection leaks\n- Increase max_connections\n- Review client configuration\n\n## Related Documentation\n\n- [Redis Overview](https://docs.danubedata.ro/cache-redis)\n- [Redis Replicas](https://docs.danubedata.ro/cache-replicas)\n- [Cache Persistence](https://docs.danubedata.ro/cache-persistence)\n- [Monitoring Overview](https://docs.danubedata.ro/monitoring-overview)\n- [Performance Optimization](https://docs.danubedata.ro/cache-redis#performance-optimization)\n\n","prev":{"title":"Persistence","slug":"cache-persistence","url":"https://docs.danubedata.ro/cache-persistence","markdown_url":"https://docs.danubedata.ro/cache-persistence.md","json_url":"https://docs.danubedata.ro/cache-persistence.json"},"next":{"title":"Networking","slug":"networking-overview","url":"https://docs.danubedata.ro/networking-overview","markdown_url":"https://docs.danubedata.ro/networking-overview.md","json_url":"https://docs.danubedata.ro/networking-overview.json"},"index_url":"https://docs.danubedata.ro/index.json"}