diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2023-02-12 01:05:52 +0100 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2023-02-12 01:05:52 +0100 |
commit | 813497a936beab893d1fdb82eed0aeb5a0b1feab (patch) | |
tree | c897f804e6b96ee3458f679b2aa605d3f7d8b9d3 | |
parent | a7aee0c454fd830b4475d5ce1a334a51be05dfaf (diff) | |
download | automato-813497a936beab893d1fdb82eed0aeb5a0b1feab.tar.gz |
untested states
-rw-r--r-- | automato/state.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/automato/state.py b/automato/state.py index d34044c..dd08e1b 100644 --- a/automato/state.py +++ b/automato/state.py @@ -90,3 +90,41 @@ class UserSessionState(State): self._data[name] = 0 self._data[name] += 1 + +class LinuxMemoryState(State): + def __init__(self, transport: transport.SshTransport, ttl: int = 60): + super().__init__(transport, ttl) + + # this is not needed. it's here to shut up pylint + self._transport = transport + + def _collect(self): + mem_data = self._transport.execHandleStderror('cat /proc/meminfo').decode('utf-8') + + self._data['mem'] = {} + for l in mem_data.splitlines(): + arr = l.split() + key = arr[0].strip(':') + val = arr[1] + + self._data['mem'][key] = val + + logger.debug(f'Memory: {key} = {val}') + +class LinuxLoadState(State): + def __init__(self, transport: transport.SshTransport, ttl: int = 30): + super().__init__(transport, ttl) + + # this is not needed. it's here to shut up pylint + self._transport = transport + + def _collect(self): + load_raw = self._transport.execHandleStderror('cat /proc/loadavg').decode('utf-8') + + data = load_raw.split(None,4) + + self._data = {} + + self._data['1'] = data[0] + self._data['5'] = data[1] + self._data['15'] = data[2] |