温馨提示×

如何监控Debian的GitLab

小樊
41
2026-07-18 13:44:53
栏目: 智能运维

监控 Debian 上的 GitLab 可以从 系统层、GitLab 服务层、应用层、日志、告警 五个维度来做。下面给你一套从基础到进阶的完整方案,适合生产环境。


一、确认 GitLab 安装方式(很重要)

不同安装方式,监控方式略有差异:

# 查看 GitLab 版本
gitlab-rake gitlab:env:info

常见安装方式:

  • Omnibus GitLab(最常见,推荐)
  • Docker GitLab
  • ⚠️ 源码安装(较少)

下面以 Omnibus GitLab on Debian 为主。


二、系统级监控(基础必做)

1️⃣ 系统资源监控

重点监控:

  • CPU
  • 内存
  • 磁盘(尤其是 /var/opt/gitlab
  • 磁盘 inode
  • 网络

工具推荐

Prometheus + node_exporter(推荐)
htop / dstat(临时排查)

apt install htop dstat -y

三、GitLab 自带监控(最重要)

1️⃣ GitLab 内置 Prometheus(强烈推荐)

Omnibus GitLab 默认已集成 Prometheus

检查是否开启

gitlab-ctl status prometheus

配置文件

/etc/gitlab/gitlab.rb

确保包含:

prometheus_monitoring['enable'] = true

重新加载:

gitlab-ctl reconfigure

访问 Prometheus

http://gitlab_ip:9090

2️⃣ GitLab 自带 Exporter(关键指标)

Exporter 作用
gitlab_exporter GitLab 应用指标
postgres_exporter 数据库
redis_exporter Redis
node_exporter 系统
puma_exporter Web 服务

查看状态:

gitlab-ctl status

四、核心监控指标(必须关注)

✅ 1. GitLab 服务状态

gitlab-ctl status

重点服务:

  • puma
  • sidekiq
  • postgresql
  • redis
  • nginx
  • gitaly

✅ 2. 仓库 & Gitaly 监控(最容易出问题)

gitlab-ctl status gitaly

关键指标:

  • git 操作延迟
  • 仓库磁盘 IO
  • Gitaly 错误率

Prometheus 查询示例:

rate(gitaly_service_requests_total[5m])

✅ 3. Sidekiq 队列(后台任务)

重点监控:

  • 队列长度
  • 失败任务
  • 处理延迟

Prometheus 指标:

sidekiq_queue_size
sidekiq_jobs_failed_total

✅ 4. HTTP / Git 访问

监控:

  • Git clone / push 延迟
  • HTTP 5xx
  • GitLab Pages / API

Nginx 日志:

/var/log/gitlab/nginx/

五、日志监控(排错核心)

1️⃣ 关键日志目录

/var/log/gitlab/

重点:

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

2️⃣ 实时查看日志

gitlab-ctl tail
gitlab-ctl tail gitaly
gitlab-ctl tail sidekiq

3️⃣ 日志监控工具(推荐)

ELK / EFKGrafana Lokirsyslog + logrotate


六、Grafana 可视化(强烈推荐)

1️⃣ 安装 Grafana

apt install grafana -y
systemctl enable grafana-server
systemctl start grafana-server

2️⃣ 添加 Prometheus 数据源

http://localhost:9090

3️⃣ 导入 GitLab Dashboard

官方 Dashboard ID:

  • GitLab Omnibus893
  • Node Exporter1860

七、告警(生产必做)

1️⃣ Prometheus Alertmanager

监控告警示例:

  • CPU > 90%
  • 内存 > 90%
  • 磁盘 > 85%
  • Sidekiq 失败
  • GitLab 服务 down

2️⃣ 告警渠道

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

八、GitLab 健康检查(快速诊断)

1️⃣ 内置检查

gitlab-rake gitlab:check
gitlab-rake gitlab:doctor:secrets

2️⃣ 接口健康检查

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

九、推荐监控架构(生产级)

Debian GitLab
 ├─ node_exporter
 ├─ Prometheus
 ├─ Grafana
 └─ Alertmanager

十、总结(重点)

必做

  • GitLab 自带 Prometheus
  • 系统资源监控
  • Sidekiq / Gitaly
  • 日志监控

推荐

  • Grafana 可视化
  • 告警系统

警告

  • 不要忽略磁盘空间
  • GitLab 非常吃内存(建议 ≥ 8GB)

如果你愿意,我可以:

  • ✅ 给你 完整 Prometheus + Grafana 安装脚本
  • ✅ 给你 生产级告警规则
  • ✅ 针对 Docker / 高可用 GitLab 单独讲

你现在 GitLab 是 Omnibus 还是 Docker

0