Skip to content

Instantly share code, notes, and snippets.

@oernii
Created December 10, 2014 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oernii/6caa43a942f1b3b2410a to your computer and use it in GitHub Desktop.
Save oernii/6caa43a942f1b3b2410a to your computer and use it in GitHub Desktop.
#!/bin/bash
# $Id: ovirt-get-accounting-info,v 1.3 2013/06/13 10:01:26 oernii Exp $
vms=`find /cgroup/blkio/libvirt/qemu/ -maxdepth 1 -mindepth 1 -type d -printf "%f\n"`
IGNORED="/dev/mapper/1ISCSI_msa1000_146 /dev/mapper/1ISCSI_msa1000_36 /dev/mapper/1STORAGE_interim /dev/mapper/1STORAGE_storage1 /dev/mapper/1STORAGE_storage2 /dev/mapper/1STORAGE_storage3"
IGNORED_REGEX=""
DM_PREFIX=253
for ig in $IGNORED
do
if [ ! -e $ig ]; then continue; fi
MN=`stat -L $ig --printf "%T"`
MN=`echo $((16#$MN))`
if [ ${#IGNORED_REGEX} -gt 0 ]
then
IGNORED_REGEX=$IGNORED_REGEX"|^$DM_PREFIX:$MN "
else
IGNORED_REGEX="^$DM_PREFIX:$MN "
fi
done
if [ ${#HOST} -eq 0 ] ; then HOST=`hostname -s`; fi
for vm in $vms
do
(
echo -n "$HOST:$vm:"
egrep -v "$IGNORED_REGEX" /cgroup/blkio/libvirt/qemu/$vm/blkio.throttle.io_serviced | grep ^253:.*Read | cut -f3 -d " " | paste -sd+ | bc
echo -n ":"
egrep -v "$IGNORED_REGEX" /cgroup/blkio/libvirt/qemu/$vm/blkio.throttle.io_serviced | grep ^253:.*Write | cut -f3 -d " " | paste -sd+ | bc
echo -n ":"
egrep -v "$IGNORED_REGEX" /cgroup/blkio/libvirt/qemu/$vm/blkio.throttle.io_service_bytes | grep ^253:.*Read | cut -f3 -d " " | paste -sd+ | bc
echo -n ":"
egrep -v "$IGNORED_REGEX" /cgroup/blkio/libvirt/qemu/$vm/blkio.throttle.io_service_bytes | grep ^253:.*Write | cut -f3 -d " " | paste -sd+ | bc
echo -n ":"
cat /cgroup/cpuacct/libvirt/qemu/$vm/cpuacct.usage
) | tr -d '\n'
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment