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

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

5 6
GitLab offers powerful integration with [Prometheus] for monitoring key metrics your apps, directly within GitLab.
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
## Managed Prometheus on Kubernetes
Joshua Lambert's avatar
Joshua Lambert committed
16
> **Note**: [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/28916) in GitLab 10.5
17

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

20
### Requirements
Joshua Lambert's avatar
Joshua Lambert committed
21

22 23
* A [connected Kubernetes cluster](../clusters/index.md)
* Helm Tiller [installed by GitLab](../clusters/index.md#installing-applications)
24

25
### Getting started
26

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

29 30 31
1. Go to the `CI/CD > Kubernetes` page, to view your connected clusters
1. Select the cluster you would like to deploy Prometheus to
1. Click the **Install** button to deploy Prometheus to the cluster
32

33
![Managed Prometheus Deploy](img/prometheus_deploy.png)
34

35
### About managed Prometheus deployments
36

37
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/).
38

39 40 41 42
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`.
43

44
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.
45

46
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.
47

48
## Manual configuration of Prometheus
49

50
### Requirements
51

52
Integration with Prometheus requires the following:
53

54 55 56 57
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
58

59
### Getting started
60

61
Installing and configuring Prometheus to monitor applications is fairly straight forward.
62

63 64 65
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)
66

67
### Configuration in GitLab
68

69 70 71
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.
72

73 74 75 76 77
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.
78

79
![Configure Prometheus Service](img/prometheus_service_configuration.png)
80

81 82
## Monitoring CI/CD Environments

83
Once configured, GitLab will attempt to retrieve performance metrics for any
84
environment which has had a successful deployment.
85

86 87
GitLab will automatically scan the Prometheus server for known metrics and attempt to identify the metrics for a particular environment. The supported metrics and scan process is detailed in our [Prometheus Metric Library documentation](prometheus_library/metrics.html).

88
[Learn more about monitoring environments.](../../../ci/environments.md#monitoring-environments)
89

90
## Determining the performance impact of a merge
Fatih Acet's avatar
Fatih Acet committed
91

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

96
Developers can view theperformance impact of their changes within the merge
97
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
98
indicates when the current changes were deployed, with up to 30 minutes of
99
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
100
each commit has been deployed.
Fatih Acet's avatar
Fatih Acet committed
101

102
Once merged and the target branch has been redeployed, the metrics will switch
103
to show the new environments this revision has been deployed to.
104

105 106
Performance data will be available for the duration it is persisted on the
Prometheus server.
107 108

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

110 111
## Troubleshooting

112
If the "Attempting to load performance data" screen continues to appear, it could be due to:
113

114
- No successful deployments have occurred to this environment.
115 116 117 118
- 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.
119

120
[autodeploy]: ../../../ci/autodeploy/index.md
121
[kubernetes]: https://kubernetes.io
122
[kube]: ./kubernetes.md
123
[prometheus-k8s-sd]: https://prometheus.io/docs/operating/configuration/#<kubernetes_sd_config>
124 125
[prometheus]: https://prometheus.io
[gitlab-prometheus-k8s-monitor]: ../../../administration/monitoring/prometheus/index.md#configuring-prometheus-to-monitor-kubernetes
126 127 128
[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
129
[ci-environment-slug]: ../../../ci/variables/#predefined-variables-environment-variables
130
[ce-8935]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/8935
Fatih Acet's avatar
Fatih Acet committed
131
[ce-10408]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/10408
132
[promgldocs]: ../../../administration/monitoring/prometheus/index.md