热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

haproxyprometheus监控dockercompose运行试用

haproxyprometheus的监控metrics使用的是exporter,因为haproxy对于状态统计报告处理的比较好,我们可以了stats同时支持一个csv的api接口,

haproxy prometheus 的监控metrics 使用的是exporter ,因为haproxy 对于状态统计报告处理的
比较好,我们可以了stats 同时支持一个csv的api 接口,所以exporter也是基于这个搞的开发,同时
里面对于不同版本的haproxy 做了适配

环境准备

  • docker-compose 文件
 
version: "3"
services:
  haproxy:
    image: haproxy:1.7
    ports:
    - "5000:5000"
    - "10080:10080"
    volumes:
    - "./conf/haproxy:/usr/local/etc/haproxy:ro"
  exporter:
    image: quay.io/prometheus/haproxy-exporter:v0.9.0
    command: --haproxy.scrape-uri="http://admin:password@haproxy:10080/haproxy?stats;csv"
    ports:
    - "9101:9101"
  g:
    image: grafana/grafana
    ports:
    - "3000:3000"
  p:
    image: prom/prometheus
    volumes:
    - "./conf/prometheus.yml:/etc/prometheus/prometheus.yml"
    ports:
    - "9090:9090"
 
 
  • haproxy 配置文件
    conf/haproxy/haproxy.cfg 很简单就是配置了stats 同时配置了一个简单的jenkins 的proxy+ lb
 
global
    log 127.0.0.1 local2
    maxconn 4000
    # turn on stats unix socket
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode http
    log global
    option httplog
    option dontlognull
    option http-server-close
    option forwardfor except 127.0.0.0/8
    option redispatch
    retries 3
    timeout http-request 10s
    timeout queue 1m
    timeout connect 10s
    timeout client 1m
    timeout server 1m
    timeout http-keep-alive 10s
    timeout check 10s
    maxconn 3000
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main
    bind 0.0.0.0:5000
    default_backend app
backend app
    balance roundrobin
    server app1 10.15.0.80:80 check
    server app2 10.15.0.80:8080 check
    server app3 127.0.0.1:5003 check
    server app4 127.0.0.1:5004 check
listen stats
        bind 0.0.0.0:10080
        mode http
        log global
        maxconn 10
        clitimeout 100s
        srvtimeout 100s
        contimeout 100s
        timeout queue 100s
        stats enable
        stats hide-version
        stats refresh 30s
        stats show-node
        stats auth admin:password
        stats uri /haproxy?stats
 
 
  • exporter 配置
    主要是启动的时候指定haproxy server 的地址,因为使用了basic auth, exporter 比较方便支持basic auth 格式的url
 
  command: --haproxy.scrape-uri="http://admin:password@haproxy:10080/haproxy?stats;csv"
 
  • prometheus 配置
    实际上就是通过静态配置添加experter 地址 ./conf/prometheus.yml
 
scrape_configs:
  - job_name: haproxy
    metrics_path: /metrics
    static_configs:
      - targets: ['exporter:9101']
 
 

运行&&效果

  • 启动
docker-compose up -d
 
  • 访问效果
    haproxy prometheus 监控docker-compose 运行试用
    haproxy prometheus 监控docker-compose 运行试用
    haproxy prometheus 监控docker-compose 运行试用
    haproxy prometheus 监控docker-compose 运行试用
    haproxy prometheus 监控docker-compose 运行试用

说明

docker-compose文件同时集成了grafana,可以方便的进行UI的可视化展示

参考资料

https://github.com/rongfengliang/haproxy_promethues-docker-compose
https://github.com/prometheus/haproxy_exporter
https://hub.docker.com/_/haproxy


推荐阅读
author-avatar
手机用户2502871605
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有