mcpField
M
mimir

mimir

github.com/grafana云与 DevOps2954.8k 次安装1 天前更新
代码仓库

关于 mimir

用于部署和运维 Grafana Mimir 的工作流技能。Mimir 为 Prometheus 和 OpenTelemetry 指标提供横向扩展、多租户的长期存储,技能涵盖本地运行、数据写入、Kubernetes 部署和故障排查。

主要功能

  1. 01使用 Docker 本地运行
  2. 02通过 Prometheus remote_write 写入
  3. 03通过 Grafana Alloy 写入
  4. 04使用 Helm 部署到 Kubernetes
  5. 05配置多租户

适用场景

  1. 01运行本地 Mimir 实例
  2. 02向 Mimir 发送 Prometheus 指标
  3. 03在 Kubernetes 上部署 Mimir
  4. 04排查指标缺失或写入受阻

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/grafana/skills --skill mimir

安装后在 Claude Code 中输入/mimir确认已加载。

附带文件references/architecture.mdreferences/storage.md

详细介绍

Grafana Mimir

文档:https://grafana.com/docs/mimir/latest/

适用于 Prometheus + OpenTelemetry 指标的水平可扩展、多租户长期存储。

前置条件

  • Docker(用于快速启动)或 Kubernetes 集群(用于 Helm)
  • 用于生产环境的对象存储存储桶(S3/GCS/Azure)——开发环境仅使用文件系统
  • 能够通过 remote_write 向 Mimir 推送端点写入数据的 Prometheus 或 Alloy

常见工作流

1. 在本地启动单体版 Mimir
# demo.yaml
target: all
multitenancy_enabled: false

blocks_storage:
  backend: filesystem
  bucket_store:
    sync_dir: /tmp/mimir/tsdb-sync
  filesystem:
    dir: /tmp/mimir/data/tsdb
  tsdb:
    dir: /tmp/mimir/tsdb

compactor:
  data_dir: /tmp/mimir/compactor
  sharding_ring:
    kvstore: { store: memberlist }

distributor:
  ring:
    instance_addr: 127.0.0.1
    kvstore: { store: memberlist }

ingester:
  ring:
    instance_addr: 127.0.0.1
    kvstore: { store: memberlist }
    replication_factor: 1

server:
  http_listen_port: 9009
  grpc_listen_port: 9095
  log_level: error
# 1. Run it
docker run --rm -p 9009:9009 -v $(pwd)/demo.yaml:/etc/mimir/demo.yaml \
  grafana/mimir:latest --config.file=/etc/mimir/demo.yaml

# 2. Verify readiness (expect HTTP 200, body: "ready")
curl -sf http://localhost:9009/ready

# 3. Verify it's serving the API
curl -s http://localhost:9009/api/v1/labels | jq '.status'   # → "success"

# 4. Verify self-metrics scrape
curl -s http://localhost:9009/metrics | grep -E '^mimir_(distributor|ingester)_' | head
2. 发送指标 — Prometheus remote_write
remote_write:
  - url: http://localhost:9009/api/v1/push
    headers:
      X-Scope-OrgID: tenant1   # required when multitenancy_enabled: true
# Verify samples are landing
curl -s -H 'X-Scope-OrgID: tenant1' \
  'http://localhost:9009/api/v1/query?query=up' | jq '.data.result | length'
# Expect > 0 within ~30s of Prometheus scraping
3. 发送指标 — Grafana Alloy
prometheus.remote_write "mimir" {
  endpoint {
    url = "http://mimir:9009/api/v1/push"
    headers = { "X-Scope-OrgID" = "tenant1" }
  }
}
4. 在 Kubernetes 上部署(Helm,微服务)
# 1. Install
helm repo add grafana https://grafana.github.io/helm-charts
helm install mimir grafana/mimir-distributed --version 6.0.6 -f values.yaml

# 2. Verify every pod is Running / Ready
kubectl get pods -n mimir
#   distributor, ingester, querier, query-frontend, store-gateway, compactor, ruler

# 3. Verify the gateway is ready
kubectl port-forward -n mimir svc/mimir-nginx 9009:80 &
curl -sf http://localhost:9009/ready

多租户

multitenancy_enabled: true
# Every request must include header:  X-Scope-OrgID: <tenant-id>

有关存储后端(S3 / GCS / Azure / 文件系统),请参阅 references/storage.md。有关组件角色、ring 选项、限制和 API 端点列表,请参阅 references/architecture.md。

故障排查

  • /ready 返回 503 → ingester 仍在加入 ring;检查 mimir_ring_members 和 ingester 日志
  • 推送时出现 429 Too Many Requests → 调高 limits.ingestion_rate / ingestion_burst_size
  • 已写入样本,但查询结果为空 → 确认写入和读取时的 X-Scope-OrgID 相匹配
  • 查询旧数据时没有结果 → 检查 compactor 日志,以及 store-gateway 是否已同步数据块

资源

评论

支持 Markdown