openGauss gs_check
Tags: opengauss
Published: 2023-02-21 07:14:43

Defining a Scenario
Log in as the OS user omm to the primary node of the database.

Create the scenario configuration file scene_XXX.xml in the $GPHOME/script/gspylib/inspection/config directory.

Write check items to the scenario configuration file in the following format:


`<?xml version="1.0" encoding="utf-8" ?>
<scene name="XXX" desc="check cluster parameters before XXX.">
<configuration/>
<allowitems>
<item name="CheckXXX"/>
<item name="CheckXXX"/>
</allowitems>
</scene>
item name indicates the check item name.

Note: You need to ensure that the user-defined XML file is correct.

Run the following command in the home/package/script/gspylib/inspection/config directory to deploy the file on each node where the check is to be performed:
`
scp scene_upgrade.xml SIA1000068994: home/package/script/gspylib/inspection/config/
 NOTE: home/package/script/gspylib/inspection/config is the absolute path of the new scenario configuration file.

Switch to user omm and run the following command to view the check result:


`gs_check  -e XXX
Defining a Check Item
Add a check item. Modify the script/gspylib/inspection/config/items.xml file in the following format:

<checkitem id="10010" name="CheckCPU">
<title>
<en>Check the CPU usage.</en>
<en>Check CPU Idle and I/O wait</en>
</title>
<threshold>
StandardCPUIdle=30;
StandardWIO=30
</threshold>
<suggestion>
<zh>If the available space is insufficient and the CPU is heavily loaded, scale out the CPU node. If iowait is too high, replace this disk with a high-performance one, which is the current performance bottleneck.</zh>.
</suggestion>
<standard>
<zh>Check the CPU usage of the host. If the value of idle is greater than 30% and the value of iowait is less than 30%, this item passes the check. Otherwise, this item fails the check.</zh>
</standard>
<category>os</category>
<permission>user</permission>
<scope>all</scope>
<analysis>default</analysis>
</checkitems>
id: specifies the check item ID.`

name: specifies the name of the check script.

title: specifies the name of the check item. It allows multiple languages.

<zh>: checks content of Chinese version.

<en>: checks content of English version.

standard: specifies the check standards. It allows multiple languages.

suggestion: provides advice on how to fix check item problems. It allows multiple languages.

threshold: specifies the check item threshold. Multiple values are separated using semicolons (;), for example, Key1=Value1;Key2=Value2.

category: specifies the check item type. It is optional. Its value can be os, device, network, cluster, database, or other.

permission: specifies the permission required for checking an item. It is optional. Its value can be root or user (default).

scope: specifies the node scope where an item is checked. It is optional. cn- indicates that only the primary database node resides is checked. local- indicates that only the current node is checked. all- is the default value, indicating that all nodes in openGauss are checked.

analysis: specifies how the check result is analyzed. default- is the default value, indicating that the result on every node is checked, and that an item passes the check only if it passes the check on all the nodes. consistent- indicates that each node returns a result, and that an item passes the check if all the results are consistent. custom- indicates other ways.

Note: You need to ensure that the user-defined XML file is correct.

Create a check script named CheckXXXX.py in the script/gspylib/inspection/items directory. The directory should contain multiple folders, each storing a type of scripts. The format is as follows:


`class CheckCPU(BaseItem):
def __init__(self):
super(CheckCPU, self).__init__(self.__class__.__name__)
self.idle = None
self.wio = None
self.standard = None

def preCheck(self):
# check the threshold was set correctly
if (not self.threshold.has_key('StandardCPUIdle')
or not self.threshold.has_key('StandardWIO')):
raise Exception("threshold can not be empty")
self.idle = self.threshold['StandardCPUIdle']
self.wio = self.threshold['StandardWIO']

# format the standard by threshold
self.standard = self.standard.format(idle=self.idle, iowait=self.wio)

def doCheck(self):
cmd = "sar 1 5 2>&1"
output = SharedFuncs.runShellCmd(cmd)
self.result.raw = output
# check the result with threshold
d = next(n.split() for n in output.splitlines() if "Average" in n)
iowait = d[-3]
idle = d[-1]
rst = ResultStatus.OK
vals = []
if (iowait > self.wio):
rst = ResultStatus.NG
vals.append("The %s actual value %s is greater than expected value %s" % ("IOWait", iowait, self.wio))
if (idle < self.idle):
rst = ResultStatus.NG
vals.append("The %s actual value %s is less than expected value %s" % ("Idle", idle, self.idle))
self.result.rst = rst
if (vals):
self.result.val = "\n".join(vals)`
A script is developed based on the BaseItem class, which defines the common check process, result analysis method, and default output format. Extended parameters:

doCheck: contains specific ways to check an item. The check result is in the following format:

result.rst: (optional) specifies the check result. Its value can be:

OK: indicates that the item passes the check.
NA: indicates that the check does not cover the node.
NG: indicates that the item failed the check.
WARNING: indicates that the check is complete and that a warning is reported.
ERROR: indicates that the check is interrupted due to an internal error.
preCheck: checks prerequisites. Its value can be cnPreCheck, which checks whether a primary database node instance is deployed on the current execution node; or localPreCheck, which checks whether the current execution node is specified for the check. You can set it using scope in the check item configuration file. This method can be reloaded to perform customized pre-checks.

postAnalysis specifies how the check result is analyzed. Its value can be default or consistent. You can set it using analysis in the check item configuration file. This method can be reloaded to perform customized result analysis.

Note: The name of a user-defined check item cannot be the same as the name of an existing check item. In addition, you need to ensure that the user-defined check item script is standard.

Deploy the script on all execution nodes.

Log in as the user omm and run the following command to view the result:

To locally perform a check, run the following command:

`gs_check -i CheckXXX  -L`
To remotely perform a check, run the following command:

`gs_check  -i  CheckXXX`