Exemplo n.º 1
0
    def doCheck(self):
        flag = "Normal"
        resultStr = ""
        pathList = []
        if (not self.cluster):
            self.result.rst = ResultStatus.NG
            self.result.val = "The datanode information is none."
            return

        for inst in self.cluster.getDbNodeByName(self.host).datanodes:
            pathList.append(inst.datadir)
        cnInstList = self.cluster.getDbNodeByName(self.host).coordinators
        if (len(cnInstList) > 0):
            tblspcDir = os.path.join(cnInstList[0].datadir, 'pg_tblspc')
            tblspcList = os.listdir(tblspcDir)
            if (tblspcList):
                for tblspc in tblspcList:
                    tblspcPath = os.path.join(tblspcDir, tblspc)
                    if (os.path.islink(tblspcPath)):
                        pathList.append(os.path.realpath(tblspcPath))

        for path in pathList:
            rateNum = g_disk.getDiskSpaceUsage(path)
            self.result.raw += "[%s] space usage: %s%%\n" % (path, rateNum)
            if (rateNum > int(self.thresholdDn)):
                resultStr += \
                    "Path(%s) space usage(%d%%)     Abnormal reason: " \
                    "The usage of the device disk space " \
                    "cannot be greater than %s%%.\n" % (
                        path, rateNum, self.thresholdDn)
                flag = "Error"
            # Check inode usage
            diskName = g_disk.getMountPathByDataDir(path)
            diskType = g_disk.getDiskMountType(diskName)
            if (not diskType in ["xfs", "ext3", "ext4", "overlay"]):
                resultStr += \
                    "Path(%s) inodes usage(%s)     Warning reason: " \
                    "The file system type [%s] is unrecognized " \
                    "or not support. Please check it.\n" % (
                        path, 0, diskType)
                if (flag == "Normal"):
                    flag = "Warning"
                self.result.raw += "[%s] disk type: %s\n" % (path, diskType)
                continue
            rateNum = g_disk.getDiskInodeUsage(path)
            self.result.raw += "[%s] inode usage: %s%%\n" % (path, rateNum)
            if (rateNum > int(self.thresholdDn)):
                resultStr += \
                    "Path(%s) inode usage(%d%%)     Abnormal reason: " \
                    "The usage of the device disk inode " \
                    "cannot be greater than %s%%.\n" % (
                        path, rateNum, self.thresholdDn)
                flag = "Error"
        self.result.val = resultStr
        if (flag == "Normal"):
            self.result.rst = ResultStatus.OK
            self.result.val = "All disk space are sufficient.\n"
        else:
            self.result.rst = ResultStatus.NG
    def doCheck(self):
        flag = "Normal"
        resultStr = ""
        top = ""
        DiskList = []
        DiskInfoDict = {}
        if (self.cluster):
            pathList = self.obtainDataDir(
                self.cluster.getDbNodeByName(self.host))
        else:
            pathList = self.obtainDiskDir()

        for path in pathList:
            diskName = g_disk.getMountPathByDataDir(path)
            diskType = g_disk.getDiskMountType(diskName)
            if (not diskType in ["xfs", "ext3", "ext4"]):
                resultStr += \
                    "Path(%s) inodes usage(%s)     Warning reason: " \
                    "The file system type [%s] is unrecognized " \
                    "or not support. Please check it.\n" % (
                        path, 0, diskType)
                if (flag == "Normal"):
                    flag = "Warning"
                continue
            usageInfo = g_disk.getDiskInodeUsage(path)
            if (diskName in DiskList):
                continue
            else:
                DiskList.append(diskName)
            DiskInfoDict[usageInfo] = "%s %s%%" % (diskName, usageInfo)
            if (usageInfo > self.Threshold_NG):
                resultStr += "The usage of the device " \
                             "disk inodes[%s:%d%%] cannot be greater than" \
                             " %d%%.\n" % (
                                 diskName, usageInfo, self.Threshold_NG)
                flag = "Error"
            elif (usageInfo > self.Threshold_Warning):
                resultStr += \
                    "The usage of the device disk inodes[%s:%d%%] " \
                    "cannot be greater than %d%%.\n" % (
                        diskName, usageInfo, self.Threshold_Warning)
                if (flag == "Normal"):
                    flag = "Warning"
        self.result.val = resultStr
        if (flag == "Normal"):
            self.result.rst = ResultStatus.OK
            self.result.val = "All disk inodes are sufficient."
        elif (flag == "Warning"):
            self.result.rst = ResultStatus.WARNING
        else:
            self.result.rst = ResultStatus.NG

        keys = DiskInfoDict.keys()
        sortedKeys = sorted(keys)
        self.result.raw = "diskname inodeUsage"
        for diskInfo in map(DiskInfoDict.get, sortedKeys):
            self.result.raw += "\n%s" % diskInfo
 def doCheck(self):
     flag = "Normal"
     path = DefaultValue.getEnv(
         "PGHOST",
         os.path.join(DefaultValue.getEnv("GPHOME"),
                      "%s_mppdb" % self.user))
     # Check space usage
     rateNum = g_disk.getDiskSpaceUsage(path)
     self.result.raw += "[%s] space usage: %s%%\n" % (path, rateNum)
     if (rateNum > int(self.thresholdDn)):
         self.result.val += \
             "Path(%s) space usage(%d%%)     Abnormal reason: " \
             "The usage of the device disk space cannot be " \
             "greater than %s%%.\n" % (
                 path, rateNum, self.thresholdDn)
         flag = "Error"
     # Check inode usage
     diskName = g_disk.getMountPathByDataDir(path)
     diskType = g_disk.getDiskMountType(diskName)
     if (not diskType in ["xfs", "ext3", "ext4"]):
         self.result.val = \
             "Path(%s) inodes usage(%s)     Warning reason: " \
             "The file system type [%s] is unrecognized or not support. " \
             "Please check it.\n" % (
                 path, 0, diskType)
         self.result.raw = "[%s] disk type: %s\n" % (path, diskType)
         self.result.rst = ResultStatus.WARNING
         return
     rateNum = g_disk.getDiskInodeUsage(path)
     self.result.raw += "[%s] inode usage: %s%%\n" % (path, rateNum)
     if (rateNum > int(self.thresholdDn)):
         self.result.val += \
             "Path(%s) inode usage(%d%%)     Abnormal reason: " \
             "The usage of the device disk inode cannot be " \
             "greater than %s%%.\n" % (
                 path, rateNum, self.thresholdDn)
         flag = "Error"
     if (flag == "Normal"):
         self.result.rst = ResultStatus.OK
         self.result.val = "Tmp disk space are sufficient.\n"
     else:
         self.result.rst = ResultStatus.NG
