Ejemplo n.º 1
0
import sys, time

sys.path.append("../../")
sys.path.append("../../../")
from communicate.communicatemaster import MasterComm
from logger.logger import Logger

# logger = Logger("CLIENT").log('../logs')
logger = Logger.__call__("CLIENT", "../logs").get_logger()
#import psutil
import subprocess


class Metric(object):
    def __init__(self, **kwargs):
        self.pid = kwargs['pid']
        self.interval = 10
        self.url = kwargs["url"]
        self.client_name = kwargs["name"]
        self.disk_path = kwargs["path"]

    def prettify_out(self):
        cmd = "ps -p {0} -o %cpu,%mem".format(self.pid)
        cmd_out = subprocess.Popen([cmd],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.STDOUT,
                                   shell=True)
        stdout, stderr = cmd_out.communicate()
        s = stdout.decode('utf-8').strip().split()
        return s[-1], s[-2]
Ejemplo n.º 2
0
import sys
import json
sys.path.append("../")
sys.path.append("../../")
sys.path.append("../../../")
from logger.logger import Logger
from db.db import Database
from db.db_operations import Operation
db = Database('client.db', '')

logger = Logger.__call__("MASTER", "../logs").get_logger()


class CallLogic(object):
    def __init__(self, input_stream):
        self.input_stream = input_stream

    def heartbeat_post(self):
        try:
            req_body = self.input_stream
            json_body = json.loads(req_body.decode('utf-8'))
            json_value = json.loads(json_body["value"].replace("'", '"'))
            logger.info(json_body["heartbeat"])
            Operation(db).check_exists_update(
                table="heartbeat",
                column="name",
                item=json_value["name"],
                value=json_value,
                update_value=[json_value["heartbeat_time"]],
                update_column=["heartbeat_time"],
                where_column="name",