How to Monitor Memcached with Vigilmon
Memcached is a battle-tested in-memory caching layer used by high-traffic applications. When Memcached fails, your database gets hammered with cache-miss traffic, causing cascading slowdowns. This guide shows how to monitor Memcached availability with Vigilmon.
Why Monitor Memcached?
Memcached uses a binary/text protocol with no built-in HTTP health endpoint. This means:
- Standard uptime monitors cannot check it directly
- A failed Memcached instance is invisible until your app starts slowing down
- Database CPU spikes are often the first symptom of Memcached failure
The solution: add a health check layer in your application that Vigilmon can reach.
Approach 1: Application Health Endpoint
Add a health endpoint to your app that tests Memcached connectivity:
Node.js:
const Memcached = require('memcached');
const client = new Memcached('localhost:11211');
app.get('/health/cache', (req, res) => {
client.get('health-check', (err, data) => {
if (err) {
return res.status(503).json({ status: 'error', cache: 'down' });
}
res.json({ status: 'ok', cache: 'up' });
});
});
Python:
from pymemcache.client.base import Client
client = Client('localhost', 11211)
@app.route('/health/cache')
def health_cache():
try:
client.get('health-probe')
return jsonify({'status': 'ok', 'cache': 'up'})
except Exception as e:
return jsonify({'status': 'error', 'cache': 'down'}), 503
PHP / Laravel:
Route::get('/health/cache', function () {
$memcached = new Memcached();
$memcached->addServer('localhost', 11211);
$stats = $memcached->getStats();
if ($stats === false) {
return response()->json(['status' => 'error', 'cache' => 'down'], 503);
}
return response()->json(['status' => 'ok', 'cache' => 'up']);
});
Approach 2: Sidecar Health Script
If you cannot modify the application, expose a lightweight health check via a bash script and netcat:
#!/bin/bash
result=$(echo "stats" | nc -w 1 localhost 11211 | grep "STAT uptime")
if [ -n "$result" ]; then
echo '{"status": "ok"}'
exit 0
else
echo '{"status": "error"}'
exit 1
fi
Setting Up Vigilmon Monitors
Monitor 1: Application Cache Health
-
URL:
https://your-app.com/health/cache - Method: GET
- Expected status: 200
-
Keyword check:
"cache":"up" - Interval: 60 seconds
- Multi-region: Enabled
Monitor 2: Application Overall Health
Also monitor your main application — if Memcached is down and your app does not degrade gracefully, the whole app may fail:
-
URL:
https://your-app.com/health - Expected status: 200
-
Keyword check:
ok
Alert Configuration
Memcached failures often precede larger outages:
- Immediate: Alert your backend team via Slack/PagerDuty
- Escalation: If cache is down for 5+ minutes, escalate to on-call
- Recovery: Auto-notify when cache comes back online
Common Failure Modes
| Failure Mode | Symptom | Vigilmon Detection |
|---|---|---|
| Process crash | 503 on /health/cache | Immediate alert |
| Memory exhaustion | High eviction rate | App-level instrumentation |
| Network partition | Timeout on cache calls | Vigilmon timeout alert |
| Configuration error | Wrong host/port | 503 on first check |
Best Practices
- Return 503 (not 200) when cache is unavailable — lets Vigilmon detect it correctly
- Add a
/health/cacheendpoint to every application using Memcached - Monitor from multiple regions — network partitions to your cache are location-specific
- Set a 5-second timeout — Memcached should respond in milliseconds
- Alert immediately — Memcached failures cascade quickly to database overload
Conclusion
Memcached failures are silent killers — your app degrades without clear error messages. Vigilmon catches cache failures before they cascade into full application outages.
Start monitoring your cache layer free at vigilmon.online
Top comments (0)