使用jenkins exporter 监控jenkins 构建任务

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']
  • 简单说明
    包含了三个exporter tboerger/jenkins-exporter ,tolleiv/jenkins_exporter,akawork/Jenkins-exporter
    使用方法很简单,同时也集成了一个基于docker 的jenkins,方便测试

启动&&测试

  • 启动
docker-compose up -d
  • 效果

 

 

  • jenkins 任务

 

 

 

说明

以上是一个简单的集成三个exporter 进行测试,还是很方便的,可以快速的查看任务的构建的状态

参考资料

https://github.com/akawork/Jenkins-exporter.git
https://github.com/akawork/Jenkins-exporter
https://github.com/rongfengliang/jenkins-exporter-prometheus

posted on 2019-08-31 14:36  荣锋亮  阅读(2554)  评论(0编辑  收藏  举报

导航