diff --git a/mikrotik/mt_system b/mikrotik/mt_system index 2a5ca7f..e49cd51 100644 --- a/mikrotik/mt_system +++ b/mikrotik/mt_system @@ -16,20 +16,48 @@ # on the router # /user add name=munin group=read password=hallowelt address= +# voltage: 24.5V +# temperature: 46C +# uptime: 1w6d17h12m25s +# version: 6.48.4 (stable) +# build-time: Aug/18/2021 06:43:27 +# factory-software: 6.46.3 +# free-memory: 209.9MiB +# total-memory: 256.0MiB +# cpu: MIPS 1004Kc V2.15 +# cpu-count: 4 +# cpu-frequency: 880MHz +# cpu-load: 0% +# free-hdd-space: 4760.0KiB +# total-hdd-space: 16.3MiB +# write-sect-since-reboot: 46412 +# write-sect-total: 62012 +# bad-blocks: 0% +# architecture-name: mmips +# board-name: hEX +# platform: MikroTik +# # CPU LOAD IRQ DISK +# 0 cpu0 0% 0% 0% +# 1 cpu1 1% 1% 0% +# 2 cpu2 0% 0% 0% +# 3 cpu3 1% 0% 0% +# + # pruefe ob sshpass installiert ist if [[ $(dpkg -l sshpass > /dev/null 2>&1) -ne "0" ]] ; then echo "could not find sshpass" exit 1 fi -data=$(sshpass -p $ssh_password ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $ssh_user@$ssh_host -q ':delay 6s; /system health print; /system resource print; /sytem resource cpu print') - +data=$(sshpass -p $ssh_password ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $ssh_user@$ssh_host -q ':delay 1s; /system health print; /system resource print; /system resource cpu print') +#data=$(cat output) # setze user und passwort ssh_user=${ssh_user:-user} ssh_password=${ssh_password:-password} ssh_host=${ssh_host:-192.168.2.1} name=${name:-mikrotik} + # wenn parameter = ... if [ "$1" = "autoconf" ]; then echo yes @@ -38,121 +66,117 @@ fi if [ "$1" = "config" ]; then while read -r line; do - if echo $line | grep 'temperature:' > /dev/null; then - # setze optionen - echo multigraph mikrotik_temperature_graph_$name - echo graph_title temperature $name # Titelzeile - echo graph_vlabel °C # Text links, hochkant - echo graph_category mikrotik # Kategorie - echo graph_args -l 0 - echo temperature.label cpu temperature - echo temperature.warning 75 - echo temperature.critical 90 - fi - if echo $line | grep 'voltage:' > /dev/null; then - echo multigraph mikrotik_voltage_graph_$name - echo graph_title voltage $name - echo graph_vlabel volt - echo graph_category mikrotik - echo graph_args -l 0 - echo voltage.label voltage - fi - if echo $line | grep 'bad-blocks:' > /dev/null; then - echo multigraph mikrotik_bad_blocks_graph_$name - echo graph_title bad blocks $name - echo graph_vlabel % - echo graph_category mikrotik - echo graph_args -l 0 --upper-limit 100 - echo bad_blocks.label bad_blocks - echo bad_blocks.warning 2 - echo bad_blocks.critical 25 - fi - if echo $line | grep 'write-sect-total:' > /dev/null; then - echo multigraph mikrotik_write_sect_total_graph_$name - echo graph_title Total sector writes $name - echo graph_vlabel count - echo graph_category mikrotik - echo graph_args -l 0 - echo write_sect_total.label write_sect_total - fi - if echo $line | grep 'write-sect-since-reboot:' > /dev/null; then - echo multigraph mikrotik_write_sect_since_reboot_graph_$name - echo graph_title Sector writes since reboot $name - echo graph_vlabel count - echo graph_category mikrotik - echo graph_args -l 0 - echo write_sect_since_reboot.label write_sect_since_reboot - fi - if echo $line | grep 'cpu-load:' > /dev/null; then - echo multigraph mikrotik_cpu_load_graph_$name - echo graph_title cpu load $name - echo graph_vlabel % - echo graph_category mikrotik - echo graph_args -l 0 --upper-limit 100 - echo cpu_load.label cpu_load - echo cpu_load.warning 75 - echo cpu_load.critical 90 - echo cpu_load.draw AREA - fi - if echo $line | grep 'cpu-count:' > /dev/null; then - echo multigraph mikrotik_cpu_load_detailed_graph_$name - echo graph_title cpu load detailed $name - echo graph_vlabel % - echo graph_category mikrotik - echo graph_args -l 0 --upper-limit 100 - echo cpu_load_detailed.label cpu_load_detailed - fi + echo $line| awk '/voltage:/{ + print "multigraph mikrotik_voltage_graph_""'"$name"'"; + print "graph_title voltage " "'"$name"'"; + print "graph_vlabel volt"; + print "graph_category mikrotik"; + print "graph_args -l 0"; + print "voltage.label voltage"; + }' + echo $line| awk '/bad-blocks:/{ + print "multigraph mikrotik_bad_blocks_graph_""'"$name"'"; + print "graph_title Total sector writes " "'"$name"'"; + print "graph_vlabel %"; + print "graph_category mikrotik"; + print "graph_args -l 0 --upper-limit 100"; + print "bad_blocks.label bad_blocks"; + print "bad_blocks.warning 2"; + print "bad_blocks.critical 25"; + }' + echo $line| awk '/write-sect-total:/{ + print "multigraph mikrotik_write_sect_total_graph_""'"$name"'"; + print "graph_title Total sector writes " "'"$name"'"; + print "graph_vlabel count"; + print "graph_category mikrotik"; + print "graph_args -l 0"; + print "write_sect_total.label write_sect_total"; + }' + echo $line| awk '/write-sect-since-reboot:/{ + print "multigraph mikrotik_write_sect_since_reboot_graph_""'"$name"'"; + print "graph_title Sector writes since reboot " "'"$name"'"; + print "graph_vlabel count"; + print "graph_category mikrotik"; + print "graph_args -l 0"; + print "write_sect_since_reboot.label write_sect_since_reboot"; + }' + echo $line| awk '/cpu-load:/{ + print "multigraph mikrotik_cpu_load_graph_""'"$name"'"; + print "graph_title cpu load " "'"$name"'"; + print "graph_vlabel %"; + print "graph_category mikrotik"; + print "graph_args -l 0 --upper-limit 100"; + print "cpu_load.label cpu_load"; + print "cpu_load.warning 75"; + print "cpu_load.critical 90"; + print "cpu_load.draw AREA" + }' + echo $line| awk '/temperature:/{ + print "multigraph mikrotik_temperature_graph_""'"$name"'"; + print "graph_title temperature " "'"$name"'"; + print "graph_vlabel °C"; + print "graph_category mikrotik"; + print "graph_args -l 0"; + print "temperature.label cpu temperature"; + print "temperature.warning 75"; + print "temperature.critical 90"; + }' done <<< "$data" + if [ "$MUNIN_CAP_DIRTYCONFIG" = "1" ]; then + echo $line| awk '/voltage:/{ + gsub(/V/,"",$2); + print "voltage.value " $2 + }' + echo $line| awk '/bad-blocks:/{ + gsub(/%/,"",$2); + print "bad_blocks.value " $2 + }' + echo $line| awk '/write-sect-total:/{ + print "write_sect_total.value " $2 + }' + echo $line| awk '/write-sect-since-reboot:/{ + print "write_sect_since_reboot.value " $2 + }' + echo $line| awk '/cpu-load:/{ + gsub(/%/,"",$2); + print "cpu_load.value " $2 + }' + echo $line| awk '/temperature:/{ + gsub(/C/,"",$2); + print "temperature.value " $2 + }' + fi exit 0 fi #echo debug ###### #echo $ssh_user #echo $ssh_password #echo $ssh_host - -while read -r line; do - if echo $line | grep 'temperature:' > /dev/null; then - echo $line | grep 'temperature:' | sed 's/C//g' | awk '{ print "multigraph mikrotik_temperature_graph_" "'"$name"'"; print "temperature.value "$2 }' - fi - if echo $line | grep 'voltage:' > /dev/null; then - echo $line | grep 'voltage:' | sed 's/V//g' | awk '{ print "multigraph mikrotik_voltage_graph_" "'"$name"'"; print "voltage.value "$2 }' - fi - if echo $line | grep 'cpu-load:' > /dev/null; then - echo $line | grep 'cpu-load:' | sed 's/%//g' | awk '{ print "multigraph mikrotik_cpu_load_graph_" "'"$name"'"; print "cpu_load.value "$2 }' - fi - if echo $line | grep 'bad-blocks:' > /dev/null; then - echo $line | grep 'bad-blocks:' | sed 's/%//g' | awk '{ print "multigraph mikrotik_bad_blocks_graph_" "'"$name"'"; print "bad_blocks.value "$2 }' - fi - if echo $line | grep 'write-sect-since-reboot:' > /dev/null; then - echo $line | grep 'write-sect-since-reboot:' | awk '{ print "multigraph mikrotik_write_sect_since_reboot_graph_" "'"$name"'"; print "write_sect_since_reboot.value "$2 }' - fi - if echo $line | grep 'write-sect-total:' > /dev/null; then - echo $line | grep 'write-sect-total:' | awk '{ print "multigraph mikrotik_write_sect_total_graph_" "'"$name"'"; print "write_sect_total.value "$2 }' - fi - if echo $line | grep 'cpu-count' > /dev/null; then - anzahl_cpu=$(echo $line | grep 'cpu-count:' | awk '{ print $2 }' | tr -dc '[:print:]') - # tr? - # error: ")syntax error: invalid arithmetic operator (error token is " - # https://stackoverflow.com/questions/23816264/remove-all-special-characters-and-case-from-string-in-bash - # --> https://www.shell-tips.com/bash/math-arithmetic-calculation/ - echo multigraph mikrotik_cpu_load_detailed_graph_$name - echo vor schleife - echo $line | grep cpu0 - c=0 - echo c $c - echo anzahl $anzahl_cpu - while [ "$c" -lt "$anzahl_cpu" ] - do - echo in schleife - #FEHLER IST DAS GREP NIE CPU0 us ausgibt, hier fehlt before/after - echo $line | grep cpu$c | sed 's/%//g' | awk '{ print "cpu_load_detailed_graph_load cpu" "'"$c"'" $3; print "cpu_load_detailed_graph_irq cpu" "'"$c"'" $4; print "cpu_load_detailed_graph_disk cpu" "'"$c"'" $5}' - c=$(( $c + 1 )) - done - fi -done <<< "$data" - +echo $line| awk '/voltage:/{ + gsub(/V/,"",$2); + print "voltage.value " $2 + }' +echo $line| awk '/bad-blocks:/{ + gsub(/%/,"",$2); + print "bad_blocks.value " $2 + }' +echo $line| awk '/write-sect-total:/{ + print "write_sect_total.value " $2 + }' +echo $line| awk '/write-sect-since-reboot:/{ + print "write_sect_since_reboot.value " $2 + }' +echo $line| awk '/cpu-load:/{ + gsub(/%/,"",$2); + print "cpu_load.value " $2 + }' +echo $line| awk '/temperature:/{ + gsub(/C/,"",$2); + print "temperature.value " $2 + }' exit 0 +# #suchbegriff #name @@ -170,3 +194,18 @@ exit 0 # CPU LOAD IRQ DISK #0 cpu0 1% 0% 0% #1 cpu1 0% 0% 0% + + +# echo $line| awk '/bad-blocks:/{ +# print "multigraph mikrotik_bad_blocks_graph_""'"$name"'"; +# print "graph_title Total sector writes " "'"$name"'"; +# print "graph_vlabel %"; +# print "graph_category mikrotik"; +# print "graph_args -l 0 --upper-limit 100"; +# print "bad_blocks.label bad_blocks"; +# print "bad_blocks.warning 2"; +# print "bad_blocks.critical 25"; +# gsub(/%/,"",$2); +# print "bad_blocks.value " $2 +# }' +# IN DOKU mit erklärung