{"id":426,"date":"2015-03-09T19:34:56","date_gmt":"2015-03-09T18:34:56","guid":{"rendered":"http:\/\/lazic.info\/josip\/?p=426"},"modified":"2016-05-06T09:12:29","modified_gmt":"2016-05-06T08:12:29","slug":"monitor-haproxy-via-prtg","status":"publish","type":"post","link":"https:\/\/lazic.info\/josip\/post\/monitor-haproxy-via-prtg\/","title":{"rendered":"Monitor HAProxy via PRTG"},"content":{"rendered":"<p>Monitoring HAProxy (http:\/\/haproxy.org) is somewhat hard to do. Yes, we have nice web\/stats interface, but watching the web interface can be fun for an hour or two, but after that&#8230; You have to find a better solution. Company where I work uses PRTG Network Monitor (http:\/\/www.paessler.com\/prtg) that provides EXE\/XML Custom sensors which allow you to run custom sensor scripts.<\/p>\n<p>You can find the script here <a href=\"https:\/\/gist.github.com\/jlazic\/50af0c706196bf81b616\" title=\"\" target=\"\">https:\/\/gist.github.com\/jlazic\/50af0c706196bf81b616<\/a>, download it and save in your PRTG install directory by default that&#8217;s <em>C:\\Program Files (x86)\\PRTG Network Monitor\\Custom Sensors<\/em>. PRTG uses 32-bit Powershell, and if you have 64-bit Windows (and you have if you are using newer Windows than Server 2008), you should add 32-bit Powershell to your $PATH (append <em>%systemroot%\\SysWOW64\\WindowsPowerShell\\v1.0\\<\/em> to PATH ENV variable). Also, you should set Powershell ExecutionPolicy to Unrestricted. I know this is not the best security practice &#8211; sign your scripts!<\/p>\n<div class=\"oembed-gist\"><script src=\"https:\/\/gist.github.com\/jlazic\/50af0c706196bf81b616.js\"><\/script><noscript>View the code on <a href=\"https:\/\/gist.github.com\/jlazic\/50af0c706196bf81b616\">Gist<\/a>.<\/noscript><\/div>\n<p>To set ExecutionPolicy run this from cmd.exe<br \/>\n<code>%systemroot%\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe Set-ExecutionPolicy Unrestricted<\/code><\/p>\n<p>The next thing you should do is creating web stats in HAProxy configuration. I have stats listening on different ports for every site, and I make them read-only and without authentification, like this:<br \/>\n<code>listen geoserver-stats 10.0.0.1:9022<br \/>\n        mode http<br \/>\n        stats enable<br \/>\n        stats scope geoserver-in<br \/>\n        stats scope geoserver-out<br \/>\n        stats uri \/<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/haproxy-listen-stats.png\" alt=\"haproxy-listen-stats\" width=\"370\" height=\"135\" class=\"aligncenter size-full wp-image-435\" srcset=\"https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/haproxy-listen-stats.png 370w, https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/haproxy-listen-stats-300x109.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n<p>Now your CSV stats will have this <em>http:\/\/10.0.0.1:9022\/;csv<\/em> URL.<\/p>\n<p>You can check if script is working by running this command from directory where .ps1 script is located. Of course, replace -url param with your URL.<\/p>\n<p><code>.\\HAProxy.ps1 -url \"http:\/\/10.0.0.1:9015\/;csv\"<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/haproxy-monitor-ps1.png\" alt=\"haproxy-monitor-ps1\" width=\"997\" height=\"219\" class=\"aligncenter size-full wp-image-434\" srcset=\"https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/haproxy-monitor-ps1.png 997w, https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/haproxy-monitor-ps1-300x66.png 300w, https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/haproxy-monitor-ps1-800x176.png 800w\" sizes=\"auto, (max-width: 997px) 100vw, 997px\" \/><\/p>\n<p>Open PRTG GUI and add new sensor with type <strong>EXE\/script Advanced<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/haproxy-prtg1.png\" alt=\"haproxy-prtg1\" width=\"788\" height=\"464\" class=\"aligncenter size-full wp-image-433\" srcset=\"https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/haproxy-prtg1.png 788w, https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/haproxy-prtg1-300x177.png 300w, https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/haproxy-prtg1-509x300.png 509w\" sizes=\"auto, (max-width: 788px) 100vw, 788px\" \/><\/p>\n<p>Under <strong>EXE\/Script<\/strong> setting select downloaded .ps1 script and under <strong>Parameters<\/strong> enter <strong>-url &#8220;http:\/\/10.0.0.1:9022\/;csv&#8221;<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/haproxy-prtg2.png\" alt=\"haproxy-prtg2\" width=\"702\" height=\"193\" class=\"aligncenter size-full wp-image-432\" srcset=\"https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/haproxy-prtg2.png 702w, https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/haproxy-prtg2-300x82.png 300w\" sizes=\"auto, (max-width: 702px) 100vw, 702px\" \/><\/p>\n<p>Script uses two params <strong>url<\/strong> and <strong>monitor<\/strong>. URL param is self explanatory, and is mandatory. <strong>Monitor<\/strong> param is optional. Default value is <em>standard<\/em>, other templated values are <em>responses<\/em> and <em>errors<\/em>.<\/p>\n<p><code>$templates =@{<br \/>\n\tstandard = \"qcur,smax,scur,smax,slim,stot,bin,bout\";<br \/>\n\tresponses = \"hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,req_rate,req_rate_max,req_tot\";<br \/>\n\terrors = \"dreq,dresp,ereq,econ,eresp,chkfail\";<br \/>\n}<\/code><\/p>\n<p>If you want to monitor for errors you should use <em>-url &#8220;http:\/\/10.0.0.1:9022\/;csv&#8221; -monitor &#8220;errors&#8221;<\/em> as Parameters option in PRTG Custom sensor. If none of the templates suit your needs, you can either edit them, or pass comma separated list of params found in <a href=\"https:\/\/gist.github.com\/jlazic\/50af0c706196bf81b616\" title=\"\" target=\"\">https:\/\/gist.github.com\/jlazic\/50af0c706196bf81b616<\/a> or <a href=\"http:\/\/cbonte.github.io\/haproxy-dconv\/configuration-1.5.html#9.1\" title=\"HAProxy documentation\" target=\"http:\/\/cbonte.github.io\/haproxy-dconv\/configuration-1.5.html#9.1\"><\/a>, like:<\/p>\n<p><code>-url \"http:\/\/10.0.0.1:9022\/;csv\" -monitor \"stot,bin,eresp,hrsp_5xx,req_rate\"<\/code><\/p>\n<p>Save, repeat and watch nice graphs. Next step would be to setup alerting based on queue length, server backend availability, and UP->DOWN events in HAProxy. I will try and do that in next few days.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/prtg_chart.png\" alt=\"prtg_chart\" width=\"975\" height=\"300\" class=\"aligncenter size-full wp-image-442\" srcset=\"https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/prtg_chart.png 975w, https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/prtg_chart-300x92.png 300w, https:\/\/lazic.info\/josip\/wp-content\/uploads\/2015\/03\/prtg_chart-800x246.png 800w\" sizes=\"auto, (max-width: 975px) 100vw, 975px\" \/><\/p>\n<p>One thing to note is that PRTG does not support more than 50 channels per sensor.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Monitoring HAProxy (http:\/\/haproxy.org) is somewhat hard to do. Yes, we have nice web\/stats interface, but watching the web interface can be fun for an hour or two, but after that&#8230; You have to find a better solution. Company where I work uses PRTG Network Monitor (http:\/\/www.paessler.com\/prtg) that provides EXE\/XML Custom sensors which allow you to [&hellip;]<\/p>\n<div class=\"clearfix text-center more-button\"><a href=\"https:\/\/lazic.info\/josip\/post\/monitor-haproxy-via-prtg\/\" class=\"btn btn-success\">Continue reading<\/a><\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,11],"tags":[12,14,13],"class_list":["post-426","post","type-post","status-publish","format-standard","hentry","category-linux","category-powershell","tag-haproxy","tag-powershell","tag-prtg"],"_links":{"self":[{"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/posts\/426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/comments?post=426"}],"version-history":[{"count":0,"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/posts\/426\/revisions"}],"wp:attachment":[{"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/media?parent=426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/categories?post=426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lazic.info\/josip\/wp-json\/wp\/v2\/tags?post=426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}