jenkins 提供了rest api,我們可以基於rest api 暴露prometheus metrics,社區已經有了好多
開源的實現了,使用起來也比較方便,以下集成幾個進行簡單的測試
環境准備
- docker-compose 文件
version: "3"
services:
jenkins:
image: jenkins/jenkins:lts-slim
ports:
- "8080:8080"
jenkins-exporter2:
image: tboerger/jenkins-exporter
command: -jenkins.address=http://jenkins:8080 -jenkins.password=dalong -jenkins.username=admin
ports:
- "9103:9103"
jenkins-exporter3:
image: tolleiv/jenkins_exporter
command: -j=http://jenkins:8080 --password=dalong --user=admin
ports:
- "9119:9118"
jenkins-exporter:
image: dalongrong/jenkins_exporter
env_file:
- .env
ports:
- "9118:9118"
grafana:
image: grafana/grafana
ports:
- "3000:3000"
prometheus:
image: prom/prometheus
volumes:
- "./prometheus.yml:/etc/prometheus/prometheus.yml"
ports:
- "9090:9090"
- promethesu 配置
scrape_configs:
- job_name: jenkins
metrics_path: /metrics
scrape_interval: 10s
scrape_timeout: 10s
static_configs:
- targets: ['jenkins-exporter:9118']
- job_name: jenkins2
metrics_path: /metrics
scrape_interval: 10s
scrape_timeout: 10s
static_configs:
- targets: ['jenkins-exporter2:9103']
- job_name: jenkins3
metrics_path: /metrics
scrape_interval: 10s
scrape_timeout: 10s
static_configs:
- targets: ['jenkins-exporter3:9118']
- 簡單說明
包含了三個exportertboerger/jenkins-exporter
,tolleiv/jenkins_exporter
,akawork/Jenkins-exporter
使用方法很簡單,同時也集成了一個基於docker 的jenkins,方便測試
啟動&&測試
- 啟動
docker-compose up -d
- 效果
- jenkins 任務
- grafana 配置
導入github 項目的json 文件https://github.com/rongfengliang/jenkins-exporter-prometheus/blob/master/jenkins-exporter_rev1.json
效果
說明
以上是一個簡單的集成三個exporter 進行測試,還是很方便的,可以快速的查看任務的構建的狀態
參考資料
https://github.com/akawork/Jenkins-exporter.git
https://github.com/akawork/Jenkins-exporter
https://github.com/rongfengliang/jenkins-exporter-prometheus