启用GitLab指标
修改配置文件 /etc/gitlab/gitlab.rb,添加以下内容并重启服务:
gitlab_rails['gitlab_metrics_enabled'] = true
global['monitoring_enabled'] = true
集成Prometheus
prometheus.yml 添加GitLab数据源:scrape_configs:
- job_name: 'gitlab'
static_configs:
- targets: ['gitlab-server-ip:9100'] # 确保GitLab节点导出器运行
prometheus-node-exporter 监控服务器基础指标。可视化监控(Grafana)
Prometheus告警规则
在 prometheus.yml 中定义规则文件(如 alert.yml):
groups:
- name: gitlab_alerts
rules:
- alert: HighCPUUsage
expr: node_cpu_seconds_total{job="gitlab"} > 0.8 for: 1m
labels:
severity: warning
annotations:
summary: "GitLab CPU使用率过高"
description: "CPU使用率超过80%,持续1分钟"
通知配置
receivers:
- name: 'email-alert'
email_configs:
- to: 'admin@example.com'
from: 'gitlab-alert@example.com'
smarthost: 'smtp.example.com:587'
GitLab内置告警(可选)
top、vmstat)。参考来源: