debian-mirror-gitlab/doc/user/project/integrations/prometheus.md

264 lines
12 KiB
Markdown
Raw Normal View History

2020-05-24 23:13:21 +05:30
---
stage: Monitor
2021-04-29 21:17:54 +05:30
group: Monitor
2021-02-22 17:27:13 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-05-24 23:13:21 +05:30
---
2021-03-11 19:13:27 +05:30
# Prometheus integration **(FREE)**
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/8935) in GitLab 9.0.
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
GitLab offers powerful integration with [Prometheus](https://prometheus.io) for
monitoring key metrics of your apps, directly in GitLab.
2018-03-17 18:26:18 +05:30
Metrics for each environment are retrieved from Prometheus, and then displayed
2021-03-11 19:13:27 +05:30
in the GitLab interface.
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
![Environment Dashboard](img/prometheus_dashboard.png)
2017-08-17 22:00:37 +05:30
2018-12-05 23:21:45 +05:30
There are two ways to set up Prometheus integration, depending on where your apps are running:
2019-03-02 22:35:43 +05:30
- For deployments on Kubernetes, GitLab can automatically [deploy and manage Prometheus](#managed-prometheus-on-kubernetes).
2021-03-11 19:13:27 +05:30
- For other deployment targets, [specify the Prometheus server](#manual-configuration-of-prometheus).
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
Once enabled, GitLab detects metrics from known services in the
[metric library](prometheus_library/index.md). You can also
[add your own metrics](../../../operations/metrics/index.md#adding-custom-metrics) and create
2020-07-28 23:09:34 +05:30
[custom dashboards](../../../operations/metrics/dashboards/index.md).
2018-03-27 19:54:05 +05:30
## Enabling Prometheus Integration
### Managed Prometheus on Kubernetes
2019-09-30 21:07:59 +05:30
2020-06-23 00:09:42 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/28916) in GitLab 10.5.
2017-08-17 22:00:37 +05:30
2021-04-29 21:17:54 +05:30
**Deprecated:** Managed Prometheus on Kubernetes is deprecated, and
scheduled for removal in [GitLab
14.0](https://gitlab.com/groups/gitlab-org/-/epics/4280).
2021-03-11 19:13:27 +05:30
GitLab can seamlessly deploy and manage Prometheus on a
[connected Kubernetes cluster](../clusters/index.md), to help you monitor your apps.
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
#### Requirements
2017-09-10 17:25:29 +05:30
2019-03-02 22:35:43 +05:30
- A [connected Kubernetes cluster](../clusters/index.md)
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
#### Getting started
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
After you have a connected Kubernetes cluster, you can deploy a managed Prometheus with a single click.
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
1. Go to the **Operations > Kubernetes** page to view your connected clusters
2018-03-17 18:26:18 +05:30
1. Select the cluster you would like to deploy Prometheus to
1. Click the **Install** button to deploy Prometheus to the cluster
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
![Managed Prometheus Deploy](img/prometheus_deploy.png)
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
#### About managed Prometheus deployments
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
Prometheus is deployed into the `gitlab-managed-apps` namespace, using the
[official Helm chart](https://github.com/helm/charts/tree/master/stable/prometheus).
Prometheus is only accessible in the cluster, with GitLab communicating through the
[Kubernetes API](https://kubernetes.io/docs/concepts/overview/kubernetes-api/).
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
The Prometheus server
[automatically detects and monitors](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config)
nodes, pods, and endpoints. To configure a resource to be monitored by Prometheus,
set the following [Kubernetes annotations](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/):
2019-02-15 15:39:39 +05:30
2019-03-02 22:35:43 +05:30
- `prometheus.io/scrape` to `true` 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`.
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
CPU and Memory consumption is monitored, but requires
[naming conventions](prometheus_library/kubernetes.md#specifying-the-environment)
to determine the environment. If you are using
[Auto DevOps](../../../topics/autodevops/index.md), this is handled automatically.
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
The [NGINX Ingress](../clusters/index.md#installing-applications) that is deployed
by GitLab to clusters, is automatically annotated for monitoring providing key
response metrics: latency, throughput, and error rates.
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
##### Example of Kubernetes service annotations and labels
As an example, to activate Prometheus monitoring of a service:
1. Add at least this annotation: `prometheus.io/scrape: 'true'`.
1. Add two labels so GitLab can retrieve metrics dynamically for any environment:
- `application: ${CI_ENVIRONMENT_SLUG}`
- `release: ${CI_ENVIRONMENT_SLUG}`
1. Create a dynamic PromQL query. For example, a query like
`temperature{application="{{ci_environment_slug}}",release="{{ci_environment_slug}}"}` to either:
- Add [custom metrics](../../../operations/metrics/index.md#adding-custom-metrics).
- Add [custom dashboards](../../../operations/metrics/dashboards/index.md).
The following is a service definition to accomplish this:
```yaml
---
# 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}
```
2021-01-29 00:20:46 +05:30
#### 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:
1. 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:
```shell
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:
```plaintext
gitlab-managed-apps prometheus-prometheus-server-55b4bd64c9-dpc6b 2/2 Running 0 71d
```
1. Run a `kubectl port-forward` command. In the following example, `9090` is the
Prometheus server's listening port:
```shell
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's `9090` port
to the `9090` port of the Prometheus pod. If the `9090` 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 port `8080` of your local system, change the
command to:
```shell
kubectl port-forward prometheus-prometheus-server-55b4bd64c9-dpc6b 8080:9090 -n gitlab-managed-apps
```
1. 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:
```shell
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
```
2018-03-27 19:54:05 +05:30
### Manual configuration of Prometheus
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
#### Requirements
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
Integration with Prometheus requires the following:
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
1. GitLab 9.0 or higher
2019-02-15 15:39:39 +05:30
1. Prometheus must be configured to collect one of the [supported metrics](prometheus_library/index.md)
2018-03-17 18:26:18 +05:30
1. Each metric must be have a label to indicate the environment
1. GitLab must have network connectivity to the Prometheus server
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
#### Getting started
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
Installing and configuring Prometheus to monitor applications is fairly straightforward.
2017-08-17 22:00:37 +05:30
2019-09-30 21:07:59 +05:30
1. [Install Prometheus](https://prometheus.io/docs/prometheus/latest/installation/)
2019-02-15 15:39:39 +05:30
1. Set up one of the [supported monitoring targets](prometheus_library/index.md)
2021-03-11 19:13:27 +05:30
1. Configure the Prometheus server to
[collect their metrics](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config)
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
#### Configuration in GitLab
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
The actual configuration of Prometheus integration in GitLab
2021-02-22 17:27:13 +05:30
requires the domain name or IP address of the Prometheus server you'd like
2020-07-28 23:09:34 +05:30
to integrate with. If the Prometheus resource is secured with Google's Identity-Aware Proxy (IAP),
2021-03-11 19:13:27 +05:30
you can pass information like Client ID and Service Account credentials.
GitLab can use these to access the resource. More information about authentication from a
2020-07-28 23:09:34 +05:30
service account can be found at Google's documentation for
[Authenticating from a service account](https://cloud.google.com/iap/docs/authentication-howto#authenticating_from_a_service_account).
1. Navigate to the [Integrations page](overview.md#accessing-integrations) at
2020-10-24 23:57:45 +05:30
**Settings > Integrations**.
2020-04-08 14:13:33 +05:30
1. Click the **Prometheus** service.
2020-07-28 23:09:34 +05:30
1. For **API URL**, provide the domain name or IP address of your server, such as
`http://prometheus.example.com/` or `http://192.0.2.1/`.
1. (Optional) In **Google IAP Audience Client ID**, provide the Client ID of the
Prometheus OAuth Client secured with Google IAP.
1. (Optional) In **Google IAP Service Account JSON**, provide the contents of the
Service Account credentials file that is authorized to access the Prometheus resource.
2021-02-11 23:33:58 +05:30
The JSON key `token_credential_uri` is discarded to prevent
[Server-side Request Forgery (SSRF)](https://www.hackerone.com/blog-How-To-Server-Side-Request-Forgery-SSRF).
2020-04-08 14:13:33 +05:30
1. Click **Save changes**.
2017-08-17 22:00:37 +05:30
2020-07-28 23:09:34 +05:30
![Configure Prometheus Service](img/prometheus_manual_configuration_v13_2.png)
2017-08-17 22:00:37 +05:30
2020-04-08 14:13:33 +05:30
#### Thanos configuration in GitLab
You can configure [Thanos](https://thanos.io/) as a drop-in replacement for Prometheus
2021-03-11 19:13:27 +05:30
with GitLab. Use the domain name or IP address of the Thanos server you'd like
2020-04-08 14:13:33 +05:30
to integrate with.
2020-04-22 19:07:51 +05:30
1. Navigate to the [Integrations page](overview.md#accessing-integrations).
2020-04-08 14:13:33 +05:30
1. Click the **Prometheus** service.
2021-03-11 19:13:27 +05:30
1. Provide the domain name or IP address of your server, for example
`http://thanos.example.com/` or `http://192.0.2.1/`.
2020-04-08 14:13:33 +05:30
1. Click **Save changes**.
2020-05-24 23:13:21 +05:30
### Precedence with multiple Prometheus configurations
Although you can enable both a [manual configuration](#manual-configuration-of-prometheus)
2021-02-22 17:27:13 +05:30
and [auto configuration](#managed-prometheus-on-kubernetes) of Prometheus, you
can use only one:
2020-05-24 23:13:21 +05:30
- If you have enabled a
[Prometheus manual configuration](#manual-configuration-of-prometheus)
and a [managed Prometheus on Kubernetes](#managed-prometheus-on-kubernetes),
the manual configuration takes precedence and is used to run queries from
2020-10-24 23:57:45 +05:30
[custom dashboards](../../../operations/metrics/dashboards/index.md) and
[custom metrics](../../../operations/metrics/index.md#adding-custom-metrics).
2020-05-24 23:13:21 +05:30
- 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](../../instance/clusters/index.md#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](../../../ci/environments/index.md#scoping-environments-with-specs) is used.
2017-08-17 22:00:37 +05:30
## Determining the performance impact of a merge
2020-04-22 19:07:51 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/10408) in GitLab 9.2.
2020-06-23 00:09:42 +05:30
> - GitLab 9.3 added the [numeric comparison](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/27439) of the 30 minute averages.
2017-08-17 22:00:37 +05:30
2021-03-11 19:13:27 +05:30
Developers can view the performance impact of their changes in the merge
2021-01-03 14:25:43 +05:30
request workflow. This feature requires [Kubernetes](prometheus_library/kubernetes.md) metrics.
2019-12-04 20:38:33 +05:30
When a source branch has been deployed to an environment, a sparkline and
2021-02-22 17:27:13 +05:30
numeric comparison of the average memory consumption displays. On the
2019-12-04 20:38:33 +05:30
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.
2017-08-17 22:00:37 +05:30
2021-02-22 17:27:13 +05:30
Once merged and the target branch has been redeployed, the metrics switches
2017-08-17 22:00:37 +05:30
to show the new environments this revision has been deployed to.
2021-02-22 17:27:13 +05:30
Performance data is available for the duration it is persisted on the
2017-08-17 22:00:37 +05:30
Prometheus server.
![Merge Request with Performance Impact](img/merge_request_performance.png)