温馨提示×

如何监控Debian GitLab

小樊
44
2026-08-02 10:54:16
栏目: 智能运维

在 Debian 上监控 GitLab 可以从 系统层、GitLab 服务层、应用层、以及日志/告警 四个层面来做。下面给你一套可落地的监控方案,从简单到专业都有。


一、使用 GitLab 自带监控(最推荐,先开启)

GitLab 内置了 Prometheus + 自带 Exporter,这是官方推荐方式。

1️⃣ 启用 Prometheus(Omnibus GitLab)

编辑配置文件:

sudo nano /etc/gitlab/gitlab.rb

启用监控:

prometheus_monitoring['enable'] = true

重新配置:

sudo gitlab-ctl reconfigure

访问:

http://<gitlab-ip>:9090

✅ 自带指标包括:

  • GitLab 各组件状态
  • Redis / PostgreSQL / Gitaly
  • HTTP 请求延迟
  • 队列长度

二、系统级监控(Debian 服务器)

1️⃣ 基础系统监控(CPU / 内存 / 磁盘)

使用 top / htop

sudo apt install htop
htop

查看 GitLab 进程

ps aux | grep gitlab

查看内存占用

free -h

2️⃣ 使用 Node Exporter + Prometheus(推荐)

安装 Node Exporter

sudo apt install prometheus-node-exporter

启动:

sudo systemctl enable prometheus-node-exporter
sudo systemctl start prometheus-node-exporter

端口:

http://<server-ip>:9100/metrics

三、GitLab 服务状态监控(重点)

1️⃣ GitLab 健康检查

快速检查

sudo gitlab-ctl status

详细检查

sudo gitlab-rake gitlab:check

2️⃣ GitLab 内置 API 健康检查

curl -s http://localhost/-/health | jq

或:

curl -I http://localhost/-/health

返回 200 OK 表示正常。


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

GitLab 主要日志目录

/var/log/gitlab/

常用日志:

日志 作用
gitlab-rails/production.log Web 请求
nginx/gitlab_access.log 访问日志
nginx/gitlab_error.log 错误
postgresql/ 数据库
redis/ 缓存
gitaly/ Git 操作

实时查看:

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

五、专业监控方案(生产环境推荐)

✅ Prometheus + Grafana(最常用)

架构

GitLab → Prometheus → Grafana

已包含 Exporter

  • GitLab exporter
  • Node exporter
  • PostgreSQL exporter
  • Redis exporter

Grafana Dashboard

官方 Dashboard:

  • GitLab 官方:https://grafana.com/grafana/dashboards/11231
  • GitLab Omnibus:https://grafana.com/grafana/dashboards/13404

六、告警(必须)

1️⃣ Prometheus Alertmanager

可监控:

  • GitLab 服务 down
  • 磁盘 > 85%
  • 内存 > 90%
  • HTTP 5xx 增多

2️⃣ 简单脚本告警(无 Prometheus)

#!/bin/bash
if ! curl -s http://localhost/-/health | grep -q "ok"; then
  echo "GitLab is down" | mail -s "GitLab Alert" admin@example.com
fi

七、GitLab 性能监控重点指标

指标 警戒值
CPU > 80%
内存 > 85%
磁盘 > 80%
并发连接 > 500
500 错误 > 1%
Sidekiq 队列 持续增长

八、推荐监控组合(直接照抄)

中小团队

  • gitlab-ctl status
  • 系统 htop
  • /var/log/gitlab
  • 定时 health check

生产环境

  • Prometheus
  • Node Exporter
  • Grafana + 告警
  • GitLab 内置 metrics

九、我可以继续帮你

你可以告诉我:

  1. ✅ GitLab 是 Omnibus 还是 Docker
  2. ✅ 是 公司生产环境还是个人服务器
  3. ✅ 是否需要 微信 / 邮件 / 钉钉告警

我可以直接给你:

  • ✅ 完整 Prometheus 配置
  • ✅ Grafana Dashboard JSON
  • ✅ 告警规则示例

0