使用Prometheus對GitLab Runner監控


配置GitLab Runner監控

GitLab Runner本地具有Prometheus指標,可以訪問嵌入式HTTP服務器,通過/metrics路徑公開。該服務器(如果已啟用)可以被Prometheus監視系統抓取,或通過任何其他HTTP客戶端進行訪問。

公開的信息包括:

  • Runner業務邏輯指標(例如,當前正在運行的作業數)
  • Go特定的流程指標(垃圾收集統計信息,goroutines,memstats等)
  • 常規指標(內存使用情況,CPU使用情況,文件描述符使用情況等)

Runner默認是沒有開啟內置的HTTP服務,可以通過兩種方式配置指標HTTP服務器:

  • 在config.toml文件中配置全局選項 listen_address。
  • 在Runner啟動的時候添加--listen-address命令選項。

在這里我直接修改的config.toml文件,內容參考如下:

# cat config.toml 
listen_address = "[::]:9252" # 雙引號必須加
concurrent = 10
check_interval = 30
log_level = "info"

修改Runner配置后需要重啟, 隨后通過netstat查看監聽的端口。

# netstat -tulnp|grep 9252       
tcp6       0      0 :::9252                 :::*                    LISTEN      26209/gitlab-runner 

當9252端口被監聽,內容的HTTP服務器就啟動了。此時我們可以獲取指標數據。

# curl 127.0.0.1:9252/metrics

接下來我們配置Prometheus對數據收集,然后通過Grafana展示。更新Prometheus配置文件。

- job_name: 'gitlab-runner'      
  metrics_path: '/metrics'      
  scheme: http      
  bearer_token: bearer_token      
  static_configs:          
    - targets: ['localhost:9252']

最后,我們找一個Grafana模板展示數據。14016或者9631 下載JSON文件,導入。

配置GitLab CI 流水線監控

安裝配置: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: ['localhost:8092'] # 具體端口號根據實際情況來定

添加Grafana面板,10620。下載JSON文件然后導入。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM