def run(self):
        try:
            utc_time = self.get_now_utc_time()
            usage_rate = Host.get_cpu_rate()
            event = {
                "time": utc_time,
                "host": self.hostname,
                "type": "cpu",
                "type_instance": "usage_rate",
                "value": usage_rate
            }
            self.octopusd.sendMessage(self.paramter['output'], event)

            loadavg = Host.get_load_stat()
            event = {
                "time": utc_time,
                "host": self.hostname,
                "type": "cpu",
                "type_instance": "lavg_1",
                "value": loadavg['lavg_1']
            }
            self.octopusd.sendMessage(self.paramter['output'], event)

        except Exception, ex:
            print ex
示例#2
0
def uptime():
    try:
        hostUtil = HostUtil()
        message = hostUtil.get_uptime_stat()
    except Exception, e:
        message = "error get uptime, Ex:%s" % (str(e))
        return Response.make_json_response(message, success=False, code=-1)
示例#3
0
def execCommand():
    try:
        hostUtil = HostUtil()
        message = hostUtil.exec_command(request.values.get("cmd"))
    except Exception, e:
        message = "error get sys process list, cmd(%s) Ex:%s" % (
            request.values.get("cmd"), str(e))
        return Response.make_json_response(message, success=False, code=-1)
示例#4
0
def getProcessList():

    try:
        hostUtil = HostUtil()
        message = hostUtil.processList()
    except Exception, e:
        message = "error get sys process list, Ex:%s" % (str(e))
        return Response.make_json_response(message, success=False, code=-1)
示例#5
0
def memInfo():
    try:
        hostUtil = HostUtil()
        message = hostUtil.get_memory_stat()

    except Exception, e:
        message = "error get mem info, Ex:%s" % (str(e))
        return Response.make_json_response(message, success=False, code=-1)
示例#6
0
def diskPathDu():
    try:
        hostUtil = HostUtil()
        message = hostUtil.get_path_du(request.args.get("path"))

    except Exception, e:
        message = "error get disk device stat, Ex:%s" % (str(e))
        return Response.make_json_response(message, success=False, code=-1)
示例#7
0
def diskUsage():
    try:
        hostUtil = HostUtil()
        message = hostUtil.disk_usage(request.args.get("mountpoint"))

    except Exception, e:
        message = "error get disk device stat, Ex:%s" % (str(e))
        return Response.make_json_response(message, success=False, code=-1)
示例#8
0
def loadavg():
    try:
        hostUtil = HostUtil()
        message = hostUtil.get_load_stat()

    except Exception, e:
        message = "error get cpu loadavg, Ex:%s" % (str(e))
        return Response.make_json_response(message, success=False, code=-1)
示例#9
0
def networkInfo(ifname):
    try:
        hostUtil = HostUtil()
        message = hostUtil.networkinfo(ifname)

    except Exception, e:
        message = "error get network %s info, Ex:%s" % (ifname, str(e))
        return Response.make_json_response(message, success=False, code=-1)
示例#10
0
def networkList():
    try:
        hostUtil = HostUtil()
        message = hostUtil.network_list()

    except Exception, e:
        message = "error get network list, Ex:%s" % str(e)
        return Response.make_json_response(message, success=False, code=-1)
示例#11
0
def getUname():
    try:
        hostUtil = HostUtil()
        message = hostUtil.uname()

    except Exception, e:
        message = "error get uname, Ex:%s" % str(e)
        return Response.make_json_response(message, success=False, code=-1)
示例#12
0
def diskPartitions():
    try:
        hostUtil = HostUtil()
        message = hostUtil.disk_partitions()

    except Exception, e:
        message = "error get disk partitions, Ex:%s" % (str(e))
        return Response.make_json_response(message, success=False, code=-1)
示例#13
0
    def run(self):
        try:
            utc_time = self.get_now_utc_time()
            disks = self.disk.split(",")
            for disk in disks:
                if not disk:
                    continue
                diskInfo = Host.disk_usage(disk)
                disk = disk.replace("/", "_")
                if disk.startswith('_'):
                    disk = disk[1:]
                    if len(disk) == 0:
                        disk = 'root'
                event = {
                    "time": utc_time,
                    "host": self.hostname,
                    "type": "df",
                    "instance": disk,
                    "type_instance": "usage_rate",
                    "value": diskInfo['usedRate']
                }
                self.octopusd.sendMessage(self.paramter['output'], event)

                event = {
                    "time": utc_time,
                    "host": self.hostname,
                    "type": "df",
                    "instance": disk,
                    "type_instance": "free_size",
                    "value": diskInfo['freeSize']
                }
                self.octopusd.sendMessage(self.paramter['output'], event)

        except Exception, ex:
            print ex
