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. Xcode清理存储空间

    文章来自 枣泥布丁 http://www.cocoachina.com/ios/20170711/19814.html 请针对性的选择删除 移除 Xcode 运行安装 APP 产生的缓存文件(Deri ...

  2. 5.7 C++函数调用操作符重载

    参考:http://www.weixueyuan.net/view/6385.html 总结: 需要以类成员函数的形式对函数调用操作符“()”进行重载. 只有常成员函数才能处理常对象,故我们依然在类中 ...

  3. 【PyImageSearch】Ubuntu16.04使用OpenCV3.3.0实现图像分类

    这篇博文将会展示如何采用一个预训练的深度学习网络(模型)在ImageNet的数据集并把它当作输入图像. 首先说明,运行环境为Ubuntu16.04(或者MacOS),windows暂不支持,已经编译好 ...

  4. python 高级语言特性

    装饰器decorator的使用 在某公司的一次笔试中面试官出了一道题,使用python 的decorator实现一个函数的执行时间的计算. 分析:关于函数执行时间的计算,那么肯定是执行之前得到一个时间 ...

  5. 四则运算 来源:一位热心的网友 http://www.tqcto.com/article/software/336297.html

    功能:实现真分数的四则运算 语言:Java  平台:JDK下的eclipse github地址:https://github.com/yeershao/hello-world/commit/9920a ...

  6. python scrapy 数据处理时间格式转换

    def show(self,response): # print(response.url) title = response.xpath('//main/div/div/div/div/h1/tex ...

  7. python中字符串的操作方法

    python中字符串的操作方法大全 更新时间:2018年06月03日 10:08:51 作者:骏马金龙 我要评论这篇文章主要给大家介绍了关于python中字符串操作方法的相关资料,文中通过示例代码详细 ...

  8. Day13作业及默写

    1. 整理今天的博客,写课上代码,整理流程图. 博客链接--博客园 2. 写一个函数完成三次登陆功能: 用户的用户名密码从一个文件register中取出. register文件包含多个用户名,密码,用 ...

  9. Python Algorithms – chapter3 计数初步

    一些基本递归式的解决方案及其应用实例 主定理的三种情况 排序算法之侏儒排序法 def gnomesort(seq): i = 0 while i < len(seq): if i == 0 or ...

  10. 性能测试-10.数据分析Analysis

    Analysis Summary 平均响应时间(Average TransactionResponse Time) 每秒响应数(Transactions per Second) 1.Vuser  Ru ...