This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
docpublic:reseaux:services:monitorix_custom [2020/04/21 14:52] procacci@tem-tsp.eu [monitorix daemon in debug] |
docpublic:reseaux:services:monitorix_custom [2020/04/23 10:35] (current) procacci@tem-tsp.eu |
||
---|---|---|---|
Line 10: | Line 10: | ||
you may have to monitor a special device or application that is not yet integrated . | you may have to monitor a special device or application that is not yet integrated . | ||
- | That's the purpose of this page to explain how I manage | + | That's the purpose of this page to explain how I managed |
+ | |||
+ | I want to get In and Out traffic like that : | ||
+ | |||
+ | {{: | ||
Line 21: | Line 26: | ||
====== Custom device ====== | ====== Custom device ====== | ||
- | In this page I will demonstrate how I manage to monitor In and Out bandwith | + | In this page I will demonstrate how I manage to monitor In and Out bandwidth |
The device does provide an http service to get the status of its services . | The device does provide an http service to get the status of its services . | ||
it replies on the Lan interface at the address of the router itself | it replies on the Lan interface at the address of the router itself | ||
Line 66: | Line 71: | ||
From the differents information provided by this web interface, | From the differents information provided by this web interface, | ||
- | ====== | + | ====== |
I am not a monitorix developer , but with great and smart indication from Monitorix developers , as there is no generic module nor snmp capailities (anyway my Freebox doesn' | I am not a monitorix developer , but with great and smart indication from Monitorix developers , as there is no generic module nor snmp capailities (anyway my Freebox doesn' | ||
Line 72: | Line 77: | ||
===== copy nginx ===== | ===== copy nginx ===== | ||
- | you can check location of all the monitorix components by requesting file location of tha monitorix package with : | + | you can check location of all the monitorix components by requesting file location of the monitorix package with : |
< | < | ||
Line 102: | Line 107: | ||
</ | </ | ||
- | ===== dev environement | + | ===== dev environment |
- | After you have check that monitorix | + | After you have checked |
< | < | ||
Line 116: | Line 121: | ||
</ | </ | ||
- | duplicate all nginx parameters in the conf file to fbxcfr (or whatever name you give to your module) so that your module is taken into account by the monitorix daemon . | + | duplicate |
- | this happens | + | this happens |
==== add module to monitorix.conf ==== | ==== add module to monitorix.conf ==== | ||
Line 132: | Line 137: | ||
url = http:// | url = http:// | ||
port = 80 | port = 80 | ||
- | rule = 24100 | ||
rigid = 0, 0, 0 | rigid = 0, 0, 0 | ||
limit = 100, 100, 100 | limit = 100, 100, 100 | ||
Line 165: | Line 169: | ||
</ | </ | ||
- | run it in debug mode to be ale to see potential errors | + | execute |
< | < | ||
- | # / | + | # / |
</ | </ | ||
+ | if the module is up and running (cf code fbxcfr.pm next) here's what the logs says after starting the daemon in debug mode | ||
+ | |||
+ | < | ||
+ | Tue Apr 21 17:57:49 2020 - Starting Monitorix version 3.12.0 (pid 1166). | ||
+ | Tue Apr 21 17:57:49 2020 - Loaded main configuration file '/ | ||
+ | Tue Apr 21 17:57:49 2020 - Entering in debug mode. | ||
+ | Tue Apr 21 17:57:49 2020 - Changed process name to '/ | ||
+ | Tue Apr 21 17:57:49 2020 - Flushing out iptables rules. | ||
+ | Tue Apr 21 17:57:49 2020 - 0 iptables rules have been flushed. | ||
+ | Tue Apr 21 17:57:49 2020 - 0 ip6tables rules have been flushed. | ||
+ | Tue Apr 21 17:57:49 2020 - Initializing graphs. | ||
+ | |||
+ | Tue Apr 21 17:57:49 2020 - fbxcfr:: | ||
+ | |||
+ | Tue Apr 21 17:57:49 2020 - Generating the ' | ||
+ | Tue Apr 21 17:57:49 2020 - Setting owner/group and permission bits for the imgs/ directory. | ||
+ | Tue Apr 21 17:57:49 2020 - Started HTTP built-in server (pid 1214). | ||
+ | Tue Apr 21 17:57:49 2020 - Ok, ready. | ||
+ | HTTPServer: You can connect to your server at http:// | ||
+ | </ | ||
+ | |||
+ | then after few second (at next minute) , here comes my two values (converted to bytes) | ||
+ | |||
+ | < | ||
+ | Tue Apr 21 17:58:00 2020 - Calling fbxcfr_update() | ||
+ | Tue Apr 21 17:58:01 2020 - fbxcfr:: | ||
+ | </ | ||
+ | |||
+ | ==== RRD file for the module ==== | ||
+ | |||
+ | |||
+ | we can check the rrd file for the value it collected | ||
+ | |||
+ | < | ||
+ | # rrdtool fetch / | ||
+ | 1587484440: 3, | ||
+ | 1587484500: 5, | ||
+ | 1587484560: 2, | ||
+ | 1587484620: 6, | ||
+ | 1587484680: 5, | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ===== fbxcfr.pm | ||
+ | |||
+ | as explained earlier , I copied the nginx module to create mine fbxcfr module . I followed the same process of fetching a URL and parse it to collect interesting values to graph . | ||
+ | |||
+ | ==== Frame ==== | ||
+ | |||
+ | here the " | ||
+ | |||
+ | < | ||
+ | package fbxcfr; | ||
+ | ... | ||
+ | sub fbxcfr_init { | ||
+ | ... | ||
+ | sub fbxcfr_update { | ||
+ | ... | ||
+ | sub fbxcfr_cgi { | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | in order to not forget any replacement occurence of the //nginx// string, I search and replace every occurence of// nginx// with// fbxcfr// | ||
+ | I used VI to do that , here's the magic command to search and repalce all in VI | ||
+ | |||
+ | < | ||
+ | : | ||
+ | </ | ||
+ | |||
+ | * **:** switch to comand | ||
+ | * **1** from 1st line of the file | ||
+ | * **,$** to last line | ||
+ | * **/nginx** search nginx string | ||
+ | * **/ | ||
+ | * **g** globally (if more than one occurence by line | ||
+ | |||
+ | |||
+ | ==== collected values code ===== | ||
+ | |||
+ | I changed a few lines in the code (a dozen ) and commented many . Indeed the nginx module collect all these : | ||
+ | |||
+ | < | ||
+ | $reqs: | ||
+ | </ | ||
+ | |||
+ | from these only the 2 last ones (in/ | ||
+ | |||
+ | not to confused with the original values/ | ||
+ | |||
+ | here are the main changes I did : | ||
+ | |||
+ | < | ||
+ | sub fbxcfr_update { | ||
+ | ... | ||
+ | my $fbxcfr = $config-> | ||
+ | ... | ||
+ | my $in = 0; | ||
+ | my $out = 0; | ||
+ | my $din = 0; | ||
+ | my $dout = 0; | ||
+ | |||
+ | my $url; | ||
+ | |||
+ | if($fbxcfr-> | ||
+ | $url = $fbxcfr-> | ||
+ | } else { | ||
+ | $url = " | ||
+ | } | ||
+ | ... | ||
+ | # | ||
+ | #get line starting with 2 spaces then WAN string and match the 2 digit (\d+) values before string ko/s | ||
+ | if(/ | ||
+ | $din = $1; #print "din: $din\n"; | ||
+ | $dout = $2; #print "dout: $dout\n"; | ||
+ | $din *= 1024; | ||
+ | $dout *= 1024; | ||
+ | |||
+ | |||
+ | | ||
+ | | ||
+ | ... | ||
+ | |||
+ | sub fbxcfr_cgi { | ||
+ | ... | ||
+ | push(@output, | ||
+ | push(@output, | ||
+ | } | ||
+ | # comment out everything related to request , total, reads, writes , wait from the nginx values around line 387 | ||
+ | | ||
+ | push(@tmp, " | ||
+ | push(@tmp, " | ||
+ | push(@tmp, " | ||
+ | push(@tmp, " | ||
+ | push(@tmp, " | ||
+ | push(@tmp, " | ||
+ | push(@tmp, " | ||
+ | ... | ||
+ | @riglim = @{setup_riglim($rigid[2], | ||
+ | undef(@tmp); | ||
+ | undef(@tmpz); | ||
+ | undef(@CDEF); | ||
+ | =END | ||
+ | =cut | ||
+ | # end comment up until around line 626 (quite long !) | ||
+ | |||
+ | # to begin with our In and Out values to graph | ||
+ | push(@tmp, " | ||
+ | push(@tmp, " | ||
+ | push(@tmp, " | ||
+ | push(@tmp, " | ||
+ | push(@tmp, " | ||
+ | push(@tmp, " | ||
+ | push(@tmpz, " | ||
+ | push(@tmpz, " | ||
+ | push(@tmpz, " | ||
+ | push(@tmpz, " | ||
+ | push(@tmpz, " | ||
+ | push(@tmpz, " | ||
+ | ... | ||
+ | return @output; | ||
+ | } | ||
+ | |||
+ | 1; | ||
+ | </ | ||
+ | |||
+ | ==== fbxcfr.pm file ==== | ||
+ | |||
+ | here is the full module file (unzip to get the .pm ) | ||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | ==== image result zoom ==== | ||
+ | {{: | ||