Exemplo n.º 4
0
    def doCheck(self):
        flag = "Normal"
        resultStr = ""
        DiskList = []
        DiskInfoDict = {}
        pathDisk = {}
        if (self.cluster):
            pathDisk = self.obtainDataDir(
                self.cluster.getDbNodeByName(self.host))
            pathList = pathDisk.keys()
        else:
            pathList = self.obtainDiskDir()
        for path in pathList:
            diskName = g_disk.getMountPathByDataDir(path)
            usageInfo = g_disk.getDiskSpaceUsage(path)
            diskInfo = "%s %s%%" % (diskName, usageInfo)
            if (diskName in DiskList):
                continue
            else:
                DiskList.append(diskName)
            DiskInfoDict[usageInfo] = diskInfo
            rateNum = usageInfo
            if (rateNum > self.Threshold_NG):
                resultStr += \
                    "The usage of the device disk space[%s:%d%%] " \
                    "cannot be greater than %d%%.\n" % (
                        diskName, rateNum, self.Threshold_NG)
                flag = "Error"
            elif (rateNum > self.Threshold_Warning):
                resultStr += \
                    "The usage of the device disk space[%s:%d%%] " \
                    "cannot be greater than %d%%.\n" % (
                        diskName, rateNum, self.Threshold_Warning)
                if (flag == "Normal"):
                    flag = "Warning"

            if (pathDisk):
                if (diskInfo):
                    AvailableSpace = psutil.disk_usage(
                        path).free // 1024 // 1024 // 1024
                    minSpace_KB = float(pathDisk[path][1])
                    if (AvailableSpace < minSpace_KB):
                        resultStr += \
                            "The %s path [%s] where" \
                            " the disk available space[%.1fGB] is less than" \
                            " %.1fGB.\n" % (
                                pathDisk[path][0], path, AvailableSpace,
                                minSpace_KB)
                        flag = "Error"
                else:
                    raise Exception(ErrorCode.GAUSS_504["GAUSS_50413"] +
                                    "Error:\n%s" % diskInfo)
        self.result.val = resultStr
        if (flag == "Normal"):
            self.result.rst = ResultStatus.OK
            self.result.val = "All disk space are sufficient.\n"
        elif (flag == "Warning"):
            self.result.rst = ResultStatus.WARNING
        else:
            self.result.rst = ResultStatus.NG

        keys = DiskInfoDict.keys()
        sorted(keys)
        MaxDisk = list(map(DiskInfoDict.get, keys))[-1]
        MinDisk = list(map(DiskInfoDict.get, keys))[0]
        self.result.val += "\nDisk     Filesystem spaceUsage\nMax " \
                           "free %s\nMin free %s" % (MaxDisk, MinDisk)
        for diskInfo in list(map(DiskInfoDict.get, keys)):
            self.result.raw += "\n%s" % diskInfo