How to Enable GitLab Metrics and Visualize Them with Prometheus & Grafana
This guide explains how to activate GitLab's metrics endpoint, configure Prometheus to scrape GitLab data, verify collection, and import ready-made Grafana dashboards to monitor CI/CD pipelines, providing step‑by‑step commands and screenshots for a complete monitoring solution.
With the rise of DevOps, CI/CD pipelines rely on continuous monitoring. GitLab’s enterprise monitoring panel provides real‑time visualization, performance analysis, and automated alerts to keep every stage from code commit to production deployment in optimal condition.
Enable GitLab Metrics
Set the
metrics.enabledflag to true in the GitLab Helm values file and upgrade the release.
<code>$ cat /etc/kubernetes/addons/gitlab-values.yaml
gitlab:
webservice:
workhorse:
metrics:
enabled: true
gitlab-runner:
metrics:
enabled: true
global:
monitoring:
enabled: true
</code> <code>$ helm -n gitlab upgrade gitlab -f /etc/kubernetes/addons/gitlab-values.yaml /etc/kubernetes/addons/gitlab
Release "gitlab" has been upgraded. Happy Helming!
...</code>Prometheus Scrape Configuration
Modify the Prometheus ConfigMap to add a job that discovers GitLab pods and rewrites labels for proper scraping.
<code>$ kubectl -n kube-system edit cm prometheus
- job_name: gitlab
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_pod_annotation_gitlab_com_prometheus_scrape]
action: keep
regex: true
- source_labels: [__meta_kubernetes_pod_annotation_gitlab_com_prometheus_scheme]
action: replace
regex: (https?)
target_label: __scheme__
- source_labels: [__meta_kubernetes_pod_annotation_gitlab_com_prometheus_path]
action: replace
target_label: __metrics_path__
regex: (.+)
- source_labels: [__address__, __meta_kubernetes_pod_annotation_gitlab_com_prometheus_port]
action: replace
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
target_label: __address__
- action: labelmap
regex: __meta_kubernetes_pod_label_(.+)
- source_labels: [__meta_kubernetes_namespace]
action: replace
target_label: kubernetes_namespace
- source_labels: [__meta_kubernetes_pod_name]
action: replace
target_label: kubernetes_pod_name
- job_name: gitlab-workhorse
kubernetes_sd_configs:
- role: endpoints
relabel_configs:
- action: keep
source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_endpoints_name, __meta_kubernetes_endpoint_port_name]
regex: gitlab;gitlab-webservice-default;http-metrics-wh
- target_label: app
replacement: workhorse
</code>Verify that Prometheus is collecting the metrics:
<code>$ curl -s $(kubectl -n kube-system get svc prometheus -ojsonpath='{.spec.clusterIP}:{.spec.ports[0].port}')/prometheus/api/v1/query --data-urlencode 'query=up{job=~"gitlab"}' | jq '.data.result[] | {app: .metric.app, instance: .metric.instance, status: .value[1]}'
{ "app": "gitlab-gitlab-runner", "instance": "10.244.58.236:9252", "status": "1" }
{ "app": "gitlab-exporter", "instance": "10.244.85.250:9168", "status": "1" }
... (additional results omitted for brevity)
</code>Grafana Dashboard Import
Import the following Grafana dashboard IDs to visualize GitLab metrics: 18917, 18923, 18921, 18925, 18926, 18927.
Tip: There are six panels, each adjusted to achieve the displayed results.
Conclusion
GitLab’s enterprise monitoring panel, combined with Prometheus and Grafana, offers a powerful way to achieve efficient development operations, improve cross‑team communication, and strengthen control over technical risk in complex IT environments.
Linux Ops Smart Journey
The operations journey never stops—pursuing excellence endlessly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.