Dubbo-Go 支持采集运行态 Metrics 指标,并接入 Prometheus + Grafana 实现微服务可观测性。
当前示例支持两种监控模式:
示例源码:
https://github.com/apache/dubbo-go-samples/tree/main/metrics
Dubbo-Go 应用 ---> Prometheus ---> Grafana
(暴露 /metrics 或 /prometheus 接口)
Prometheus 主动抓取 Dubbo-Go 应用指标。
Dubbo-Go 应用 ---> Pushgateway ---> Prometheus ---> Grafana
应用主动推送指标到 Pushgateway,Prometheus 再拉取。
⚠️ 注意:
Pushgateway 适用于 短生命周期任务(如 batch / cron job),不推荐用于长期运行的服务。
| 组件 | 端口 | 说明 |
|---|---|---|
| Grafana | 3000 | 指标可视化 |
| Prometheus | 9090 | 指标存储与查询 |
| Pushgateway | 9091 | 接收应用推送指标 |
| go-server | — | Dubbo-Go Provider 示例 |
| go-client | — | Dubbo-Go Consumer 示例 |
进入目录:
cd metrics/prometheus_grafana
启动监控组件:
docker-compose up -d
访问地址:
客户端与服务端使用相同环境变量:
export ZK_ADDRESS="127.0.0.1:2181"
# Push 模式必需
export PUSHGATEWAY_URL="127.0.0.1:9091"
export JOB_NAME="dubbo-service"
# 可选
export PUSHGATEWAY_USER="username"
export PUSHGATEWAY_PASS="1234"
go run ./go-server/cmd/main.go
go run ./go-client/cmd/main.go
go run ./go-client/cmd/main.go --push=false
go run ./go-server/cmd/main.go --push=false
访问:
http://localhost:9091/metrics
访问:
http://localhost:<应用端口>/prometheus
Home → Connections → Data sources
http://host.docker.internal:9090
Home → Dashboards → New → Import
grafana.json你将看到:
Pushgateway 默认:
不会自动删除旧指标
任务停止后:
机制:
job_pushed_at_seconds工具路径:
tools/pgw-cleaner
用于:
请检查:
dubbo_consumer_requests_succeed_total
是否有数据
请改为实际 IP 地址:
推荐使用:
kube-prometheus https://github.com/prometheus-operator/kube-prometheus
创建:
dubboPodMonitor.yaml
内容:
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: dubbo-pod-monitor
namespace: monitoring
spec:
namespaceSelector:
matchNames:
- dubbo-system
selector:
matchLabels:
app-type: dubbo
podMetricsEndpoints:
- port: metrics
path: /prometheus
kubectl apply -f Deployment.yaml
访问:
http://<prometheus-nodeport>/targets
确认 Pod 状态为:
UP
| 场景 | 推荐模式 |
|---|---|
| 长期运行服务 | Pull |
| 短生命周期任务 | Push |
| K8s 环境 | Pull + PodMonitor |
| 需要清理能力 | 配合 pgw-cleaner |
Dubbo-Go 当前支持:
通过以上配置,可以实现完整的 Dubbo-Go 可观测性体系。