本文主要闡述如何配置GitLabRunner和GitLabCI/CD流水線的數據採集與監控。git
GitLab Runner本地具備Prometheus指標,能夠訪問嵌入式HTTP服務器,經過/metrics
路徑公開。該服務器(若是已啓用)能夠被Prometheus監視系統抓取,或經過任何其餘HTTP客戶端進行訪問。github
公開的信息包括:docker
這些指標是運維人員監視和了解GitLab Runners的一種方式。例如,您可能會對Runner主機上的平均負載和做業數量感興趣。vim
Runner默認是沒有開啓內置的HTTP服務,能夠經過兩種方式配置指標HTTP服務器:api
config.toml
文件中配置全局選項 listen_address
。--listen-address
命令選項。在這裏我直接修改的config.toml
文件,內容參考以下:bash
$ cat config.toml listen_address = "[::]:9252" concurrent = 10 check_interval = 30 log_level = "info"
修改Runner配置後須要重啓, 隨後經過netstat
查看監聽的端口。服務器
bash-5.0$ netstat -anlpt | grep 9252 tcp 0 0 :::9252 :::* LISTEN 1/gitlab-runner tcp 0 0 ::ffff:10.244.0.102:9252 ::ffff:10.244.0.1:35880 ESTABLISHED 1/gitlab-runner tcp 0 0 ::ffff:10.244.0.102:9252 ::ffff:10.244.0.107:36184 ESTABLISHED 1/gitlab-runner tcp 0 0 ::ffff:10.244.0.102:9252 ::ffff:10.244.0.103:57404 ESTABLISHED 1/gitlab-runner
當9252
端口被監聽,內容的HTTP服務器就啓動了。此時咱們能夠獲取指標數據。運維
curl 127.0.0.1:9252/metrics # HELP gitlab_runner_api_request_statuses_total The total number of api requests, partitioned by runner, endpoint and status. # TYPE gitlab_runner_api_request_statuses_total counter gitlab_runner_api_request_statuses_total{endpoint="request_job",runner="6i2MzLuX",status="204"} 178 # HELP gitlab_runner_autoscaling_machine_creation_duration_seconds Histogram of machine creation time. # TYPE gitlab_runner_autoscaling_machine_creation_duration_seconds histogram gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker+machine",le="30"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker+machine",le="37.5"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker+machine",le="46.875"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker+machine",le="58.59375"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker+machine",le="73.2421875"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker+machine",le="91.552734375"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker+machine",le="114.44091796875"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker+machine",le="143.0511474609375"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker+machine",le="178.81393432617188"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker+machine",le="223.51741790771484"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker+machine",le="+Inf"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_sum{executor="docker+machine"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_count{executor="docker+machine"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker-ssh+machine",le="30"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker-ssh+machine",le="37.5"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker-ssh+machine",le="46.875"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker-ssh+machine",le="58.59375"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker-ssh+machine",le="73.2421875"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker-ssh+machine",le="91.552734375"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker-ssh+machine",le="114.44091796875"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker-ssh+machine",le="143.0511474609375"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker-ssh+machine",le="178.81393432617188"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker-ssh+machine",le="223.51741790771484"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_bucket{executor="docker-ssh+machine",le="+Inf"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_sum{executor="docker-ssh+machine"} 0 gitlab_runner_autoscaling_machine_creation_duration_seconds_count{executor="docker-ssh+machine"} 0 # HELP gitlab_runner_autoscaling_machine_states The current number of machines per state in this provider.
接下來咱們配置Prometheus對數據收集,而後經過Grafana展現。更新Prometheus
配置文件。ssh
- job_name: 'gitlab-runner' metrics_path: '/metrics' scheme: http bearer_token: bearer_token static_configs: - targets: ['192.168.1.200:30092']
而後,訪問http://192.168.1.200:30003/new/targets
, 目標爲up。curl
最後,咱們找一個Grafana模板展現數據。https://grafana.com/grafana/dashboards/9631
下載JSON文件,導入。
有時候對於運維管理人員來講,咱們須要看到整個平臺的流水線狀態。相似於Jenkins同樣有統一的面板展現。在GitLab中每一個項目都有CI/CD數據的展現。須要進入每一個項目才能看到,這樣很是不便。 在這裏咱們安裝配置:gitlab-ci-pipelines-exporter
來實現對GitLabCI流水線狀態的展現。
首先咱們須要下載chart
源碼,而後修改values.yaml
中的GitLab
配置。 配置GitLab服務器的地址和Token、須要同步的項目。
git clone https://github.com/mvisonneau/gitlab-ci-pipelines-exporter.git vim chart/values.yaml ##關鍵配置 ## Actual configuration of the exporter ## config: # # Full configuration syntax reference available here: # # https://github.com/mvisonneau/gitlab-ci-pipelines-exporter/blob/master/docs/configuration_syntax.md gitlab: url: http://192.168.1.200:30088 # # You can also configure the token using --gitlab-token # # or the $GCPE_GITLAB_TOKEN environment variable token: Z-smAyB8pFyttu6D2d_J # projects: # - name: foo/project # - name: bar/project wildcards: - owner: name: cidevops kind: group helm install gitlabci-pipline-exporter --namespace gitlab-runner ./chart
配置Prometheus
:修改配置文件添加目標。
- job_name: 'gitlab-runner-ci-pipeline' metrics_path: '/metrics' scheme: http bearer_token: bearer_token static_configs: - targets: ['10.1.234.132:80']
添加Grafana
面板https://grafana.com/grafana/dashboards/10620
。下載JSON文件然導入。最終效果以下: