介绍
GitLab Runner 使用本机 Prometheus 指标进行检测,这些指标可以通过路径上的嵌入式 HTTP 服务器公开/metrics
。服务器 - 如果启用 - 可以被普罗米修斯监控系统抓取或通过任何其他 HTTP 客户端访问。
暴露的信息包括:
- Runner 业务逻辑指标(例如,当前正在运行的作业数)
- Go 特定的进程指标(垃圾收集统计信息、goroutines、memstats 等)
- 一般进程指标(内存使用、CPU 使用、文件描述符使用等)
- 构建版本信息
度量格式记录在 Prometheus 的 Exposition formats specification 中。
这些指标旨在作为操作员监控和深入了解您的跑步者的一种方式。例如,您可能有兴趣了解运行器主机上平均负载的增加是否与已处理作业的增加有关。或者您可能正在运行一个机器集群,并且您想要跟踪构建趋势以便您可以更改您的基础设施。
配置
配置 Runner
- 启用 runner metrics
# 修改监听配置
$ sudo cat /etc/gitlab-runner/config.toml
concurrent = 4
check_interval = 5
listen_address = ":9252" # 添加监听地址,启动后自动加载 metrics
[session_server]
...
[[runners]]
...
- 重启 runner
$ sudo gitlab-runner restart
配置 Grafana
- 开启页面更新
$ vi /etc/gitlab/gitlab.rb
grafana['admin_password'] = 'admin' # 设置管理员密码
grafana['disable_login_form'] = false
grafana['dashboards'] = [
{
'name' => 'GitLab Omnibus',
'orgId' => 1,
'folder' => 'GitLab Omnibus',
'type' => 'file',
'disableDeletion' => false,
'allowUiUpdates' => true, # 允许页面更新
'updateIntervalSeconds' => 600,
'options' => {
'path' => '/opt/gitlab/embedded/service/grafana-dashboards',
}
}
]
- 重新配置
$ gitlab-ctl reconfigure
- 添加 grafana link 到 gitlab
Menu
>Admin
>Settings
>Metrics and Profiling
>Metrics - Grafana
配置 Prometheus
- 添加 endpoint
$ cat <<EOF >> /etc/gitlab/gitlab.rb
## Prometheus Configure
prometheus['listen_address'] = '0.0.0.0:9090'
prometheus['scrape_configs'] = [
{
'job_name': 'gitlab-ci-pipelines',
'static_configs' => [
'targets' => ['127.0.0.1:8090'],
],
},
{
'job_name': 'gitlab-runner', # 添加 runner 监控
'static_configs' => [
'targets' => ['127.0.0.1:9252'],
],
},
]
EOF
- 重新配置
$ gitlab-ctl reconfigure
验证
- 查看 metrics
$ curl -s http://localhost:9252/metrics | grep -v '#'
导入 dashboards
导航到 Menu
> Admin
> Monitoring
> Metrics Dashboard
,跳转到 Grafana 登录界面,使用管理员账户登录。
-
导航到左侧边栏,点击
+
>Import
-
导入 ID 10156:
-
点击
Load
-
Options:
-
Name
:GitLab Runners -
Folder
:GitLab Omnibus -
Unique identifier(uid)
:gitlab_runners -
prometheus
:GitLab Omnibus -
GITLAB_HOST
:gitlab.msens.cn
-
-
点击
Import