示例#14
0
    def __init__(self, octopusd, paramter):
        self.paramter = paramter
        self.octopusd = octopusd
        self.filters = paramter.get('filters')
        self.bss = paramter.get('bss')

        if paramter and paramter.get('hostname'):
            self.hostname = paramter.get('hostname')
        else:
            self.hostname = Host.getHostname()

        if paramter and paramter.get('containername'):
            self.containername = paramter.get('containername')
        else:
            self.containername = "{{name}}"

        if paramter and paramter.get('instance'):
            self.instance = paramter.get('instance')
        else:
            self.instance = None

        #if paramter and paramter.get('interval_time') :
        #    self.interval_time = paramter.get('interval_time')
        #else :
        #    self.interval_time = 0.5

        self.cacheStatsList = None
        self.cacheStatsTime = None
示例#15
0
    def __init__(self, octopusd, paramter):
        self.paramter = paramter
        self.octopusd = octopusd
        self.filters = paramter.get('filters')
        self.bss = paramter.get('bss')

        if paramter and paramter.get('hostname'):
            self.hostname = paramter.get('hostname')
        else:
            self.hostname = Host.getHostname()

        if paramter and paramter.get('containername'):
            self.containername = paramter.get('containername')
        else:
            self.containername = "{{name}}"

        if paramter and paramter.get('instance'):
            self.instance = paramter.get('instance')
        else:
            self.instance = None

        #if paramter and paramter.get('interval_time') :
        #    self.interval_time = paramter.get('interval_time')
        #else :
        #    self.interval_time = 0.5

        #{containerid:{cachetime:time, cachemap:{variabels:{},global_status:{}}}}
        self.status_cache = {}
示例#16
0
 def __init__(self, octopusd, paramter) :
     self.paramter = paramter
     self.octopusd = octopusd
     if paramter and paramter.get('hostname') :
         self.hostname = paramter.get('hostname')
     else :
         self.hostname = Host.getHostname()
示例#17
0
 def run(self):
     try:
         utc_time = self.get_now_utc_time()
         memInfo = Host.get_memory_stat()
         event = {"time": utc_time, "host": self.hostname, "type": "mem", "type_instance": "used", "value": memInfo['MemUsed']}
         self.octopusd.sendMessage(self.paramter['output'], event)
         
         #loadavg = Host.get_load_stat()
         event = {"time": utc_time, "host": self.hostname, "type": "mem", "type_instance": "usage_rate", "value": memInfo['MemUsedPerc']}
         self.octopusd.sendMessage(self.paramter['output'], event)
         
     except Exception,ex:
         print ex
    def run(self):
        try:
            utc_time = self.get_now_utc_time()
            interfaces = self.interface.split(",")
            for interface in interfaces:
                if not interface:
                    continue
                netRate = Host.get_net_rate(interface)

                event = {
                    "time": utc_time,
                    "host": self.hostname,
                    "type": "interface",
                    "instance": interface,
                    "type_instance": "bandwidth",
                    "value": netRate['rate']
                }
                self.octopusd.sendMessage(self.paramter['output'], event)

        except Exception, ex:
            print ex
示例#19
0
    def run(self):
        try:
            utc_time = self.get_now_utc_time()
            paths = self.path.split(",")
            for path in paths:
                if not path:
                    continue
                pathSize = Host.get_path_du(path)
                path = path.replace("/", "_")
                if path.startswith('_'):
                    path = path[1:]
                event = {
                    "time": utc_time,
                    "host": self.hostname,
                    "type": "du",
                    "instance": path,
                    "type_instance": "total",
                    "value": pathSize
                }
                self.octopusd.sendMessage(self.paramter['output'], event)

        except Exception, ex:
            print ex
示例#20
0
 def __init__(self):
     self.docker = 'docker'
     self.rootfs = Host.getRootfs()