From 77f635962133fc26855a78dd8a3163b29626455e Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Tue, 21 Sep 2021 21:18:23 +0200 Subject: [PATCH] mem und free als func --- mikrotik/mt_system | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/mikrotik/mt_system b/mikrotik/mt_system index ee36def..c1460ba 100644 --- a/mikrotik/mt_system +++ b/mikrotik/mt_system @@ -68,6 +68,18 @@ function get_data { # hole daten per ssh 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; /system resource cpu print; /system identity print') } +function get_mem_total { + mem_total=$( + while read -r line; do + echo $line | awk '/total-memory:/{ gsub(/MiB/,"",$2); print $2 }' | tr -dc '[0-9.]' + done <<< "$data") +} +function get_mem_free { + mem_free=$( + while read -r line; do + echo $line | awk '/free-memory:/{ gsub(/MiB/,"",$2); print $2 }' | tr -dc '[0-9.]' + done <<< "$data") +} function get_voltage_label { while read -r line; do # für jede zeile in... ; siehe "done" @@ -265,6 +277,8 @@ function get_cpu_value { } function get_memory_label { + get_mem_total + get_mem_free while read -r line; do echo $line | awk '/free-memory:/{ print "multigraph memory_graph_""'"$name"'"; @@ -297,14 +311,7 @@ function get_memory_value { done <<< "$data" # berechne used-memory # gesamt + frei = benutzt - mem_total=$( - while read -r line; do - echo $line | awk '/total-memory:/{ gsub(/MiB/,"",$2); print $2 }' | tr -dc '[0-9.]' - done <<< "$data") - mem_free=$( - while read -r line; do - echo $line | awk '/free-memory:/{ gsub(/MiB/,"",$2); print $2 }' | tr -dc '[0-9.]' - done <<< "$data") + echo used_memory.value $(echo $mem_total-$mem_free| bc) # prufe noch ob war gesetzt }