温馨提示×

Linux GitLab怎么监控

小樊
35
2026-08-24 23:04:31
栏目: 智能运维

在 Linux 上监控 GitLab,通常从 系统资源、GitLab 服务状态、应用性能、日志、告警 几个层面来做。下面给你一套从基础到进阶的完整方案,适合生产环境。


一、基础监控(必做)

1️⃣ 系统资源监控(Linux 层面)

CPU / 内存 / 磁盘 / 网络

top
htop
free -h
df -h
iostat -x 1

常用工具

  • htop:进程 & CPU
  • iotop:磁盘 IO
  • netstat / ss:端口 & 连接
  • vmstat:系统整体负载

重点指标

  • CPU 使用率
  • 内存是否 swap
  • 磁盘是否满(尤其是 /var/opt/gitlab
  • 网络 IO

2️⃣ GitLab 服务状态监控(官方方式)

GitLab 自带服务管理命令:

gitlab-ctl status

查看单个组件:

gitlab-ctl status nginx
gitlab-ctl status sidekiq
gitlab-ctl status puma

✅ 常见关键服务:

  • puma(Web)
  • sidekiq(后台任务)
  • postgresql
  • redis
  • nginx
  • gitaly

二、GitLab 内置监控(推荐)

3️⃣ GitLab Prometheus + Grafana(官方方案)

GitLab 自带 Prometheus,无需额外安装。

开启 Prometheus(默认已开启)

gitlab-ctl status prometheus

访问:

http://gitlab_ip:9090

查看指标

  • CPU / 内存
  • 请求 QPS
  • Sidekiq 队列
  • DB 连接数
  • Redis 命中率

4️⃣ GitLab 自带 Grafana(推荐)

GitLab 企业版(EE)自带 Grafana
社区版(CE)可手动对接 Prometheus

路径:

Admin → Monitoring → Metrics

✅ 推荐监控面板:

  • GitLab Overview
  • Sidekiq
  • PostgreSQL
  • Gitaly
  • Redis

三、日志监控(非常重要)

5️⃣ GitLab 日志位置

/var/log/gitlab/

关键日志:

gitlab-rails/production.log
sidekiq.log
nginx/gitlab_access.log
nginx/gitlab_error.log
postgresql/postgresql.log
redis/redis.log
gitaly/current

实时查看

tail -f /var/log/gitlab/gitlab-rails/production.log

✅ 关注:

  • 500 / 502 错误
  • 慢请求
  • DB 连接失败
  • Redis timeout

四、GitLab 健康检查(API)

6️⃣ 健康检查接口

curl http://gitlab.local/-/health

返回:

GitLab OK

详细状态:

curl http://gitlab.local/-/readiness
curl http://gitlab.local/-/liveness

✅ 可用于:

  • 负载均衡健康检查
  • 自动重启脚本

五、告警监控(生产必备)

7️⃣ Prometheus + Alertmanager

GitLab 集成 Alertmanager:

gitlab-ctl status alertmanager

默认告警规则:

  • CPU 高
  • 内存不足
  • 磁盘快满
  • Sidekiq 队列堆积

✅ 可接入:

  • 邮件
  • 钉钉
  • 企业微信
  • Slack

六、第三方监控方案(推荐)

8️⃣ 使用 Prometheus + Grafana(最通用)

架构:

GitLab → Prometheus → Grafana

✅ 适合:

  • 多 GitLab 实例
  • 统一监控平台

GitLab exporter 自动暴露:

http://gitlab_ip:9100/metrics

9️⃣ Zabbix 监控 GitLab(企业常用)

Zabbix 监控项:

  • GitLab 服务端口
  • 进程存活
  • 系统资源
  • 日志关键字(502 / error)

七、GitLab 性能监控重点指标

指标 说明
并发请求数 Puma
Sidekiq 队列长度 后台任务
DB 连接数 PostgreSQL
Redis 命中率 缓存
Gitaly 延迟 Git 操作
磁盘 IO 仓库增长

八、推荐监控组合(最佳实践)

中小型

  • gitlab-ctl status
  • Prometheus
  • 日志 + 健康检查

生产环境

  • Prometheus + Grafana
  • Alertmanager 告警
  • 日志集中(ELK / Loki)
  • 磁盘 & 备份监控

九、常见故障监控点

问题 监控点
502 nginx / puma
DB / Gitaly
卡顿 Sidekiq
磁盘满 repo 增长
内存爆 sidekiq + puma

如果你愿意,我可以帮你:

  • 画一套 GitLab 监控架构图
  • 给你 Prometheus 告警规则
  • 针对 CE / EE 定制监控方案
  • 写 Zabbix / Grafana 模板

你现在用的是 GitLab CE 还是 EE?单机还是高可用?

0