Commit bfbea3f9 authored by Peter Möller's avatar Peter Möller

Fixed disk size measurement: it all uses Byte now

parent 9ef09759
#!/bin/bash
# Collecting host data and sending it to the CS monitor server
# Linux version
# 2021-06-02/PM
# Getting data for the host web.cs.lth.se"
# 2021-05-17/PM
MONITOR_RESTAPI_URL=https://monitor.cs.lth.se/api/v1
......@@ -49,15 +48,15 @@ AuthStr="\"authentication\": \"${Authentication}\"" # Ex: AuthStr='"authenti
Firewall="$(systemctl list-units --type=service --state=active | egrep -i "^\ *(iptables|firewalld|ufw)" | awk '{print $1}' | cut -d\. -f1)"
FirewWStr="\"firewall\":\"${Firewall}\"" # Ex: FirewWStr='"firewall":"ufw"'
# Disks
Filesystems="$(df -kT -t xfs -t ext4 | egrep "\/" | awk '{print $1" "$2" "$3" "$7}')"
Filesystems="$(df -kB1 -T -t xfs -t ext4 | egrep "\/" | awk '{print $1" "$2" "$3" "$7}')"
# Ex: a number of rows with
# Filesystem Type 1K-blocks Mounted on
# /dev/mapper/vg0-ubuntu ext4 13343816 /
LVMDisks="$(LANG=C lsblk | egrep -i lvm | awk '{print $4" "$NF}' | egrep -vi swap | sort -u)"
# /dev/mapper/vg0-ubuntu ext4 527366881280 /Websites
#(Filesystem Type 1B-blocks Mounted on)
LVMDisks="$(lsblk -b | egrep -i lvm | awk '{print $4" "$NF}' | egrep -vi swap | sort -u)"
# Ex:
# LVMDisks='13G /
# 500G /Websites
# 50G /var/log/apache2'
# LVMDisks='13950255104 /
# 53682896896 /var/log/apache2
# 536866717696 /Websites'
# Flags
# SELinux
......@@ -156,18 +155,20 @@ Flags="\"selinux:$SELinux\", \"kernel:${Kernel}\"$CPUBugsStr, \"arch:${Architect
# partitions
OUTPUT=""
while read -r Filesystem Type Kblocks MountP
while read -r Filesystem Type KBlocks MountP
do
if [ -n "$(echo "$LVMDisks" | egrep "\s${MountP}$")" ]; then
LVM="LVM"
case $(echo "$LVMDisks" | egrep "\s${MountP}$" | awk '{print $1}' | sed 's/[0-9.]*//') in
M) ScaleFactor=1024;;
G) ScaleFactor=1048576;;
T) ScaleFactor=1073741824;;
esac
Kblocks=$(echo "scale=0; $(echo "$LVMDisks" | egrep "\s${MountP}$" | awk '{print $1}' | sed 's/[MGT]//') * $ScaleFactor" | bc -l)
#case $(echo "$LVMDisks" | egrep "\s${MountP}$" | awk '{print $1}' | sed 's/[0-9.]*//') in
#M) ScaleFactor=1024;;
#G) ScaleFactor=1048576;;
#T) ScaleFactor=1073741824;;
#esac
#Kblocks=$(echo "scale=0; $(echo "$LVMDisks" | egrep "\s${MountP}$" | awk '{print $1}' | sed 's/[MGT]//') * $ScaleFactor" | bc -l)
Kblocks=$(echo "scale=0; $(echo "$LVMDisks" | egrep "\s${MountP}$" | awk '{print $1}') / 1024" | bc -l)
else
LVM=""
Kblocks=$(echo "scale=0; $KBlocks / 1024" | bc -l)
fi
OUTPUT+="{ \"partition\": \"$Filesystem\", \"mount-point\":\"$MountP\", \"type\":\"$Type\", \"total-kb\":$Kblocks, \"storage\":\"${LVM:-direct}\" },"
done <<< "$Filesystems"
......@@ -275,4 +276,3 @@ curl --silent -X POST "$MONITOR_RESTAPI_URL/hosts/monitor?token=$SOURCE_TOKEN" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d "$OBSERVATIONS"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment