prometheus.md 8.75 KB
Newer Older
1 2
# Prometheus integration

3
> [Introduced][ce-8935] in GitLab 9.0.
4

5
GitLab offers powerful integration with [Prometheus] for monitoring key metrics of your apps, directly within GitLab.
6
Metrics for each environment are retrieved from Prometheus, and then displayed
7 8
within the GitLab interface.

9
![Environment Dashboard](img/prometheus_dashboard.png)
10

11 12 13
There are two ways to setup Prometheus integration, depending on where your apps are running:
* For deployments on Kubernetes, GitLab can automatically [deploy and manage Prometheus](#managed-prometheus-on-kubernetes)
* For other deployment targets, simply [specify the Prometheus server](#manual-configuration-of-prometheus).
14

15 16 17 18 19
Once enabled, GitLab will automatically detect metrics from known services in the [metric library](#monitoring-ci-cd-environments). You are also able to [add your own metrics](#adding-additional-metrics) as well.

## Enabling Prometheus Integration

### Managed Prometheus on Kubernetes
Joshua Lambert's avatar
Joshua Lambert committed
20
> **Note**: [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/28916) in GitLab 10.5
21

22
GitLab can seamlessly deploy and manage Prometheus on a [connected Kubernetes cluster](../clusters/index.md), making monitoring of your apps easy.
23

24
#### Requirements
Joshua Lambert's avatar
Joshua Lambert committed
25

26 27
* A [connected Kubernetes cluster](../clusters/index.md)
* Helm Tiller [installed by GitLab](../clusters/index.md#installing-applications)
28

29
#### Getting started
30

31
Once you have a connected Kubernetes cluster with Helm installed, deploying a managed Prometheus is as easy as a single click.
32

33
1. Go to the `Operations > Kubernetes` page, to view your connected clusters
34 35
1. Select the cluster you would like to deploy Prometheus to
1. Click the **Install** button to deploy Prometheus to the cluster
36

37
![Managed Prometheus Deploy](img/prometheus_deploy.png)
38

39
#### About managed Prometheus deployments
40

41
Prometheus is deployed into the `gitlab-managed-apps` namespace, using the [official Helm chart](https://github.com/kubernetes/charts/tree/master/stable/prometheus). Prometheus is only accessible within the cluster, with GitLab communicating through the [Kubernetes API](https://kubernetes.io/docs/concepts/overview/kubernetes-api/).
42

43 44 45 46
The Prometheus server will [automatically detect and monitor](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Ckubernetes_sd_config%3E) nodes, pods, and endpoints. To configure a resource to be monitored by Prometheus, simply set the following [Kubernetes annotations](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/):
* `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`.
47

48
CPU and Memory consumption is monitored, but requires [naming conventions](prometheus_library/kubernetes.html#specifying-the-environment) in order to determine the environment. If you are using [Auto DevOps](../../../topics/autodevops/), this is handled automatically.
49

50
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.
51

52
### Manual configuration of Prometheus
53

54
#### Requirements
55

56
Integration with Prometheus requires the following:
57

58 59 60 61
1. GitLab 9.0 or higher
1. Prometheus must be configured to collect one of the [supported metrics](prometheus_library/metrics.md)
1. Each metric must be have a label to indicate the environment
1. GitLab must have network connectivity to the Prometheus server
62

63
#### Getting started
64

65
Installing and configuring Prometheus to monitor applications is fairly straight forward.
66

67 68 69
1. [Install Prometheus](https://prometheus.io/docs/introduction/install/)
1. Set up one of the [supported monitoring targets](prometheus_library/metrics.md)
1. Configure the Prometheus server to [collect their metrics](https://prometheus.io/docs/operating/configuration/#scrape_config)
70

71
#### Configuration in GitLab
72

73 74 75
The actual configuration of Prometheus integration within GitLab is very simple.
All you will need is the DNS or IP address of the Prometheus server you'd like
to integrate with.
76

77 78 79 80 81
1. Navigate to the [Integrations page](project_services.md#accessing-the-project-services)
1. Click the **Prometheus** service
1. Provide the base URL of the your server, for example `http://prometheus.example.com/`.
   The **Test Settings** button can be used to confirm connectivity from GitLab
   to the Prometheus server.
82

83
![Configure Prometheus Service](img/prometheus_service_configuration.png)
84

85 86
## Monitoring CI/CD Environments

87
Once configured, GitLab will attempt to retrieve performance metrics for any
88
environment which has had a successful deployment.
89

90
GitLab will automatically scan the Prometheus server for metrics from known serves like Kubernetes and NGINX, and attempt to identify individual environment. The supported metrics and scan process is detailed in our [Prometheus Metric Library documentation](prometheus_library/metrics.html).
91 92 93

You can view the performance dashboard for an environment by [clicking on the monitoring button](../../../ci/environments.md#monitoring-environments).

Marcia Ramos's avatar
Marcia Ramos committed
94
### Adding additional metrics **[PREMIUM]**
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

> [Introduced](https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/3799) in [GitLab Premium](https://about.gitlab.com/products/) 10.6.

Additional metrics can be monitored by adding them on the Prometheus integration page. Once saved, they will be displayed on the environment performance dashboard.

![Add New Metric](img/prometheus_add_metric.png)

A few fields are required:
* **Name**: Chart title
* **Type**: Type of metric. Metrics of the same type will be shown together.
* **Query**: Valid [PromQL query](https://prometheus.io/docs/prometheus/latest/querying/basics/). Note, no validation is performed at this time. If the query is not valid, the dashboard will display an error.
* **Y-axis label**: Y axis title to display on the dashboard.
* **Unit label**: Query units, for example `req / sec`. Shown next to the value.

#### Query Variables

GitLab supports a limited set of [CI variables] in the Prometheus query. This is particularly useful for identifying a specific environment, for example with `CI_ENVIRONMENT_SLUG`. The supported variables are:

* CI_ENVIRONMENT_SLUG
* KUBE_NAMESPACE
115

116
To specify a variable in a query, enclose it in curly braces with a leading percent. For example: `%{ci_environment_slug}`.
117

118
## Determining the performance impact of a merge
Fatih Acet's avatar
Fatih Acet committed
119

120
> [Introduced][ce-10408] in GitLab 9.2.
121
> GitLab 9.3 added the [numeric comparison](https://gitlab.com/gitlab-org/gitlab-ce/issues/27439) of the 30 minute averages.
122
> Requires [Kubernetes](prometheus_library/kubernetes.md) metrics
Fatih Acet's avatar
Fatih Acet committed
123

124
Developers can view the performance impact of their changes within the merge
125
request workflow. When a source branch has been deployed to an environment, a sparkline and numeric comparison of the average memory consumption will appear. On the sparkline, a dot
126
indicates when the current changes were deployed, with up to 30 minutes of
127
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
128
each commit has been deployed.
Fatih Acet's avatar
Fatih Acet committed
129

130
Once merged and the target branch has been redeployed, the metrics will switch
131
to show the new environments this revision has been deployed to.
132

133 134
Performance data will be available for the duration it is persisted on the
Prometheus server.
135 136

![Merge Request with Performance Impact](img/merge_request_performance.png)
Fatih Acet's avatar
Fatih Acet committed
137

138 139
## Troubleshooting

140
If the "No data found" screen continues to appear, it could be due to:
141

142
- No successful deployments have occurred to this environment.
143 144 145 146
- Prometheus does not have performance data for this environment, or the metrics
  are not labeled correctly. To test this, connect to the Prometheus server and
  [run a query](#gitlab-prometheus-queries), replacing `$CI_ENVIRONMENT_SLUG`
  with the name of your environment.
147

148
[autodeploy]: ../../../ci/autodeploy/index.md
149
[kubernetes]: https://kubernetes.io
150
[kube]: ./kubernetes.md
151
[prometheus-k8s-sd]: https://prometheus.io/docs/operating/configuration/#<kubernetes_sd_config>
152 153
[prometheus]: https://prometheus.io
[gitlab-prometheus-k8s-monitor]: ../../../administration/monitoring/prometheus/index.md#configuring-prometheus-to-monitor-kubernetes
154 155 156
[prometheus-docker-image]: https://hub.docker.com/r/prom/prometheus/
[prometheus-yml]:samples/prometheus.yml
[gitlab.com-ip-range]: https://gitlab.com/gitlab-com/infrastructure/issues/434
157
[ci-environment-slug]: ../../../ci/variables/#predefined-variables-environment-variables
158
[ce-8935]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/8935
Fatih Acet's avatar
Fatih Acet committed
159
[ce-10408]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/10408
160
[promgldocs]: ../../../administration/monitoring/prometheus/index.md