A Battle-Tested Guide to Monitoring Self-Hosted GitLab with Prometheus and Grafana

Quick Start: Enable GitLab Metrics and Connect Grafana in 5 Minutes

The GitLab Omnibus package comes pre-packaged with almost every exporter you need. Instead of going through the trouble of installing standalone node-exporter or sidekiq-exporter instances, all you have to do is enable the built-in endpoints in your configuration file.

Step 1: Enable Exporters on the GitLab Server

Open /etc/gitlab/gitlab.rb with root privileges:

# Allow Prometheus server (192.168.1.50) to scrape metrics
gitlab_rails['monitoring_whitelist'] = ['127.0.0.0/8', '192.168.1.50/32']

# Exporters for Sidekiq and Puma web server
sidekiq['listen_address'] = "0.0.0.0"
sidekiq['listen_port'] = 8082

puma['exporter_enabled'] = true
puma['exporter_address'] = "0.0.0.0"
puma['exporter_port'] = 8083

# Node exporter to collect OS metrics (CPU, RAM, Disk)
node_exporter['enable'] = true
node_exporter['listen_address'] = '0.0.0.0:9100'

# Gitaly metrics (measure Git operation load)
gitaly['prometheus_listen_addr'] = "0.0.0.0:9236"

Save the file and apply the changes:

sudo gitlab-ctl reconfigure

Step 2: Configure Scrape Jobs on the Prometheus Server

Add the corresponding scrape jobs to the prometheus.yml file on your dedicated monitoring cluster. Assuming your GitLab server’s IP address is 192.168.1.100:

scrape_configs:
  - job_name: 'gitlab-system'
    scrape_interval: 15s
    static_configs:
      - targets: ['192.168.1.100:9100']

  - job_name: 'gitlab-sidekiq'
    scrape_interval: 15s
    static_configs:
      - targets: ['192.168.1.100:8082']

  - job_name: 'gitlab-puma'
    scrape_interval: 15s
    static_configs:
      - targets: ['192.168.1.100:8083']

  - job_name: 'gitlab-gitaly'
    scrape_interval: 15s
    static_configs:
      - targets: ['192.168.1.100:9236']

Reload the configuration without restarting the service:

curl -X POST http://localhost:9090/-/reload

Step 3: Import Dashboards into Grafana

In Grafana, navigate to Dashboards → New → Import. Enter dashboard ID 13624 (GitLab Omnibus Service Metrics) or 4090 (GitLab Overview). Instantly, you’ll have real-time visibility into CPU, memory usage, Sidekiq queue states, and Git request volumes.

Real-World Bottlenecks: 3 Culprits Behind GitLab Sluggishness

Every Sysadmin or DevOps engineer has likely run into this scenario. Around 9 AM, Slack starts blowing up with complaints: “Why is git clone hanging?” or “I triggered a CI/CD pipeline and the runner won’t pick it up!”. You SSH into the server, run top, and see CPU usage hovering lazily around 25–30%. The server isn’t CPU-bound at all. So where is the bottleneck?

1. Sidekiq Job Backlog

GitLab offloads most resource-intensive background tasks to Sidekiq—from sending notification emails and computing Merge Request diffs to scheduling CI pipelines. When 50 developers push code simultaneously or trigger a wave of pre-release commits, Redis gets flooded with pending jobs.

The symptoms are unmistakable: developers push code successfully, but the web UI doesn’t show the new commits, and pipelines sit delayed for 15 to 30 minutes.

Three key metrics to monitor closely:

  • sidekiq_queue_size: The number of jobs queued and waiting to run.
  • sidekiq_running_jobs: The number of jobs currently being processed by workers.
  • sidekiq_jobs_completion_seconds_count: The system’s job completion throughput.

PromQL query to identify queues with more than 200 pending jobs:

sum(sidekiq_queue_size) by (name) > 200

2. Gitaly RPC Latency Spikes Caused by Disk I/O Saturation

Gitaly is the service responsible for all read and write operations against repository directories on disk. Every git fetch, git push, or commit history browse in the UI translates into RPC calls routed to Gitaly.

Sudden latency spikes usually stem from two causes. First, repositories balloon in size when developers mistakenly commit multi-hundred-megabyte binaries (such as .apk or .tar.gz build artifacts). Second, aggressive CI/CD scripts polling with git fetch every 30 seconds exhaust disk IOPS. As a result, git-upload-pack processes pile up waiting on disk I/O.

