HAProxy是一个功能强大的开源负载均衡器和代理服务器。它能够将网络流量分发到多个服务器,从而提高系统的可靠性、可扩展性和性能。

haproxy配置

haproxy还是比较贴心的,自带指标接口,不要额外安装导出器。 只要在配置文件中添加以下内容即可开启

frontend stats
    bind *:8404
    http-request use-service prometheus-exporter if { path /metrics }
    stats enable
    stats uri /stats
    stats refresh 10s

prometheus配置

在prometheus.yml添加以下内容

  - job_name: 'haproxy'
    static_configs:
    - targets: ['IP:8404']

告警规则

保存到alert目录中

wget https://raw.githubusercontent.com/samber/awesome-prometheus-alerts/master/dist/rules/haproxy/embedded-exporter-v2.yml

grafana模板

https://grafana.com/grafana/dashboards/12693-haproxy-2-full/

参考文档

https://samber.github.io/awesome-prometheus-alerts/rules#haproxy https://github.com/haproxy/haproxy/tree/master/addons/promex https://github.com/prometheus/haproxy_exporter/#alternatives