collectd configuration
This commit is contained in:
@@ -1,25 +1,77 @@
|
||||
#!/bin/bash
|
||||
COLLECTION=sepia
|
||||
INTERVAL=90
|
||||
#!/usr/bin/python3
|
||||
|
||||
DIRS=$(cat <<LIST
|
||||
/host/root/media/data/Inverter
|
||||
/host/root/media/data/Monique
|
||||
/host/root/media/data/Music
|
||||
/host/root/media/data/Peter
|
||||
/host/root/media/data/Photographs
|
||||
/host/root/media/data/Raw
|
||||
/host/root/media/data/Sanne
|
||||
/host/root/media/data/Wii
|
||||
LIST
|
||||
)
|
||||
#
|
||||
# Imports
|
||||
#
|
||||
import sys
|
||||
import time
|
||||
import subprocess
|
||||
import argparse
|
||||
|
||||
while :; do
|
||||
SECONDS=0
|
||||
for DIR in $DIRS; do
|
||||
SIZE=$(du -cs $DIR | tail -1 | awk '{print $1}')
|
||||
NAME=$(echo $DIR | sed 's/.//' | tr / - )
|
||||
echo "PUTVAL $COLLECTION/exec-du-$NAME/gauge-size interval=$INTERVAL N:$SIZE"
|
||||
done
|
||||
sleep $((INTERVAL-$SECONDS))
|
||||
done
|
||||
|
||||
#
|
||||
# Methods
|
||||
#
|
||||
def get_disk_usage(path, human_readable):
|
||||
"""disk usage in human readable format (e.g. '2,1GB')"""
|
||||
arguments = "-sh" if human_readable else "-s"
|
||||
command = "du %s %s" % (arguments, path)
|
||||
status, output = subprocess.getstatusoutput(command)
|
||||
|
||||
if status != 0:
|
||||
raise Exception(command)
|
||||
|
||||
disk_usage = output.split()[0]
|
||||
if not human_readable:
|
||||
# du reports in units of 1024 bytes, convert to plain number of bytes
|
||||
disk_usage = int(disk_usage) * 1024
|
||||
return disk_usage
|
||||
|
||||
|
||||
#
|
||||
# Directories to scan
|
||||
#
|
||||
hostname = "sepia"
|
||||
interval = 10
|
||||
directories = list()
|
||||
|
||||
directories.append(["inverter", "/host/root/media/data/Inverter"])
|
||||
directories.append(["monique", "/host/root/media/data/Monique"])
|
||||
directories.append(["music", "/host/root/media/data/Music"])
|
||||
directories.append(["peter", "/host/root/media/data/Peter"])
|
||||
directories.append(["photographs", "/host/root/media/data/Photographs"])
|
||||
directories.append(["sanne", "/host/root/media/data/Sanne"])
|
||||
directories.append(["wii", "/host/root/media/data/Wii"])
|
||||
|
||||
#
|
||||
# Command line arguments
|
||||
#
|
||||
parser = argparse.ArgumentParser(description="Get DU disk usage")
|
||||
parser.add_argument("-s", action="store_true", help="print in human readable format")
|
||||
args = parser.parse_args()
|
||||
human_readable = args.s
|
||||
|
||||
|
||||
#
|
||||
# Main
|
||||
#
|
||||
if human_readable:
|
||||
for (name, path) in directories:
|
||||
disk_usage = get_disk_usage(path, human_readable)
|
||||
print(("%s: %s" % (name, disk_usage)))
|
||||
else:
|
||||
# RRD mode
|
||||
while True:
|
||||
for (name, path) in directories:
|
||||
disk_usage = get_disk_usage(path, human_readable)
|
||||
timestamp = int(time.time())
|
||||
size = float(disk_usage)
|
||||
print(
|
||||
(
|
||||
"PUTVAL {}/exec-du_{}/gauge-size {}:{:.1f}".format(
|
||||
hostname, name, timestamp, size
|
||||
)
|
||||
)
|
||||
)
|
||||
sys.stdout.flush()
|
||||
time.sleep(interval)
|
||||
|
||||
Reference in New Issue
Block a user