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
 
  • 访问效果




说明

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

参考资料

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

haproxy prometheus 监控docker-compose 运行试用的更多相关文章

  1. Prometheus监控Docker Swarm集群(一)

    Prometheus监控Docker Swarm集群(一) cAdvisor简介 为了解决容器的监控问题,Google开发了一款容器监控工具cAdvisor(Container Advisor),它为 ...

  2. Prometheus 监控Docker服务器及Granfanna可视化

    Prometheus 监控Docker服务器及Granfanna可视化 cAdvisor(Container Advisor)用于收集正在运行的容器资源使用和性能信息. 使用Prometheus监控c ...

  3. Grafana连接Prometheus监控Docker平台

    Grafana是一款开源的分析平台. Grafana allows you to query, visualize, alert on and understand your metrics no m ...

  4. dotnet跨平台 - 使用Nginx+Docker Compose运行.NETCore项目

    参考文档: https://docs.docker.com/install/linux/docker-ce/centos/ http://www.dockerinfo.net/document htt ...

  5. Prometheus入门到放弃(4)之cadvisor监控docker容器

    Prometheus监控docker容器运行状态,我们用到cadvisor服务,cadvisor我们这里也采用docker方式直接运行. 1.下载镜像 [root@prometheus-server ...

  6. .NET遇上Docker - 使用Docker Compose组织Ngnix和.NETCore运行

    本文工具准备: Docker for Windows Visual Studio 2015 与 Visual Studio Tools for Docker 或 Visual Studio 2017 ...

  7. prometheus监控(小试牛刀)

    prometheus监控(小试牛刀) 环境:全部服务都是基于docker运行 本文略微草率,好文章在这里,特别好如下: https://www.cnblogs.com/tchua/p/11120228 ...

  8. 6. 使用cadvisor监控docker容器

    Prometheus监控docker容器运行状态,我们用到cadvisor服务,cadvisor我们这里也采用docker方式直接运行.这里我们可以服务端和客户端都使用cadvisor 客户端 1.下 ...

  9. Docker:Docker Compose 详解

    Docker Compose 概述与安装? 前面我们使用 Docker 的时候,定义 Dockerfile 文件,然后使用 docker build.docker run 等命令操作容器.然而微服务架 ...

随机推荐

  1. Mac生成rsa证书

    详细参考大神 https://blog.csdn.net/qq_30513483/article/details/51242338 RSA为一种加密算法,生成的文件格式有两种,一种是PEM格式,另一种 ...

  2. sas 选择一段日期,和一定周期,生成日期序列和周期序列

    工作需要,得选择一段日期,和一定周期,生成日期序列和周期序列.暂时用七天为一个周期 data d; format date date9.; do date='04mar2018'd to'05may2 ...

  3. caffe blob

    Blob,包括输入数据.输出数据.权值等: Blob是Caffe中处理和传递实际数据的数据封装包,并且在CPU与GPU之间具有同步处理能力.从数学意义上说,blob是按C风格连续存储的N维数组. ca ...

  4. spring4全注解web项目demo

    记得没接触框架的时候,写demo测试时真的很爽,新建web项目,然后随便写写servlet随便调试 框架越来越多,配置记不得了,整合容易出问题,集成新东西越来越少了,不敢动了. 这是个spring4的 ...

  5. GD2模块-图像处理

    GD2模块-图像处理 1.图像处理模块的主要功能: a) 验证码 b) 加盖水印 c) 缩略图 d) 帖子图片签名 e) 在线LOGO制作 2确认PHP是否支持图像处理 检测PHPINFO文件中是否存 ...

  6. vue-cli快速构建vue项目模板

    vue-cli 是vue.js的脚手架,用于自动生成vue.js模板工程的. 1.使用npm安装vue-cli 需要先装好vue 和 webpack(前提是已经安装了nodejs,否则连npm都用不了 ...

  7. VS2012里面使用EF框架的增删改查和分页的方法

    public class BaseRepository<T> where T : class    {        //实例化EF框架        DataModelContainer ...

  8. L299 EST 科技英语翻译-美学取向 (下)

    4. Ordering(有序美) DescriptiveExpositoryArgumentative Chinese: end focus 句尾焦点English: beginning focus ...

  9. Nodejs安装express提示不是内部或外部命令

    安装nodejs安装包后,通过npm安装express后,运行express提示" express"不是内部或外部命令. c:\express -t ejs web 原因是版本问题 ...

  10. HDU 5776 sum(抽屉原理)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=5776 Problem Description Given a sequence, you're ask ...