Skip to content

Commit

Permalink
fix to support different cgroup directories
Browse files Browse the repository at this point in the history
  • Loading branch information
ckiddo74 committed Sep 21, 2015
1 parent b341e03 commit dbd4937
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions hresmonAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,8 @@ def calculateDerived(matrix):
return updMatrix

def runAgent(pollTime,uuid,metrics,pid):
global CGROUP_DIR

createResourceValuesStore(uuid,metrics)
p = multiprocessing.current_process()
#pidCmd = "ps -fe | grep "+uuid+" | grep -v grep | awk '{print $2}'"
Expand All @@ -585,7 +587,8 @@ def runAgent(pollTime,uuid,metrics,pid):
command = buildCommand(metrics)+commandTimestamp
if "__pid__" in command:
command = command.replace("__pid__",pid)

if ("__cgroup__" in command) and (CGROUP_DIR != ""):
command = command.replace("__cgroup__", CGROUP_DIR)
#print "New command", command

while True:
Expand All @@ -612,6 +615,8 @@ def runAgent(pollTime,uuid,metrics,pid):


def runAgentMulti(pollTime,uuid,metrics,pid):
global CGROUP_DIR

createResourceValuesStoreMulti(uuid,metrics)
p = multiprocessing.current_process()
msg = 'Starting '+p.name+ " to monitor "+pid
Expand Down Expand Up @@ -639,6 +644,8 @@ def runAgentMulti(pollTime,uuid,metrics,pid):
command = commandTimestamp+";"+metrics[i]['command']
if "__pid__" in command:
command = command.replace("__pid__",pid)
if ("__cgroup__" in command) and (CGROUP_DIR != ""):
command = command.replace("__cgroup__", CGROUP_DIR)

#print "COMMAND for METRICS",command

Expand Down Expand Up @@ -666,6 +673,7 @@ def runAgentMulti(pollTime,uuid,metrics,pid):
time.sleep(pollTime)

def runAgentMulti2(pollTime,uuid,metrics,pid):
global CGROUP_DIR
logger.info("Called")
createResourceValuesStoreMulti(uuid,metrics)
p = multiprocessing.current_process()
Expand All @@ -690,7 +698,8 @@ def runAgentMulti2(pollTime,uuid,metrics,pid):
command = commandTimestamp+";"+metrics[key]['command']
if "__pid__" in command:
command = command.replace("__pid__",pid)
print "COMMAND for METRICS:",command
if ("__cgroup__" in command) and (CGROUP_DIR != ""):
command = command.replace("__cgroup__", CGROUP_DIR)

values = subprocess.check_output(command, shell=True).rstrip()

Expand Down Expand Up @@ -720,6 +729,7 @@ def runAgentMulti2(pollTime,uuid,metrics,pid):

def runAgentC(pollTime,uuid,metrics):
#createResourceValuesStore(uuid,metrics)
global CGROUP_DIR
p = multiprocessing.current_process()
pidCmd = "sudo docker ps | grep "+uuid+" | awk '{ print $1 }'"
pid = getPid(uuid,pidCmd)
Expand All @@ -731,6 +741,8 @@ def runAgentC(pollTime,uuid,metrics):
command = buildCommand(metrics)
if "__pid__" in command:
command = command.replace("__pid__",pid)
if ("__cgroup__" in command) and (CGROUP_DIR != ""):
command = command.replace("__cgroup__", CGROUP_DIR)

print "New command", command

Expand Down Expand Up @@ -866,8 +878,17 @@ def main():
else:
PORT_ADDR = 12000
print "No port specified, using "+str(PORT_ADDR)+" as default"


global CGROUP_DIR
if os.path.isdir("/sys/fs/cgroup"):
CGROUP_DIR = "/sys/fs/cgroup"
elif os.path.isdir("/cgroup"):
CGROUP_DIR = "/cgroup"
else:
CGROUP_DIR = ""

try:
print "cgroup dir = ", CGROUP_DIR
init(INTERFACE)
print "Initialization done"
startAPI(IP_ADDR,PORT_ADDR)
Expand Down

0 comments on commit dbd4937

Please sign in to comment.