aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2020-03-22 20:02:51 -0400
committerKevin O'Connor <kevin@koconnor.net>2020-03-22 20:02:51 -0400
commit6aae62542c2b571c6533565ff7d673d448ed07e0 (patch)
treeea515be4325ceb4f7788c1cd95caf6bbc54684e6
parentf3667fd4536dfa2b9031ffa8e5da6b3bcac851e3 (diff)
downloadkutter-6aae62542c2b571c6533565ff7d673d448ed07e0.tar.gz
kutter-6aae62542c2b571c6533565ff7d673d448ed07e0.tar.xz
kutter-6aae62542c2b571c6533565ff7d673d448ed07e0.zip
statistics: Add system stats
Report os load, process cpu time, and system available memory to each statistics report. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--klippy/extras/statistics.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/klippy/extras/statistics.py b/klippy/extras/statistics.py
index 84186ed1..f79c7add 100644
--- a/klippy/extras/statistics.py
+++ b/klippy/extras/statistics.py
@@ -1,9 +1,24 @@
# Support for logging periodic statistics
#
-# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
+# Copyright (C) 2018-2020 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import logging
+import os, time, logging
+
+def get_os_stats(eventtime):
+ # Get core usage stats
+ msg = "sysload=%.2f cputime=%.3f" % (os.getloadavg()[0], time.clock())
+ # Get available system memory
+ try:
+ f = open("/proc/meminfo", "rb")
+ data = f.read()
+ f.close()
+ for line in data.split('\n'):
+ if line.startswith("MemAvailable:"):
+ msg = "%s memavail=%s" % (msg, line.split()[1])
+ except:
+ pass
+ return (False, msg)
class PrinterStats:
def __init__(self, config):
@@ -21,6 +36,7 @@ class PrinterStats:
def generate_stats(self, eventtime):
stats = [cb(eventtime) for cb in self.stats_cb]
if max([s[0] for s in stats]):
+ stats.append(get_os_stats(eventtime))
logging.info("Stats %.1f: %s", eventtime,
' '.join([s[1] for s in stats]))
return eventtime + 1.