温馨提示×

CentOS GitLab如何监控

小樊
36
2026-07-20 04:24:06
栏目: 智能运维

CentOS 上运行的 GitLab 监控通常分为 系统级监控、GitLab 自身状态监控、日志监控、以及外部监控系统接入(Prometheus / Grafana / Zabbix 等)。下面按实用层次详细说明。


一、GitLab 自带监控(最基础)

1️⃣ GitLab 内置 Prometheus(推荐)

GitLab 默认集成 Prometheus(尤其 Omnibus 安装方式)。

查看是否启用:

grep -R prometheus /etc/gitlab/gitlab.rb

启用 Prometheus:

gitlab_rails['monitoring_whitelist'] = ['127.0.0.1']
prometheus['enable'] = true
prometheus_monitoring['enable'] = true

重新配置:

gitlab-ctl reconfigure

访问:

http://<gitlab_ip>:9090

查看指标:

process_resident_memory_bytes
gitlab_workhorse_requests_total

✅ 优点:

  • 官方支持
  • 自动采集 GitLab 组件数据

二、GitLab 状态与服务监控

1️⃣ GitLab 内置健康检查

gitlab-ctl status

查看单个服务:

gitlab-ctl status nginx
gitlab-ctl status redis
gitlab-ctl status postgresql

2️⃣ 应用层健康检查

curl http://localhost/-/health

或:

curl http://localhost/-/readiness
curl http://localhost/-/liveness

返回值:

  • 200 ✅ 正常
  • 500/503 ❌ 异常

三、系统资源监控(CentOS)

1️⃣ CPU / 内存 / 磁盘

top
htop
free -h
df -h

2️⃣ GitLab 资源占用重点

组件 说明
Sidekiq 后台任务,CPU 高
PostgreSQL 内存消耗大
Gitaly Git 仓库访问
Redis 缓存

查看进程:

ps aux | grep gitlab

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

1️⃣ GitLab 日志目录

/var/log/gitlab/

关键日志:

日志 作用
gitlab-rails/production.log 主应用
sidekiq/current 后台任务
nginx/gitlab_access.log 访问
postgresql/postgresql.log 数据库
gitaly/current Git 操作

实时查看:

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

五、使用 Prometheus + Grafana(生产推荐)

1️⃣ 架构

GitLab → Prometheus → Grafana

2️⃣ Grafana 添加数据源

  • 类型:Prometheus
  • URL:http://localhost:9090

3️⃣ 推荐 Dashboard

GitLab 官方 Grafana Dashboard:

https://grafana.com/grafana/dashboards/11264

包含:

  • 请求 QPS
  • 错误率
  • Sidekiq 队列
  • DB / Redis 状态

六、Zabbix 监控 GitLab(企业常用)

监控项示例

监控项 方法
GitLab 服务状态 gitlab-ctl status
HTTP 可用性 curl -s -o /dev/null -w "%{http_code}"
磁盘 Zabbix Agent
内存 Zabbix Agent
PostgreSQL 连接数 SQL 查询

七、GitLab 性能监控建议(生产环境)

必看指标

  • CPU 使用率
  • 内存是否 swap
  • PostgreSQL 连接数
  • Sidekiq queue 长度
  • 磁盘 inode 使用率

告警阈值建议

  • CPU > 80%
  • 内存 > 90%
  • 磁盘 > 85%
  • 5xx 错误 > 1%

八、推荐监控方案总结

场景 方案
小型团队 GitLab 自带 Prometheus
企业级 Prometheus + Grafana
传统运维 Zabbix
DevOps GitLab + Prometheus + Alertmanager

如果你愿意,我可以:

  • ✅ 给你 CentOS + GitLab 完整 Prometheus 配置
  • ✅ 推荐 生产环境硬件 & 监控阈值
  • ✅ 帮你排查 GitLab 卡顿 / 高负载问题

直接告诉我你的 GitLab 安装方式(Omnibus / Docker / 源码)即可。

0