Skip to content

Commit

Permalink
Merge pull request #136 from ei-grad/master
Browse files Browse the repository at this point in the history
Fix __check_mem
  • Loading branch information
direvius committed Feb 14, 2015
2 parents e02e721 + f05abad commit 9e97e75
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions yandextank/plugins/ResourceCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
import time
import logging

import psutil

from yandextank.core import AbstractPlugin
import yandextank.core as tankcore


class ResourceCheckPlugin(AbstractPlugin):
''' Plugin to check system resources '''
'''Plugin to check system resources'''
SECTION = "rcheck"

@staticmethod
def get_key():
return __file__


def __init__(self, core):
''' Constructor '''
AbstractPlugin.__init__(self, core)
Expand Down Expand Up @@ -55,8 +56,8 @@ def __check_disk(self):
res = tankcore.execute(cmd, True, 0.1, True)
logging.debug("Result: %s", res)
if not len(res[1]):
self.log.debug("No disk usage info: %s", res[2])
return
self.log.debug("No disk usage info: %s", res[2])
return
disk_free = res[1]
self.log.debug("Disk free space: %s/%s", disk_free.strip(), self.disk_limit)
if int(disk_free.strip()) < self.disk_limit:
Expand All @@ -66,8 +67,8 @@ def __check_disk(self):

def __check_mem(self):
''' raise exception on RAM exceeded '''
cmd = "free -m | awk '$1==\"-/+\" {print $4}'"
mem_free = int(tankcore.execute(cmd, True, 0.1, True)[1].strip())
mem_free = psutil.virtual_memory().available / 2 ** 20
self.log.debug("Memory free: %s/%s", mem_free, self.mem_limit)
if mem_free < self.mem_limit:
raise RuntimeError("Not enough resources: free memory less than %sMB: %sMB" % (self.mem_limit, mem_free))
raise RuntimeError("Not enough resources: free memory less "
"than %sMB: %sMB" % (self.mem_limit, mem_free))

0 comments on commit 9e97e75

Please sign in to comment.