id: garnet-cache-memory-saturation-and-eviction-sentinel
namespace: company.cache
description: |
Infrastructure sentinel that periodically probes Microsoft Garnet via the RESP protocol,
tracks memory saturation against allocated boundaries, evaluates key eviction counters,
dispatches rich Slack capacity alerts before OOM degradation occurs, and persists
telemetry for operational auditing.
inputs:
- id: garnet_host
type: STRING
displayName: "Garnet Host"
defaults: "localhost"
description: "Garnet cache instance hostname, service VIP, or container name."
- id: garnet_port
type: INT
displayName: "Garnet Port"
defaults: 3278
description: "Garnet RESP TCP port (default 3278, or 6379 in Redis compatibility mode)."
- id: memory_threshold_pct
type: INT
displayName: "Memory Threshold %"
defaults: 85
description: "Memory saturation warning threshold percentage (0-100)."
- id: alert_on_evictions
type: BOOL
displayName: "Alert on Evictions"
defaults: true
description: "When true, escalates to alert state if key evictions are actively
occurring."
- id: slack_channel
type: STRING
displayName: "Slack Channel"
defaults: "#cache-ops"
description: "Target Slack channel for Garnet capacity and eviction warnings."
triggers:
- id: periodic_saturation_check
type: io.kestra.plugin.core.trigger.Schedule
description: "Executes continuous capacity audits every 10 minutes. Shipped
disabled by default for initial connection verification."
cron: "*/10 * * * *"
disabled: true
tasks:
- id: probe_garnet_metrics
type: io.kestra.plugin.scripts.python.Script
description: "Connects to Microsoft Garnet via RESP, extracts memory consumption
and eviction counters, and calculates saturation percentage."
containerImage: python:3.11-slim
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
beforeCommands:
- pip install redis kestra
env:
GARNET_HOST: "{{ inputs.garnet_host }}"
GARNET_PORT: "{{ inputs.garnet_port }}"
GARNET_PASSWORD: "{{ secret('GARNET_PASSWORD') }}"
THRESHOLD_PCT: "{{ inputs.memory_threshold_pct }}"
script: |
import os
import sys
import redis
from kestra import Kestra
host = os.environ.get("GARNET_HOST", "localhost")
port = int(os.environ.get("GARNET_PORT", 3278))
password = os.environ.get("GARNET_PASSWORD") or None
threshold = float(os.environ.get("THRESHOLD_PCT", 85))
try:
r = redis.Redis(
host=host,
port=port,
password=password,
socket_timeout=5,
decode_responses=True
)
info_memory = r.info("memory")
info_stats = r.info("stats")
except Exception as e:
print(f"Failed to connect to Garnet at {host}:{port}: {e}", file=sys.stderr)
sys.exit(1)
used_memory = int(info_memory.get("used_memory", 0))
maxmemory = int(
info_memory.get("maxmemory")
or info_memory.get("system_memory_limit")
or info_memory.get("total_system_memory")
or (1024 * 1024 * 1024)
)
evicted_keys = int(info_stats.get("evicted_keys", 0))
saturation_pct = round((used_memory / maxmemory) * 100, 2) if maxmemory > 0 else 0.0
def format_bytes(bytes_val):
mb = round(bytes_val / (1024 * 1024), 2)
return f"{mb} MB"
status = "HEALTHY"
if saturation_pct >= threshold:
status = "SATURATED"
elif evicted_keys > 0:
status = "EVICTIONS_DETECTED"
Kestra.outputs({
"saturation_pct": saturation_pct,
"used_memory_bytes": used_memory,
"maxmemory_bytes": maxmemory,
"used_memory_human": format_bytes(used_memory),
"maxmemory_human": format_bytes(maxmemory),
"evicted_keys": evicted_keys,
"status": status
})
- id: evaluate_saturation_state
type: io.kestra.plugin.core.flow.If
description: "Evaluates saturation percentage and eviction counters against team
thresholds to branch into alerting or healthy states."
condition: "{{ outputs.probe_garnet_metrics.vars.saturation_pct >=
inputs.memory_threshold_pct or (inputs.alert_on_evictions and
outputs.probe_garnet_metrics.vars.evicted_keys > 0) }}"
then:
- id: notify_slack_memory_alert
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Dispatches high-priority Slack incident briefing card with exact
utilization figures and SRE remediation guidance."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "{{ inputs.slack_channel }}",
"text": ":rotating_light: *GARNET CAPACITY ALERT: Memory Saturation / Key Eviction*",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "GARNET ALERT: Cache Memory Saturation",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Target Instance:*\n`{{ inputs.garnet_host }}:{{ inputs.garnet_port }}`"
},
{
"type": "mrkdwn",
"text": "*Status:*\n:warning: `{{ outputs.probe_garnet_metrics.vars.status }}`"
},
{
"type": "mrkdwn",
"text": "*Memory Saturation:*\n`{{ outputs.probe_garnet_metrics.vars.saturation_pct }}%` (Limit: `{{ inputs.memory_threshold_pct }}%`)"
},
{
"type": "mrkdwn",
"text": "*Used / Max Memory:*\n`{{ outputs.probe_garnet_metrics.vars.used_memory_human }} / {{ outputs.probe_garnet_metrics.vars.maxmemory_human }}`"
},
{
"type": "mrkdwn",
"text": "*Active Key Evictions:*\n`{{ outputs.probe_garnet_metrics.vars.evicted_keys }}`"
},
{
"type": "mrkdwn",
"text": "*Execution ID:*\n`{{ execution.id }}`"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Recommended Remediation:*\n1. Audit active keyspaces for missing TTL configurations.\n2. Scale instance `--memory` limit or adjust container memory boundaries.\n3. Verify cache hit ratios to confirm if working set exceeds allocated RAM."
}
}
]
}
- id: log_saturation_warning
type: io.kestra.plugin.core.log.Log
description: "Logs capacity saturation warning in Kestra execution history."
message: "GARNET WARNING: Instance at {{ inputs.garnet_host }}:{{
inputs.garnet_port }} is at {{
outputs.probe_garnet_metrics.vars.saturation_pct }}% memory saturation
({{ outputs.probe_garnet_metrics.vars.used_memory_human }} / {{
outputs.probe_garnet_metrics.vars.maxmemory_human }}). Evicted keys:
{{ outputs.probe_garnet_metrics.vars.evicted_keys }}."
else:
- id: log_healthy_metrics
type: io.kestra.plugin.core.log.Log
description: "Records nominal memory utilization and zero-eviction state when
operating within capacity tolerances."
message: "GARNET HEALTHY: Instance at {{ inputs.garnet_host }}:{{
inputs.garnet_port }} is healthy. Memory utilization: {{
outputs.probe_garnet_metrics.vars.saturation_pct }}% ({{
outputs.probe_garnet_metrics.vars.used_memory_human }} / {{
outputs.probe_garnet_metrics.vars.maxmemory_human }}). Evicted keys:
{{ outputs.probe_garnet_metrics.vars.evicted_keys }}."
- id: finalize_capacity_telemetry
type: io.kestra.plugin.core.output.OutputValues
description: "Publishes structured telemetry for downstream dashboards,
historical trend auditing, and capacity planning."
values:
execution_id: "{{ execution.id }}"
host: "{{ inputs.garnet_host }}"
port: "{{ inputs.garnet_port }}"
saturation_pct: "{{ outputs.probe_garnet_metrics.vars.saturation_pct }}"
used_memory_human: "{{ outputs.probe_garnet_metrics.vars.used_memory_human }}"
maxmemory_human: "{{ outputs.probe_garnet_metrics.vars.maxmemory_human }}"
evicted_keys: "{{ outputs.probe_garnet_metrics.vars.evicted_keys }}"
status: "{{ outputs.probe_garnet_metrics.vars.status }}"
errors:
- id: notify_probe_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Alerts SRE channel if the RESP probe fails to connect or query the
Garnet instance."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "{{ inputs.slack_channel }}",
"text": ":rotating_light: *GARNET SENTINEL PROBE FAILED*\n*Target:* `{{ inputs.garnet_host }}:{{ inputs.garnet_port }}`\n*Failure:* Sentinel was unable to collect RESP metrics or authenticate to the Garnet instance.\n*Execution ID:* `{{ execution.id }}`"
}