Skip to main content

Memcached

Monitor Memcached — cache hit ratios, evictions, connection counts, memory usage, and command throughput — using the Prometheus Memcached exporter.

Pattern: memcached_exporter → Prometheus scrape → xScaler remote_write


Prerequisites

  • Memcached 1.5+
  • xScaler tenant credentials (token + tenant ID)

Option A — Prometheus Exporter

docker run -d \
-p 9150:9150 \
prom/memcached-exporter \
--memcached.address=localhost:11211

Add to prometheus.yml:

scrape_configs:
- job_name: memcached
static_configs:
- targets: ['localhost:9150']

remote_write:
- url: https://euw1-01.m.xscalerlabs.com/api/v1/push
authorization:
credentials: <token>
headers:
X-Scope-OrgID: <tenant-id>

Option B — Grafana Alloy

prometheus.exporter.memcached "cache" {
address = "localhost:11211"
}

prometheus.scrape "memcached" {
targets = prometheus.exporter.memcached.cache.targets
forward_to = [prometheus.remote_write.xscaler.receiver]
}

prometheus.remote_write "xscaler" {
endpoint {
url = "https://euw1-01.m.xscalerlabs.com/api/v1/push"
authorization {
type = "Bearer"
credentials = "<token>"
}
headers = { "X-Scope-OrgID" = "<tenant-id>" }
}
}

Option C — OpenTelemetry Collector

receivers:
memcached:
endpoint: localhost:11211
collection_interval: 15s

processors:
memory_limiter:
check_interval: 1s
limit_mib: 256
batch:
timeout: 10s

exporters:
otlphttp/xscaler:
endpoint: https://euw1-01.m.xscalerlabs.com
headers:
Authorization: "Bearer <token>"
X-Scope-OrgID: "<tenant-id>"
compression: gzip

service:
pipelines:
metrics:
receivers: [memcached]
processors: [memory_limiter, batch]
exporters: [otlphttp/xscaler]

Logs

Collect Memcached server log via systemd journal. Add the following to your Alloy config:

loki.source.journal "memcached_journal" {
forward_to = [loki.write.xscaler.receiver]
relabel_rules = loki.relabel.memcached_journal.rules
labels = {
job = "integrations/memcached",
instance = constants.hostname,
}
}

loki.relabel "memcached_journal" {
forward_to = []
rule {
source_labels = ["__journal__systemd_unit"]
target_label = "unit"
}
}

loki.write "xscaler" {
endpoint {
url = "https://euw1-01.l.xscalerlabs.com/api/v1/logs/push"

http_client_config {
authorization {
type = "Bearer"
credentials = env("XSCALER_TOKEN")
}
}

headers = { "X-Scope-OrgID" = env("XSCALER_TENANT_ID") }
}
}

Key metrics

MetricDescription
memcached_current_itemsItems stored in cache
memcached_current_connectionsActive connections
memcached_commands_totalCommands processed by type
memcached_get_hits_totalCache hits on GET
memcached_get_misses_totalCache misses on GET
memcached_evictions_totalItems evicted due to memory pressure
memcached_bytesCurrent memory used by items
memcached_bytes_read_totalTotal bytes read from clients