haproxy prometheus 监控docker-compose 运行试用
Posted rongfengliang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了haproxy prometheus 监控docker-compose 运行试用相关的知识,希望对你有一定的参考价值。
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:[email protected]: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:[email protected]: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 运行试用的主要内容,如果未能解决你的问题,请参考以下文章
k8s Prometheus+CAdvisor+node_export+grafana