Dubbo-Go supports runtime metrics collection and integration with Prometheus + Grafana to build observability for microservices.
This example covers two monitoring modes:
Example source code:
https://github.com/apache/dubbo-go-samples/tree/main/metrics
Dubbo-Go Application ---> Prometheus ---> Grafana
(exposes /metrics or /prometheus endpoint)
Prometheus actively scrapes metrics from Dubbo-Go applications.
Dubbo-Go Application ---> Pushgateway ---> Prometheus ---> Grafana
Applications push metrics to Pushgateway. Prometheus scrapes Pushgateway.
Pushgateway is designed for short-lived jobs (batch / cron) and is not recommended for long-running services.
| Component | Port | Description |
|---|---|---|
| Grafana | 3000 | Metrics visualization dashboard |
| Prometheus | 9090 | Metrics storage and query engine |
| Pushgateway | 9091 | Receives pushed metrics |
| go-server metrics endpoint | 9099 in this sample | Provider metrics in Pull mode |
| go-client metrics endpoint | 9097 in this sample | Consumer metrics in Pull mode |
If you use Dubbo-Go defaults instead of this sample, the default metrics endpoint is http://localhost:9090/metrics. This sample overrides the metrics path to /prometheus.
Navigate to:
cd metrics/prometheus_grafana
Start services:
docker-compose up -d
Access:
Both client and server share the same configuration:
export ZK_ADDRESS="127.0.0.1:2181"
# Required for Push mode
export PUSHGATEWAY_URL="127.0.0.1:9091"
export JOB_NAME="dubbo-service"
# Optional
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
Open:
http://localhost:9091/metrics
<app_port> means the HTTP metrics port exposed by the Dubbo-Go application itself, not the Prometheus or Pushgateway port.
In this sample:
http://localhost:9099/prometheushttp://localhost:9097/prometheusThese ports are defined in metrics/prometheus_grafana/prometheus_pull.yml.
If you use your own Dubbo-Go application instead of this sample, replace the port with your application’s metrics port.
admin / adminHome → Connections → Data sources
http://host.docker.internal:9090
Note:
host.docker.internalallows Docker containers to access the host network. Replace with your actual IP if necessary.
Home → Dashboards → New → Import
grafana.json from the sample directory19294 (Dubbo Observability) and click LoadThe sample repository already includes the dashboard file at metrics/prometheus_grafana/grafana.json, so uploading that file is the most direct option.
Select the Prometheus data source
Click Import
You will see:
Metrics update dynamically as the client continuously calls the server.
Pushgateway does not automatically delete old metrics.
If a job stops:
Mechanism:
job_pushed_at_secondsTool repository:
Detailed documentation:
This tool lives in the apache/dubbo-go-samples repository, not in the apache/dubbo-go core repository.
Purpose:
Check:
dubbo_consumer_requests_succeed_total
returns results
Replace it with your actual host IP:
metrics/prometheus_grafana/prometheus_pull.ymlRecommended:
kube-prometheus https://github.com/prometheus-operator/kube-prometheus
Create 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
If your cluster enforces RBAC, grant Prometheus permission to read Pods in dubbo-system:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: dubbo-system
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: pod-reader-binding
namespace: dubbo-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: pod-reader
subjects:
- kind: ServiceAccount
name: prometheus-k8s
namespace: monitoring
If your Prometheus installation uses a different service account, replace the subjects section accordingly.
kubectl apply -f Deployment.yaml
Visit:
http://<prometheus-nodeport>/targets
Ensure your pods show:
UP
| Scenario | Recommended Mode |
|---|---|
| Long-running services | Pull |
| Short-lived jobs | Push |
| Kubernetes | Pull + PodMonitor |
| Pushgateway usage | Use pgw-cleaner |
Dubbo-Go provides:
With this setup, you can build a complete Dubbo-Go observability system.