GitLab System Admin - Hands-On Lab: Logging and Monitoring GitLab Kubernetes
Estimated time to complete: 30 minutes
Objectives
The objective of this lab is to demonstrate how to use Prometheus and Grafana for log analysis and monitoring.
Task A. Access the Prometheus Service
-
GitLab’s Prometheus server can be reached via TCP port 9090. To access this port, you need to create a proxy into your Kubernetes cluster. This can be done with the following command:
kubectl proxy
-
To access Prometheus, you need to know its pod name. To find this, run the command
kubectl get pods
. Search for Prometheus in the output. -
Navigate to
http://localhost:8001/api/v1/namespaces/default/pods/PROMETHEUS_POD_NAME:9090/proxy/
in a web browser to view the built-in Prometheus server. -
To view the available metrics in Prometheus, navigate to
http://localhost:8001/api/v1/namespaces/default/pods/PROMETHEUS_POD_NAME:9090/proxy/metrics
.To see a more detailed list of each metric, check out the documentation.
Task B. Viewing Prometheus Metrics
For this example, suppose you wanted to monitor HTTP requests sent into your GitLab instance. To achieve this, we can use some built in GitLab metrics.
-
Navigate to
http://localhost:8001/api/v1/namespaces/default/pods/PROMETHEUS_POD_NAME:9090/proxy/
. -
In the input beside the magnifying glass button, type
http_requests_total
. -
Click the Execute button.
-
Click Table to view a table of all the results generated by the query.
You will likely see a variety of different HTTP requests in the results. Note that you can see the
job
,instance
,HTTP method
andstatus
of each request. -
Click Graph to view a graph of your data.
On the left hand side of the graph, you will see a - and + button. You can click these buttons to change the scale of the graph. Try adjusting the scale to see how it impacts your data.
Task C. Alert Configurations
Prometheus can be used to alert administrators based on specific metrics. GitLab comes with a set of predefined alerts for Prometheus.
-
Navigate to
http://localhost:8001/api/v1/namespaces/default/pods/PROMETHEUS_POD_NAME:9090/proxy/
. -
Click Alerts in the top menu.
Note that there are two sets of alert rules, one named GitLab and one named Node. The GitLab alerts correspond to platform issues such as a service being down, Postgres being down, or high queueing within services. A Node alert corresponds to the server GitLab is deployed on.
-
Note the file that contains the alerting rules. By default, the file is
/var/opt/gitlab/prometheus/rules/gitlab.rules
.As an administrator, you can define custom rules inside this file to use for alerting. This will allow you to monitor your system for any potential issues.
Task D. Common Performance Metrics
There are a variety of different metrics administrators can use to monitor the performance of their GitLab instances. Let’s examine a few common queries you can use to monitor an instance.
-
Navigate to
http://localhost:8001/api/v1/namespaces/default/pods/PROMETHEUS_POD_NAME:9090/proxy/
. -
In the input beside the magnifying glass button, type the following query:
((node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) or ((node_memory_MemFree_bytes + node_memory_Buffers_bytes + node_memory_Cached_bytes) / node_memory_MemTotal_bytes)) * 100
This query will show you the percentage of memory available on your instance.
-
Click Graph to view the percentage of memory over time.
-
In the query input, delete your previous query and replace it with the following query:
1 - avg without (mode,cpu) (rate(node_cpu_seconds_total{mode="idle"}[5m]))
This query will show you the percentage of CPU used on your instance.
-
Click Graph to view the percent of CPU used over time.
For these metrics and many others, you may want to consider alerting for specific conditions. For example, you could alert for cases where the CPU usage exceeds 50% consistently, as it might indicate an issue.
Lab Guide Complete
You have completed this lab exercise. You can view the other lab guides for this course.
Suggestions?
If you’d like to suggest changes to the GitLab System Admin Basics Hands-on Guide, please submit them via merge request.
23df6bff
)