diff options
Diffstat (limited to 'overseerlib/plugins/ramfree_plugin.py')
-rw-r--r-- | overseerlib/plugins/ramfree_plugin.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/overseerlib/plugins/ramfree_plugin.py b/overseerlib/plugins/ramfree_plugin.py new file mode 100644 index 0000000..b1161ee --- /dev/null +++ b/overseerlib/plugins/ramfree_plugin.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +# +# Copyright (C) 2014 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +import cliapp + +import overseerlib + + +class RamFreePlugin(cliapp.Plugin): + + def enable(self): + self.app.add_subcommand('ramfree', self.ramfree, + arg_synopsis='THRESHOLD') + + def disable(self): + pass + + def ramfree(self, args): + if len(args) < 1: + raise cliapp.AppException('ramfree requires a threshold to be ' + 'specified') + threshold = args[0] + threshold_type = args[1] if len(args) == 2 else 'high' + + if threshold.isdigit() == False: + threshold = overseerlib.app.human_to_bytes(threshold) + + with open('/proc/meminfo') as f: + for line in f: + if line.startswith('MemFree'): + free = line.split()[1] + free = int(free) * 1024 + + message = '' + if free >= threshold: + message+=('%s bytes of memory free\n' % free) + if message != '': + print message |