コード例 #1
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
コード例 #2
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)