From e9cdcc95715cba566db77fd1e995a4198e122f01 Mon Sep 17 00:00:00 2001 From: Anael Beutot Date: Thu, 3 May 2012 17:44:40 +0200 Subject: [PATCH] Rewrote host tags with decorators. --- ccnode/host/tags.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/ccnode/host/tags.py b/ccnode/host/tags.py index 19e28f3..8d57532 100644 --- a/ccnode/host/tags.py +++ b/ccnode/host/tags.py @@ -10,12 +10,14 @@ from socket import getfqdn import psutil +from ccnode.tags import ttl, refresh + +@ttl(3600 * 24) # one day +@refresh(5) def h(): """Hostname tag.""" return getfqdn() -h.ttl = 3600 * 24 # one day -h.refresh = 5 # CPU related tags @@ -39,32 +41,31 @@ def cpu(): return None +@ttl(10) +@refresh(2) def cpuuse(): """CPU usage in percentage.""" return u'%.1f' % psutil.cpu_percent() -cpuuse.ttl = 10 -cpuuse.refresh = 2 # memory related tags def mem(): """Total physical memory available on system.""" return unicode(psutil.avail_phymem() + psutil.used_phymem()) -mem.ttl = -1 # FIXME validate ttl +@ttl(5) +@refresh(10) def memfree(): """Available physical memory on system.""" return unicode(psutil.avail_phymem()) -memfree.ttl = 5 -memfree.refresh = 10 +@ttl(5) +@refresh(10) def memused(): """Used physical memory on system.""" return unicode(psutil.used_phymem()) -memused.ttl = 5 -memused.refresh = 10 # disks related tags @@ -126,13 +127,15 @@ def uname(): return u' '.join(os_.uname()) or None +@ttl(5) +@refresh(5) def uptime(): """Uptime of the system in seconds.""" return open('/proc/uptime').read().split()[0].split(u'.')[0] or None -uptime.ttl = 5 -uptime.refresh = 5 +@ttl(5) +@refresh(5) def load(): """Average of the number of processes in the run queue over the last 1, 5 and 15 minutes.""" @@ -142,5 +145,3 @@ def load(): except OSError: pass return load_ -load.ttl = 5 -load.refresh = 5 -- GitLab