Crucial Gitaly metrics to track:

  • gitaly_service_client_requests_total: Total volume of RPC requests sent to Gitaly.
  • gitaly_smarthttp_max_concurrent_streams: Concurrent Git-over-HTTP connection load.
  • rate(gitaly_service_client_request_duration_seconds_sum[5m]) / rate(gitaly_service_client_request_duration_seconds_count[5m]): Average response time per RPC call.

Fire an alert when average Git operations take longer than 2 seconds:

rate(gitaly_service_client_request_duration_seconds_sum[5m]) 
/
rate(gitaly_service_client_request_duration_seconds_count[5m]) > 2

3. Puma Connection Pool Exhaustion (HTTP 502 Bad Gateway)

Puma operates on a multi-worker, multi-threaded architecture. When heavy requests come in—such as opening a massive Merge Request spanning 12,000 lines of code—worker threads get blocked rendering diffs.

When these requests surpass capacity, every worker becomes occupied. Subsequent user requests will immediately fail with 502 Bad Gateway or 504 Gateway Timeout errors.

Formula to monitor Puma thread saturation:

puma_active_connections / puma_max_threads > 0.85

If this ratio consistently exceeds 0.85 for more than 3 minutes, your Puma cluster is on the verge of connection exhaustion.

Centralizing Prometheus and Setting Up Alert Rules

For GitLab deployments serving more than 50 engineers, you should disable the bundled internal Prometheus in the Omnibus package. Running the monitoring stack on the same host consumes 1.5 GB to 3 GB of RAM and directly competes for disk I/O with PostgreSQL and Gitaly.

Disabling GitLab’s Internal Monitoring Stack

Offload metrics collection to a dedicated Prometheus server by updating /etc/gitlab/gitlab.rb:

prometheus['enable'] = false
alertmanager['enable'] = false
grafana['enable'] = false

Execute sudo gitlab-ctl reconfigure to instantly free up several gigabytes of system memory.

Setting Up Production-Ready Alert Rules

Create /etc/prometheus/rules/gitlab_alerts.yml on your Prometheus server to route alerts to Telegram or Slack:

groups:
  - name: gitlab_alerts
    rules:
      - alert: GitLabSidekiqQueueBacklog
        expr: sum(sidekiq_queue_size{name=~"default|pipeline_processing:build"}) > 300
        for: 3m
        labels:
          severity: critical
        annotations:
          summary: "GitLab Sidekiq queue backlog detected"
          description: "Queue {{ $labels.name }} has exceeded 300 jobs continuously for 3 minutes."

      - alert: GitLabGitalySlowRPC
        expr: rate(gitaly_service_client_request_duration_seconds_sum[5m]) / rate(gitaly_service_client_request_duration_seconds_count[5m]) > 3
        for: 2m
        labels:
          severity: warning
        annotations:
          summary: "Git operations are responding very slowly"
          description: "Gitaly Git operation processing time exceeded 3 seconds for over 2 minutes."

      - alert: GitLabHostLowMemory
        expr: (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes > 0.90
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "GitLab server running low on memory"
          description: "Available RAM has dropped below 10% for the past 5 minutes."

Hard-Won Lessons from Production Operations

Our team’s GitLab cluster previously supported over 80 engineers with constant commit traffic. Thanks to this monitoring stack, we preempted multiple outages before developers ever noticed an issue. Here are 4 production tips you should implement immediately:

  • Dedicate dedicated workers for Sidekiq: By default, GitLab pools all background tasks together. You should set sidekiq['concurrency'] = 25 and enable sidekiq['queue_selector'] = true. This isolates CI/CD pipeline workers from email dispatch and repository housekeeping jobs.
  • Lock down metrics ports with UFW: Ports 8082, 8083, 9236, and 9100 expose internal system metrics. Restrict access exclusively to your Prometheus server’s IP: sudo ufw allow from 192.168.1.50 to any port 9100 proto tcp.
  • Always check %iowait when git clone feels slow: When Gitaly latency spikes while CPU remains idle, inspect the rate(node_disk_io_time_seconds_total[5m]) metric immediately. Over 90% of performance slowdowns on budget cloud VPS providers trace back to exhausted shared disk IOPS (often capped at just 300–500 IOPS).
  • Prune repositories using Git LFS: When a repository triggers sudden Gitaly I/O surges, have the team run git-filter-repo to extract oversized binary files. Then, configure Git LFS backed by MinIO or AWS S3 to offload storage burden from your server disks.
Share: