cockroachdb 官方提供的是一个直接使用docker 运行的方式,但是使用docker-compose 会比较方便,可以快速搭建一个集群
同时官方也提供了prometheus 的metrics,我们可以快速的通过grafana 提供一个dashboard
docker-compose 运行
- docker-compose 文件
version: "3"
services:
grafana:
image: grafana/grafana
ports:
- "3000:3000"
alert:
image: prom/alertmanager
ports:
- "9093:9093"
prometheus:
image: prom/prometheus
volumes:
- "./rules:/rules"
- "./prometheus.yml:/etc/prometheus/prometheus.yml"
ports:
- "9090:9090"
roach1:
image: cockroachdb/cockroach:v19.1.5
hostname: roach1
command: start --insecure
volumes:
- "./data1:/cockroach/cockroach-data"
ports:
- "26257:26257"
- "8081:8080"
roach2:
image: cockroachdb/cockroach:v19.1.5
hostname: roach2
command: start --insecure --join=roach1
volumes:
- "./data2:/cockroach/cockroach-data"
ports:
- "26258:26257"
- "8082:8080"
roach3:
image: cockroachdb/cockroach:v19.1.5
hostname: roach3
command: start --insecure --join=roach1
volumes:
- "./data3:/cockroach/cockroach-data"
ports:
- "26259:26257"
- "8083:8080"
- 说明
上述集成了prometheus、alertmanager 以及grafana,集群的搭建很简单
alertmanager 以及grafana dashboard
官方已经提供好了alertmanager 的rule同时也给我们提供了grafana dashboard 的json 文件
参考https://www.cockroachlabs.com/docs/stable/monitor-cockroachdb-with-prometheus.html
prometheus.yml:
# Prometheus configuration for cockroach clusters.
# Requires prometheus 2.X
#
# Run with:
# $ prometheus -config.file=prometheus.yml
global:
scrape_interval: 10s
evaluation_interval: 10s
rule_files:
- "/rules/alerts.rules.yml"
- "/rules/aggregation.rules.yml"
# Alert manager running on the same host:
alerting:
alertmanagers:
- path_prefix: "/alertmanager/"
static_configs:
- targets:
- alert:9093
scrape_configs:
- job_name: 'cockroachdb'
metrics_path: '/_status/vars'
# Insecure mode:
scheme: 'http'
tls_config:
insecure_skip_verify: true
static_configs:
- targets: ['roach1:8080','roach2:8080','roach3:8080']
labels:
cluster: 'my-cockroachdb-cluster'
grafana dashboard json 文件可以参考官方文档,或者github 项目
运行效果
参考资料
https://www.cockroachlabs.com/docs/stable/monitor-cockroachdb-with-prometheus.html
https://github.com/rongfengliang/cockroachdb-docker-compose-local-cluster