---
title: "GitLab integration | Grafana Cloud documentation"
description: "Learn about GitLab Grafana Cloud integration."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# GitLab integration for Grafana Cloud

GitLab is an open-source DevOps platform for software development. The GitLab integration uses Grafana Alloy to collect metrics for monitoring a GitLab EE (Enterprise Edition) instance, including aspects such as HTTP request rates, HTTP request latencies, and CI pipeline creation rates. The integration also supports the rails error logs being scraped by Alloy using Promtail. An accompanying dashboard is provided to visualize these metrics and logs.

This integration supports GitLab EE 15.3.3+.

This integration includes 4 useful alerts and 1 pre-built dashboard to help monitor and visualize GitLab metrics and logs.

## Before you begin

In order for the integration to work, you must configure your GitLab EE instance to expose its metrics through it’s built in prometheus metrics server.

It is required to first enable the prometheus metrics as [described in the GitLab documentation](https://docs.gitlab.com/ee/administration/monitoring/prometheus/gitlab_metrics.html).

In order to collect metrics using Alloy, the local IP must be added to the monitoring whitelist in `/etc/gitlab/gitlab.rb`:

ruby ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```ruby
gitlab_rails['monitoring_whitelist'] = ['127.0.0.0/8']
```

Then, GitLab must be restarted for the above change to take effect:

sh ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```sh
sudo gitlab-ctl restart
```

## Install GitLab integration for Grafana Cloud

1. In your Grafana Cloud stack, click **Connections** in the left-hand menu.
2. Find **GitLab** and click its tile to open the integration.
3. Review the prerequisites in the **Configuration Details** tab and set up Grafana Alloy to send GitLab metrics and logs to your Grafana Cloud instance.
4. Click **Install** to add this integration’s pre-built dashboard and alerts to your Grafana Cloud instance, and you can start monitoring your GitLab setup.

## Configuration snippets for Grafana Alloy

### Simple mode

These snippets are configured to scrape a single GitLab instance running locally with default ports.

First, **manually** copy and append the following snippets into your alloy configuration file.

### Metrics snippets

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
discovery.relabel "metrics_integrations_integrations_gitlab" {
	targets = [{
		__address__ = "localhost:80",
	}]

	rule {
		target_label = "instance"
		replacement  = constants.hostname
	}
}

prometheus.scrape "metrics_integrations_integrations_gitlab" {
	targets      = discovery.relabel.metrics_integrations_integrations_gitlab.output
	forward_to   = [prometheus.remote_write.metrics_service.receiver]
	job_name     = "integrations/gitlab"
	metrics_path = "/-/metrics"
}
```

### Logs snippets

#### linux

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
local.file_match "logs_integrations_integrations_gitlab" {
	path_targets = [{
		__address__ = "localhost",
		__path__    = "/var/log/gitlab/gitlab-rails/exceptions_json.log",
		instance    = constants.hostname,
		job         = "integrations/gitlab",
	}]
}

loki.process "logs_integrations_integrations_gitlab" {
	forward_to = [loki.write.grafana_cloud_loki.receiver]

	stage.match {
		selector            = "{job=\"integrations/gitlab\"} |~ \"^#\""
		action              = "drop"
		drop_counter_reason = "gitlab_comment_line"
	}
}

loki.source.file "logs_integrations_integrations_gitlab" {
	targets    = local.file_match.logs_integrations_integrations_gitlab.targets
	forward_to = [loki.process.logs_integrations_integrations_gitlab.receiver]
}
```

### Advanced mode

The following snippets provide examples to guide you through the configuration process.

To instruct Grafana Alloy to scrape your GitLab instances, **manually** copy and append the snippets to your alloy configuration file, then follow subsequent instructions.

### Advanced metrics snippets

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
discovery.relabel "metrics_integrations_integrations_gitlab" {
	targets = [{
		__address__ = "localhost:80",
	}]

	rule {
		target_label = "instance"
		replacement  = constants.hostname
	}
}

prometheus.scrape "metrics_integrations_integrations_gitlab" {
	targets      = discovery.relabel.metrics_integrations_integrations_gitlab.output
	forward_to   = [prometheus.remote_write.metrics_service.receiver]
	job_name     = "integrations/gitlab"
	metrics_path = "/-/metrics"
}
```

To monitor your GitLab instance, you must use a [discovery.relabel](/docs/alloy/latest/reference/components/discovery.relabel/) component to discover your GitLab Prometheus endpoint and apply appropriate labels, followed by a [prometheus.scrape](/docs/alloy/latest/reference/components/prometheus.scrape) component to scrape it.

Configure the following properties within each `discovery.relabel` component:

- `__address__`: The address to your GitLab Prometheus metrics endpoint.
- `instance` label: `constants.hostname` sets the `instance` label to your Grafana Alloy server hostname. If that is not suitable, change it to a value uniquely identifies this GitLab instance. Make sure this label value is the same for all telemetry data collected for this instance.

If you have multiple GitLab servers to scrape, configure one `discovery.relabel` for each and scrape them by including each under `targets` within the `prometheus.scrape` component.

### Advanced logs snippets

#### linux

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
local.file_match "logs_integrations_integrations_gitlab" {
	path_targets = [{
		__address__ = "localhost",
		__path__    = "/var/log/gitlab/gitlab-rails/exceptions_json.log",
		instance    = constants.hostname,
		job         = "integrations/gitlab",
	}]
}

loki.process "logs_integrations_integrations_gitlab" {
	forward_to = [loki.write.grafana_cloud_loki.receiver]

	stage.match {
		selector            = "{job=\"integrations/gitlab\"} |~ \"^#\""
		action              = "drop"
		drop_counter_reason = "gitlab_comment_line"
	}
}

loki.source.file "logs_integrations_integrations_gitlab" {
	targets    = local.file_match.logs_integrations_integrations_gitlab.targets
	forward_to = [loki.process.logs_integrations_integrations_gitlab.receiver]
}
```

To monitor your GitLab instance logs, you will use a combination of the following components:

- [local.file\_match](/docs/alloy/latest/reference/components/local.file_match) defines where to find the log file to be scraped. Change the following properties according to your environment:
  
  - `__address__`: The GitLab instance address
  - `__path__`: The path to the log file.
  - `instance` label: `constants.hostname` sets the `instance` label to your Grafana Alloy server hostname. If that is not suitable, change it to a value uniquely identifies this GitLab instance. Make sure this label value is the same for all telemetry data collected for this instance.
- [loki.process](/docs/alloy/latest/reference/components/loki.process) defines how to process logs before sending it to Loki.
- [loki.source.file](/docs/alloy/latest/reference/components/loki.source.file) sends logs to Loki.

## Kubernetes instructions

Instructions for Kubernetes

### Before you begin with Kubernetes

**Please note**: These instructions assume the use of the [Kubernetes Monitoring Helm chart](https://github.com/grafana/k8s-monitoring-helm)

In order for the integration to work, you must configure your GitLab EE instance to expose its metrics through it’s built in prometheus metrics server.

It is required to first enable the prometheus metrics as [described in the GitLab documentation](https://docs.gitlab.com/ee/administration/monitoring/prometheus/gitlab_metrics.html).

In order to collect metrics using the agent, the IP range used in your Kubernetes cluster must be added to the monitoring whitelist in `/etc/gitlab/gitlab.rb` for the Alloy deployment in the Kubernetes Helm Chart to be allowed to scrape. As an example:

ruby ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```ruby
gitlab_rails['monitoring_whitelist'] = ['10.0.0.0/8']
```

Then, GitLab must be restarted for the above change to take effect:

sh ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```sh
sudo gitlab-ctl restart
```

### Configuration snippets for Kubernetes Helm chart

The following snippets provide examples to guide you through the configuration process.

To scrape your Gitlab instances, **manually** modify your Kubernetes Monitoring Helm chart with these configuration snippets.

Replace any values between the angle brackets `<>` in the provided snippets with your desired configuration values.

#### Metrics snippets

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
alloy-metrics:
    extraConfig: |-
        discovery.kubernetes "gitlab" {
            role = "pod"
            selectors {
                role = "pod"
                label = "<gitlab_pod_label_name>=<gitlab_pod_label_value>"
            }
        }
        
        discovery.relabel "gitlab" {
            targets = discovery.kubernetes.gitlab.targets
            rule {
                source_labels = ["__meta_kubernetes_pod_container_port_number"]
                regex = "<gitlab_prometheus_port_number>"
                action = "keep"
            }
            rule {
                source_labels = ["__meta_kubernetes_namespace", "__meta_kubernetes_pod_container_name"]
                separator = "-"
                target_label = "instance"
            }       
        }
        
        prometheus.scrape "gitlab" {
            targets      = discovery.relabel.gitlab.output
            metrics_path = "/-/metrics"
            job_name     = "integrations/gitlab"
            honor_labels = true
            forward_to   = [prometheus.remote_write.metrics_service.receiver]
        }
```

#### Logs snippets

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
podLogs:
    extraDiscoveryRules: |-
        rule {
            source_labels = ["__meta_kubernetes_pod_label_<gitlab_pod_label>", "__meta_kubernetes_pod_container_port_number"]
            separator     = ":"
            regex         = "<activemq_pod_label_value>:<gitlab_prometheus_port_number>"
            replacement   = "gitlab"
            target_label  = "integration"
        }

    extraLogProcessingStages: |-
        stage.match {
            selector = "{integration=\\"gitlab\\"}"

            stage.drop {
                expression = "^([^{}].*)?$"
            }
    
            stage.regex {
                expression = \`^\\{\"severity\":\"(?P<severity>ERROR)\",\"time\":\"(?P<time>[^\"]+)\",\"correlation_id\":\"(?P<correlation_id>[^\"]+)\",\"exception.class\":\"(?P<exception_class>[^\"]+)\",.*$\`
            }
    
            stage.labels {
                values = {
                    severity = "",
                    time = "",
                    correlation_id = "",
                    exception_class = "",
                }
            }
    
            stage.match {
                selector = \`{exception_class=\"\"}\`
                action = "drop"
            }

            stage.template {
                source   = "instance"
                template = "{{ .namespace }}-{{ .container }}"
            }

            stage.static_labels {
                values = {
                    job = "integrations/gitlab",
                }
            }
        }
```

## Dashboards

The GitLab integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.

- GitLab Overview

**GitLab overview dashboard 1**

**GitLab overview dashboard 2**

**GitLab overview dashboard 3**

## Alerts

The GitLab integration includes the following useful alerts:

Expand table

| Alert                             | Description                                                     |
|-----------------------------------|-----------------------------------------------------------------|
| GitLabHighJobRegistrationFailures | Warning: Large percentage of failed attempts to register a job. |
| GitLabHighRunnerAuthFailure       | Warning: Large percentage of runner authentication failures.    |
| GitLabHigh5xxResponses            | Critical: Large rate of HTTP 5XX errors.                        |
| GitLabHigh4xxResponses            | Warning: Large rate of HTTP 4XX errors.                         |

## Metrics

The most important metrics provided by the GitLab integration, which are used on the pre-built dashboard and Prometheus alerts, are as follows:

- gitlab\_ci\_active\_jobs\_sum
- gitlab\_ci\_pipeline\_size\_builds\_sum
- gitlab\_ci\_runner\_authentication\_failure\_total
- gitlab\_ci\_runner\_authentication\_success\_total
- gitlab\_ci\_trace\_operations\_total
- gitlab\_rails\_boot\_time\_seconds
- http\_request\_duration\_seconds\_count
- http\_request\_duration\_seconds\_sum
- http\_requests\_total
- job\_register\_attempts\_failed\_total
- job\_register\_attempts\_total
- pipelines\_created\_total
- up
- user\_session\_logins\_total

## Changelog

md ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```md
# 1.0.0 - October 2023

* Added Grafana Agent Operator configuration snippet to support Gitlab in kubernetes cluster
* Added cluster selector to dashboard for kubernetes support

# 0.0.3 - September 2023

* New Filter Metrics option for configuring the Grafana Agent, which saves on metrics cost by dropping any metric not used by this integration. Beware that anything custom built using metrics that are not on the snippet will stop working.
* New hostname relabel option, which applies the instance name you write on the text box to the Grafana Agent configuration snippets, making it easier and less error prone to configure this mandatory label.

# 0.0.2 - August 2023

* Add regex filter for logs datasource

# 0.0.1 - November 2022

* Initial Release
```

## Cost

By connecting your GitLab instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see [Active series and dpm usage](/docs/grafana-cloud/fundamentals/active-series-and-dpm/) and [Cloud tier pricing](/products/cloud/pricing/).
