configure collectd
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python3
|
||||
|
||||
#
|
||||
# Imports
|
||||
#
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import commands
|
||||
import subprocess
|
||||
import argparse
|
||||
|
||||
|
||||
@@ -14,13 +13,12 @@ import argparse
|
||||
# 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'
|
||||
path = os.path.realpath(path)
|
||||
command = 'sudo du %s %s' % (arguments, path)
|
||||
status, output = commands.getstatusoutput(command)
|
||||
"""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 is not 0:
|
||||
if status != 0:
|
||||
raise Exception(command)
|
||||
|
||||
disk_usage = output.split()[0]
|
||||
@@ -29,13 +27,13 @@ def get_disk_usage(path, human_readable):
|
||||
disk_usage = int(disk_usage) * 1024
|
||||
return disk_usage
|
||||
|
||||
|
||||
#
|
||||
# Directories to scan
|
||||
#
|
||||
hostname = 'server'
|
||||
hostname = 'shuttle'
|
||||
interval = 10
|
||||
directories = [
|
||||
#['bram', '/media/data/Personal/Bram'],
|
||||
['rik', '/media/data/Personal/Rik'],
|
||||
['books', '/media/data/Shared/Books'],
|
||||
['games', '/media/data/Shared/Games'],
|
||||
@@ -45,15 +43,14 @@ directories = [
|
||||
['music', '/media/data/Shared/Music'],
|
||||
['photographs', '/media/data/Shared/Photographs'],
|
||||
['pictures', '/media/data/Shared/Pictures'],
|
||||
['raw', '/media/data/Shared/Raw'],
|
||||
['software', '/media/data/Shared/Software']
|
||||
]
|
||||
|
||||
#
|
||||
# Command line arguments
|
||||
#
|
||||
parser = argparse.ArgumentParser(description='Get BTRFS disk usage')
|
||||
parser.add_argument('-s', action='store_true', help='print in human readable format')
|
||||
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
|
||||
|
||||
@@ -61,10 +58,10 @@ human_readable = args.s
|
||||
#
|
||||
# Main
|
||||
#
|
||||
if (human_readable):
|
||||
if human_readable:
|
||||
for (name, path) in directories:
|
||||
disk_usage = get_disk_usage(path, human_readable)
|
||||
print('%s: %s' % (name, disk_usage))
|
||||
print(("%s: %s" % (name, disk_usage)))
|
||||
else:
|
||||
# RRD mode
|
||||
while True:
|
||||
@@ -72,6 +69,12 @@ else:
|
||||
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))
|
||||
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