啟用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)。參考來源: