在Linux系统里监控GitLab运行有多种方法,以下是一些常用的监控方法:
安装和配置Prometheus:
下载并安装Prometheus:
wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz tar xvfz prometheus-2.30.3.linux-amd64.tar.gz cd prometheus-2.30.3.linux-amd64 ./prometheus --config.file=prometheus.yml 编辑 prometheus.yml 文件,添加GitLab的监控目标:
scrape_configs: - job_name: 'gitlab' static_configs: - targets: ['gitlab.example.com:9090'] 启动Prometheus服务:
./prometheus --config.file=prometheus.yml 安装和配置Grafana:
下载并安装Grafana:
wget https://dl.grafana.com/oss/release/grafana-8.2.0.linux-amd64.tar.gz tar -zxvf grafana-8.2.0.linux-amd64.tar.gz cd grafana-8.2.0 ./bin/grafana-server 访问Grafana仪表板:http://gitlab.example.com:3000
在Grafana中添加Prometheus作为数据源,并创建仪表盘来监控GitLab的各项指标。
设置报警规则:
在Prometheus中创建告警规则文件 alert.yml:
groups: - name: gitlab_alerts rules: - alert: HighCPUUsage expr: node_cpu_seconds_total{job="gitlab"} > 0.8 * 1m for: 1m labels: severity: warning annotations: summary: "High CPU usage on GitLab server" description: "CPU usage on GitLab server is above 80%" 在Prometheus中加载告警规则文件,并启用告警通知。
创建自监控项目:
在GitLab项目中,进入 Settings -> Metrics and profiling -> Self monitoring,启用自监控功能。
创建自监控项目后,GitLab会生成一个监控项目,用于可视化和配置监控。
top、htop、glances 等来查看GitLab服务器的资源使用情况。curl --header "PRIVATE-TOKEN: your-access-token" "http://your-gitlab-domain/api/v4/projects" curl --header "PRIVATE-TOKEN: your-access-token" "http://your-gitlab-domain/api/v4/runners" curl --header "PRIVATE-TOKEN: your-access-token" "http://your-gitlab-domain/api/v4/issues" sudo gitlab-ctl tail sudo gitlab-ctl tail unicorn sudo gitlab-ctl tail sidekiq