Prometheus integration
Introduced in GitLab 9.0.
GitLab offers powerful integration with Prometheus for monitoring key metrics of your apps, directly within GitLab. Metrics for each environment are retrieved from Prometheus, and then displayed within the GitLab interface.
There are two ways to set up Prometheus integration, depending on where your apps are running:
- For deployments on Kubernetes, GitLab can automatically deploy and manage Prometheus.
- For other deployment targets, simply specify the Prometheus server.
Once enabled, GitLab detects metrics from known services in the metric library. You can also add your own metrics and create custom dashboards.
Enabling Prometheus Integration
Managed Prometheus on Kubernetes
Introduced in GitLab 10.5.
GitLab can seamlessly deploy and manage Prometheus on a connected Kubernetes cluster, making monitoring of your apps easy.
Requirements
Getting started
Once you have a connected Kubernetes cluster, deploying a managed Prometheus is as easy as a single click.
- Go to the Operations > Kubernetes page to view your connected clusters
- Select the cluster you would like to deploy Prometheus to
- Click the Install button to deploy Prometheus to the cluster
About managed Prometheus deployments
Prometheus is deployed into the gitlab-managed-apps
namespace, using the official Helm chart. Prometheus is only accessible within the cluster, with GitLab communicating through the Kubernetes API.
The Prometheus server automatically detects and monitors nodes, pods, and endpoints. To configure a resource to be monitored by Prometheus, simply set the following Kubernetes annotations:
-
prometheus.io/scrape
totrue
to enable monitoring of the resource. -
prometheus.io/port
to define the port of the metrics endpoint. -
prometheus.io/path
to define the path of the metrics endpoint. Defaults to/metrics
.
CPU and Memory consumption is monitored, but requires naming conventions in order to determine the environment. If you are using Auto DevOps, this is handled automatically.
The NGINX Ingress that is deployed by GitLab to clusters, is automatically annotated for monitoring providing key response metrics: latency, throughput, and error rates.
Example of Kubernetes service annotations and labels
As an example, to activate Prometheus monitoring of a service:
- Add at least this annotation:
prometheus.io/scrape: 'true'
. - Add two labels so GitLab can retrieve metrics dynamically for any environment:
application: ${CI_ENVIRONMENT_SLUG}
release: ${CI_ENVIRONMENT_SLUG}
- Create a dynamic PromQL query. For example, a query like
temperature{application="{{ci_environment_slug}}",release="{{ci_environment_slug}}"}
to either:- Add custom metrics.
- Add custom dashboards.
The following is a service definition to accomplish this:
---
# Service
apiVersion: v1
kind: Service
metadata:
name: service-${CI_PROJECT_NAME}-${CI_COMMIT_REF_SLUG}
# === Prometheus annotations ===
annotations:
prometheus.io/scrape: 'true'
labels:
application: ${CI_ENVIRONMENT_SLUG}
release: ${CI_ENVIRONMENT_SLUG}
# === End of Prometheus ===
spec:
selector:
app: ${CI_PROJECT_NAME}
ports:
- port: ${EXPOSED_PORT}
targetPort: ${CONTAINER_PORT}
Access the UI of a Prometheus managed application in Kubernetes
You can connect directly to Prometheus, and view the Prometheus user interface, when using a Prometheus managed application in Kubernetes:
-
Find the name of the Prometheus pod in the user interface of your Kubernetes provider, such as GKE, or by running the following
kubectl
command in your terminal:kubectl get pods -n gitlab-managed-apps | grep 'prometheus-prometheus-server'
The command should return a result like the following example, where
prometheus-prometheus-server-55b4bd64c9-dpc6b
is the name of the Prometheus pod:gitlab-managed-apps prometheus-prometheus-server-55b4bd64c9-dpc6b 2/2 Running 0 71d
-
Run a
kubectl port-forward
command. In the following example,9090
is the Prometheus server's listening port:kubectl port-forward prometheus-prometheus-server-55b4bd64c9-dpc6b 9090:9090 -n gitlab-managed-apps
The
port-forward
command forwards all requests sent to your system's9090
port to the9090
port of the Prometheus pod. If the9090
port on your system is used by another application, you can change the port number before the colon to your desired port. For example, to forward port8080
of your local system, change the command to:kubectl port-forward prometheus-prometheus-server-55b4bd64c9-dpc6b 8080:9090 -n gitlab-managed-apps
-
Open
localhost:9090
in your browser to display the Prometheus user interface.
Script access to Prometheus
You can script the access to Prometheus, extracting the name of the pod automatically like this:
POD_INFORMATION=$(kubectl get pods -n gitlab-managed-apps | grep 'prometheus-prometheus-server')
POD_NAME=$(echo $POD_INFORMATION | awk '{print $1;}')
kubectl port-forward $POD_NAME 9090:9090 -n gitlab-managed-apps
Manual configuration of Prometheus
Requirements
Integration with Prometheus requires the following:
- GitLab 9.0 or higher
- Prometheus must be configured to collect one of the supported metrics
- Each metric must be have a label to indicate the environment
- GitLab must have network connectivity to the Prometheus server
Getting started
Installing and configuring Prometheus to monitor applications is fairly straightforward.
- Install Prometheus
- Set up one of the supported monitoring targets
- Configure the Prometheus server to collect their metrics
Configuration in GitLab
The actual configuration of Prometheus integration within GitLab requires the domain name or IP address of the Prometheus server you'd like to integrate with. If the Prometheus resource is secured with Google's Identity-Aware Proxy (IAP), additional information like Client ID and Service Account credentials can be passed which GitLab can use to access the resource. More information about authentication from a service account can be found at Google's documentation for Authenticating from a service account.
- Navigate to the Integrations page at Settings > Integrations.
- Click the Prometheus service.
- For API URL, provide the domain name or IP address of your server, such as
http://prometheus.example.com/
orhttp://192.0.2.1/
. - (Optional) In Google IAP Audience Client ID, provide the Client ID of the Prometheus OAuth Client secured with Google IAP.
- (Optional) In Google IAP Service Account JSON, provide the contents of the Service Account credentials file that is authorized to access the Prometheus resource.
- Click Save changes.
Thanos configuration in GitLab
You can configure Thanos as a drop-in replacement for Prometheus with GitLab, using the domain name or IP address of the Thanos server you'd like to integrate with.
- Navigate to the Integrations page.
- Click the Prometheus service.
- Provide the domain name or IP address of your server, for example
http://thanos.example.com/
orhttp://192.0.2.1/
. - Click Save changes.
Precedence with multiple Prometheus configurations
Although you can enable both a manual configuration and auto configuration of Prometheus, you can use only one:
- If you have enabled a Prometheus manual configuration and a managed Prometheus on Kubernetes, the manual configuration takes precedence and is used to run queries from custom dashboards and custom metrics.
- If you have managed Prometheus applications installed on Kubernetes clusters at different levels (project, group, instance), the order of precedence is described in Cluster precedence.
- If you have managed Prometheus applications installed on multiple Kubernetes clusters at the same level, the Prometheus application of a cluster with a matching environment scope is used.
Determining the performance impact of a merge
- Introduced in GitLab 9.2.
- GitLab 9.3 added the numeric comparison of the 30 minute averages.
Developers can view the performance impact of their changes within the merge request workflow. This feature requires Kubernetes metrics.
When a source branch has been deployed to an environment, a sparkline and numeric comparison of the average memory consumption displays. On the sparkline, a dot indicates when the current changes were deployed, with up to 30 minutes of performance data displayed before and after. The comparison shows the difference between the 30 minute average before and after the deployment. This information is updated after each commit has been deployed.
Once merged and the target branch has been redeployed, the metrics switches to show the new environments this revision has been deployed to.
Performance data is available for the duration it is persisted on the Prometheus server.