aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hoffmann <volker@cheleb.net>2016-06-13 20:48:39 +0200
committerVolker Hoffmann <volker@cheleb.net>2016-06-14 09:01:41 +0200
commitf742d112d11e1fa8a3dc2e27bcd6ad1e610b335b (patch)
tree5be737371d2a01a458a6bb5a16e29ebc46fa9bae
parente26482966c5a09a0ec2fe0fc038b249f7ab2334f (diff)
feat: basic filesystem stats
-rw-r--r--Common/fs.py23
-rw-r--r--ticker.py20
2 files changed, 42 insertions, 1 deletions
diff --git a/Common/fs.py b/Common/fs.py
new file mode 100644
index 0000000..39d5c78
--- /dev/null
+++ b/Common/fs.py
@@ -0,0 +1,23 @@
+"""
+Filesystem Stuff.
+"""
+
+import os
+
+
+def get_fs_usage(fs='/volume1'):
+ """
+ Get filesystem usage for a given mount point.
+
+ http://stackoverflow.com/a/12327880
+ https://docs.python.org/release/2.6.8/library/os.html#os.statvfs
+ http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/statvfs.h.html
+
+ @param: fs - Filesystem Mount Point [String]
+ @return: usage - Usage (free, total, used) (Bytes) [Dict of Floats]
+ """
+ statvfs = os.statvfs(fs)
+ total = statvfs.f_bsize * statvfs.f_blocks
+ free = statvfs.f_bsize * statvfs.f_bavail
+ used = total - free
+ return { 'free': free, 'total': total, 'used': used }
diff --git a/ticker.py b/ticker.py
index cfde2d5..8666504 100644
--- a/ticker.py
+++ b/ticker.py
@@ -5,6 +5,7 @@ Read, Parse, Post Stats to InfluxDB.
import Common.sensors as sensors
import Common.influx as influx
import Common.net as net
+import Common.fs as fs
import socket
import argparse
@@ -17,10 +18,12 @@ parser.add_argument('--netatmo', action='store_true', \
help="Query and Push Netatmo Data.")
parser.add_argument('--vpn', action='store_true', \
help="Query and Push VPN Status.")
+parser.add_argument('--fs', action='store_true', \
+ help="Filesystem Stats.")
args = parser.parse_args()
# Sanity Check
-if not args.netatmo and not args.vpn:
+if not args.netatmo and not args.vpn and not args.fs:
raise Exception('Nothing Queried. Terminating.')
# #############################################################################
@@ -36,11 +39,17 @@ if args.vpn:
is_vpn_connected = net.is_vpn_connected()
# #############################################################################
+# Get Filesystem Stats
+# #############################################################################
+if args.fs:
+ fs_usage = fs.get_fs_usage(fs='/volume1')
+
# #############################################################################
# Get Hostname
# #############################################################################
hostname = socket.gethostname()
+# #############################################################################
# Build Data Post
# NB: For InfluxDB >=0.9.3, integer data points require a trailing i.
# For example, ncpus_allocated,parititon=cpu value=5i
@@ -64,6 +73,15 @@ if args.vpn:
( hostname, is_vpn_connected )
lines.append(line)
+# Filesystem Status
+if args.fs:
+ line_01 = "fs_free,host=%s value=%ii" % ( hostname, fs_usage['free'] )
+ line_02 = "fs_total,host=%s value=%ii" % ( hostname, fs_usage['total'] )
+ line_03 = "fs_used,host=%s value=%ii" % ( hostname, fs_usage['used'] )
+ lines.append(line_01)
+ lines.append(line_02)
+ lines.append(line_03)
+
# Join
data = "\n".join(lines)