diff --git "a/docs/zh/docs/sysSentry/AI\351\230\210\345\200\274\346\205\242\347\233\230\346\243\200\346\265\213\346\217\222\344\273\266.md" "b/docs/zh/docs/sysSentry/AI\351\230\210\345\200\274\346\205\242\347\233\230\346\243\200\346\265\213\346\217\222\344\273\266.md" new file mode 100644 index 0000000000000000000000000000000000000000..a12ee578ecc6fd4ae94ef7b13325c457a565f5b8 --- /dev/null +++ "b/docs/zh/docs/sysSentry/AI\351\230\210\345\200\274\346\205\242\347\233\230\346\243\200\346\265\213\346\217\222\344\273\266.md" @@ -0,0 +1,169 @@ +# AI阈值慢盘检测插件 + +用户可通过AI阈值慢盘检测插件进行慢盘故障检测。 + +### 一、规格要求 + +- 仅支持openEuler-20.03-LTS-SP4版本,并使用4.19.90内核 +- 仅支持对nvme-ssd、sata-ssd、sata-hdd盘进行慢盘检测 + +### 二、安装插件 + +#### 1. 前置条件 + +已安装sysSentry巡检插件,sentryCollector采集服务已配置io相关采集项(请参考《安装和使用》进行配置) + +#### 2. 安装软件包 + +``` +yum install -y ai_block_io pysentry_notify pysentry_collect python3-numpy sysSentry +``` + +#### 3. (可选)重编内核并重启机器 + +注:该操作为可选步骤,重编内核可以支撑插件进行更详细的慢盘检测 + +##### step1. 下载kernel-source包并解压 + +``` +yumdownloader kernel-source-4.19.90-2409.3.0.0294.oe2003sp4 +# 请跟据机器架构替换[$ARCH]为x86_64或aarch64 +rpm2cpio kernel-source-4.19.90-2409.3.0.0294.oe2003sp4.[$ARCH].rpm |cpio -div +cd usr/src/linux-4.19.90-2409.3.0.0294.oe2003sp4.[$ARCH]/ +``` + +##### step2. 配置&构建 + +``` +yum install -y openssl-devel bc rsync gcc gcc-c++ flex bison m4 ncurses-devel elfutils-libelf-devel + +# 搜索BLK_IO_HIERARCHY_STATS,对应的config全部打开后保存退出 +make menuconfig + +修改Makefile中的EXTRAVERSION = .blk_io (这里修改会体现在最终构建出来的内核版本号上) + +# 编译 +make -j 200 && make modules_install && make install +``` + +##### step3. 使用新内核重启 + +``` +grubby --info ALL # 查看新编的内核对应的index +grubby --set-default-index N # N对应新编内核的index +reboot +``` + +##### step4. 重新启动sysSentry相关服务 + +``` +systemctl restart xalarmd +systemctl restart sysSentry +systemctl restart sentryCollector +``` + +#### 4. 将ai_block_io加入框架管理 + +``` +sentryctl reload ai_block_io +``` + +### 三、配置文件说明 + +ai_block_io插件配置文件路径:/etc/sysSentry/plugins/ai_block_io.ini,配置文件修改会在下一次启动巡检任务时生效。 + +| 配置段 | 配置项 | 配置项说明 | 默认值 | 必选项 | +| ------------------- | --------------------- | ------------------------------------------------------------ | -------------- | ------ | +| [log] | level | 记录日志的等级,可配置范围是debug/info/warning/error/critical,未配置或值异常时使用默认参数 | info | Y | +| [common] | disk | 磁盘名称,由逗号分隔,default表示当前环境上所有盘,配置异常时仅保留正确字段 | default | Y | +| | stage | 监控阶段,由逗号分隔,目前已支持throtl/wbt/gettag/plug/deadline/hctx/requeue/rq_driver/bio九个阶段,根据盘种类不同提供的stage可能有不同,配置default表示盘支持的所有阶段,未配置时使用默认配置,配置异常时报错退出;注:用户自行配置时,必须包含bio阶段 | default | Y | +| | iotype | io类别,由逗号分隔,共支持两种场景:read、write,未配置时使用默认配置,配置异常时报错退出 | read,write | Y | +| | period_time | 数据采集周期,整形类型,单位为秒,范围为1~max(采集周期),未配置时使用默认配置,配置异常时报错退出;注:采集周期=period_time * max_save(请参考sentryCollector配置文件) | 1 | Y | +| [algorithm] | train_data_duration | AI阈值算法训练数据采集时长,单位h, 浮点类型,该字段值越大,算法统计结果越稳定。范围为0~720,未配置时使用默认配置,配置异常时报错退出 | 24 | Y | +| | train_update_duration | AI阈值算法阈值更新时长,浮点类型,单位h, 该字段值越小,阈值更新越快,误报越高。范围为0~train_data_duration,未配置时使用默认配置,配置异常时报错退出 | 2 | Y | +| | algorithm_type | AI阈值算法类型,字符串类型,该字段取值可选项为:absolute/boxplot/n_sigma,未配置时使用默认配置,配置异常时报错退出 | boxplot | Y | +| | boxplot_parameter | boxplot算法的参数,浮点类型,该字段值越大,对异常的敏感程度就越低。范围为0~10,未配置时使用默认配置,配置异常时报错退出 | 1.5 | N | +| | n_sigma_parameter | n_sigma算法的参数,浮点类型,该字段值越大,对异常的敏感程度就越低。范围为0~10,未配置时使用默认配置,配置异常时报错退出 | 3.0 | N | +| | win_type | AI阈值算法检测窗口类型,适用于不同的检测目的,字符串类型,该字段取值可选项为:not_continuous/continuous/median。未配置时使用默认配置,配置异常时报错退出 | not_continuous | Y | +| | win_size | AI阈值算法检测窗口长度,慢IO检测时只判断窗口内的数据是否为异常,整数类型,范围为0~3600。未配置时使用默认配置,配置异常时报错退出 | 30 | Y | +| | win_threshold | AI阈值算法超阈值数量,整形类型,该字段值越小,算法上报异常速度越快,误报越高。范围为1~win_size,未配置时使用默认配置,配置异常时报错退出 | 6 | Y | +| [latency_DISK_TYPE] | read_avg_lim | 读时延平均值上限,单位us,代表窗口中读IO平均时延限制,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | - | Y | +| | write_avg_lim | 写时延平均值上限,单位us,代表窗口中写IO平均时延限制,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | - | Y | +| | read_tot_lim | 读时延绝对上限,单位us,读时延超过此数据即为异常数据,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | - | Y | +| | write_tot_lim | 写时延绝对上限,单位us,写时延超过此数据即为异常数据,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | - | Y | +| [iodump] | read_iodump_lim | 读iodump绝对上限,整形类型,读iodump数量超过此数据即为异常数据,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | 0 | Y | +| | write_iodump_lim | 写iodump绝对上限,整形类型,写iodump数量超过此数据即为异常数据,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | 0 | Y | + +**注:** + +1. latency_[DISK_TYPE]、iodump配置段的所有参数调整均会影响算法的准确性,且优劣并存:若数值越大,算法漏报率越高,则数值越小,算法误报率越高。需要根据经验进行取舍。 +2. [DISK_TYPE]为磁盘类型,目前仅支持三类:sata_ssd、nvme_ssd、sata_hdd +3. period_time配置需满足以下几条: + 1. 如果巡检插件周期不满足采集模块周期的整数倍,请求不合法 + 2. 如果巡检插件周期超过采集模块存储数据能力,请求不合法 + 3. 如果巡检插件磁盘名与采集模块磁盘名不一致,请求不合法 +4. win_type选择检测类型时,各选项分别代表以下含义: + 1. not_continuous:检测窗口内异常点不要求连续 + 2. continuous:检测窗口内异常点要求连续 + 3. median:检测窗口内所有数据点的中位数是否超过阈值 + +### 四、使用AI阈值慢盘检测插件 + +1. 启动巡检 + + ``` + sentryctl start ai_block_io + ``` + +2. 查看巡检插件状态 + + ``` + sentryctl status ai_block_io + ``` + + 状态为RUNNING即为运行中,状态为EXITED为退出 + +3. 查看告警信息 + + ``` + sentryctl get_alarm ai_block_io -s 1 -d + ``` + + 示例: + + ``` + [ + { + "alarm_id": 1002, + "alarm_type": 1, + "alarm_level": 1, + "timestamp": "2024-10-23 11:56:51", + "alarm_info": { + "alarm_source": "ai_block_io", + "driver_name": "sda", + "io_type": "write", + "reason": "IO press", + "block_stack": "bio,wbt", + "alarm_type": "latency", + "details": { + "latency": "gettag: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], rq_driver: [0,0,0,0,0,437.9,0,0,0,0,517,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], bio: [0,0,0,0,0,521.1,0,0,0,0,557.8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], wbt: [0,0,0,0,0,0,8.5,0,0,0,0,12.0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]", + "iodump": "gettag: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], rq_driver: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], bio: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], wbt: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]" + } + } + } + ] + ``` + +4. 停止巡检 + + ``` + sentryctl stop ai_block_io + ``` + +5. 查看巡检结果信息 + + ``` + sentryctl get_result ai_block_io + ``` + + 注:仅在巡检停止后可查看有效信息 \ No newline at end of file diff --git "a/docs/zh/docs/sysSentry/sysSentry\347\224\250\346\210\267\346\214\207\345\215\227.md" "b/docs/zh/docs/sysSentry/sysSentry\347\224\250\346\210\267\346\214\207\345\215\227.md" new file mode 100644 index 0000000000000000000000000000000000000000..981a5372a7baf4bd55cd920bb09ee4703f9ac417 --- /dev/null +++ "b/docs/zh/docs/sysSentry/sysSentry\347\224\250\346\210\267\346\214\207\345\215\227.md" @@ -0,0 +1,10 @@ +sysSentry主要提供故障巡检框架,该框架通过提供统一的北向故障上报接口以及南向提供支持不同巡检/诊断能力的插件,支持对系统中CPU、内存、磁盘、NPU等硬件故障进行巡检和诊断。 + + + +sysSentry功能设计如下: + +1. 统一告警/事件通知服务:通过提供一个统一的告警服务,接收各个插件上报的故障信息,并由该通知服务进行统一转发,各个业务订阅服务可以根据需要进行不同故障的消息订阅。 +2. 统一日志服务:通过提供统一的日志服务,支持各个插件的故障信息进行汇总记录,提升问题定位效率。 +3. 故障诊断/巡检框架:该框架支持以插件化的方式进行各项巡检任务以及诊断任务的开发和配置,不同插件支持独立启动、停止、状态查询、结果查询以及启动方式设置,并且支持C/C++、Python、Shell等不同编程语言的插件。 +4. 轻量级数据采集服务:该服务支持通过内核接口、BIOS、BMC等接口,查询硬件的各个状态信息,供各个插件进行分析和使用,并且支持适配底层不同的架构、版本以及数据采集服务。 \ No newline at end of file diff --git "a/docs/zh/docs/sysSentry/\344\272\214\346\254\241\345\274\200\345\217\221\346\214\207\345\215\227.md" "b/docs/zh/docs/sysSentry/\344\272\214\346\254\241\345\274\200\345\217\221\346\214\207\345\215\227.md" new file mode 100644 index 0000000000000000000000000000000000000000..24ee77dc956a2f7aa5a7ab41b743aa5878176e0d --- /dev/null +++ "b/docs/zh/docs/sysSentry/\344\272\214\346\254\241\345\274\200\345\217\221\346\214\207\345\215\227.md" @@ -0,0 +1,793 @@ +# 二次开发指南 + +sysSentry作为一款故障巡检管理框架,其中管理的巡检任务是以插件的形式独立存在的,支持用户修改插件配置、增加新的插件。 + +**注:** 请先通过《安装和使用》文档了解sysSentry基本使用方法并完成部署。 + +## 一、通过sentryCollector服务采集系统数据 + +sysSentry软件中包含用来做数据采集的服务:sentryCollector,用户可通过sentryCollector服务定期采集系统数据,当前sentryCollector支持采集的数据类别如下: + +| 系统数据维度 | 是否支持 | +| ------------ | -------- | +| io | 已支持 | +| network | 开发中 | +| ... | | + +sysSentry软件提供了python语言的对外接口,并打包成rpm,如用户需要通过sentryCollector服务获取系统数据,需要安装pysentry_collect.rpm软件包 + +```shell +[root@openEuler ~]# yum install -y pysentry_collect +``` + +该包中包含提供给用户使用的python对外接口,调用方法如下: + +```python +[root@openEuler ~]# cat test.py +#/usr/bin/python3 + +from sentryCollector.collect_plugin import * +``` + +### 1. io数据采集 + +sentryCollector支持按周期采集指定磁盘的数据,并提供两种采集方式: + +- 内核无锁采集 +- ebpf采集 + +#### 1)内核无锁采集和ebpf采集的区别 + +两种采集方法可采集的数据范围有区别: + +A. 支持的内核 + +| 内核版本 | 内核无锁采集 | ebpf采集 | +| -------- | ------------ | -------- | +| 4.19 | 已支持 | 已支持 | +| 5.10 | 暂不支持 | 暂不支持 | + +B. 支持采集的磁盘类型 + +| 磁盘类型 | 内核无锁采集 | ebpf采集 | +| -------- | ------------ | -------- | +| nvme ssd | 已支持 | 已支持 | +| sata ssd | 已支持 | 已支持 | +| sata hdd | 已支持 | 已支持 | + +B. 支持采集的阶段 + +将一个io从发生到结束分成多个不同的阶段,以下是两种采集方式支持的阶段类型: + +| 阶段名称 | 内核无锁采集 | ebpf采集 | +| --------- | ------------ | -------- | +| bio | 已支持 | 已支持 | +| rq_driver | 已支持 | 已支持 | +| throtl | 已支持 | 暂不支持 | +| wbt | 已支持 | 已支持 | +| gettag | 已支持 | 已支持 | +| plug | 已支持 | 暂不支持 | +| deadline | 已支持 | 暂不支持 | +| bpf | 已支持 | 暂不支持 | +| requeue | 已支持 | 暂不支持 | +| hctx | 已支持 | 暂不支持 | + +C. 支持采集的IO类型 + +| IO类型 | 内核无锁采集 | ebpf采集 | +| ------- | ------------ | -------- | +| read | 已支持 | 已支持 | +| write | 已支持 | 已支持 | +| flush | 已支持 | 暂不支持 | +| discard | 已支持 | 暂不支持 | + +D. 支持采集的数据类型 + +注:以下数据粒度为 指定磁盘 & 指定阶段 & 指定IO类型 的 latency/iodump/iolength/iops数据 + +| 数据类型 | 内核无锁采集 | ebpf采集 | 数据含义 | +| -------- | ------------ | -------- | ------------------------ | +| latency | 已支持 | 已支持 | 周期内的时延 | +| iodump | 已支持 | 已支持 | 周期内超时未完成的io数量 | +| iolength | 已支持 | 已支持 | io队列长度 | +| iops | 已支持 | 已支持 | 每秒的io数量 | + +#### 2)内核无锁采集和ebpf采集的使用方法 + +内核无锁采集和ebpf采集无法同时使用,且内核无锁采集优先级高于ebpf采集,openEuler-20.03-LTS-SP4版本操作系统上运行sentryCollector服务时默认使用ebpf采集,如需要启动内核无锁采集,需通过以下方法重编内核: + +step1. 下载kernel-source包并解压 + +``` +[root@openEuler ~]# yumdownloader kernel-source-4.19.90-2409.3.0.0294.oe2003sp4 +# 请跟据机器架构替换[$ARCH]为x86_64或aarch64 +[root@openEuler ~]# rpm2cpio kernel-source-4.19.90-2409.3.0.0294.oe2003sp4.[$ARCH].rpm |cpio -div +[root@openEuler ~]# cd usr/src/linux-4.19.90-2409.3.0.0294.oe2003sp4.[$ARCH]/ +``` + +step2. 配置&构建 + +``` +[root@openEuler ~]# yum install -y openssl-devel bc rsync gcc gcc-c++ flex bison m4 ncurses-devel elfutils-libelf-devel + +# 搜索BLK_IO_HIERARCHY_STATS,对应的config全部打开后保存退出 +[root@openEuler ~]# make menuconfig + +修改Makefile中的EXTRAVERSION = .blk_io (这里修改会体现在最终构建出来的内核版本号上) + +# 编译 +[root@openEuler ~]# make -j 200 && make modules_install && make install +``` + +step3. 使用新内核重启 + +``` +[root@openEuler ~]# grubby --info ALL # 查看新编的内核对应的index +[root@openEuler ~]# grubby --set-default-index N # N对应新编内核的index +[root@openEuler ~]# reboot +``` + +step4. 重新启动sysSentry相关服务 + +``` +[root@openEuler ~]# systemctl restart xalarmd +[root@openEuler ~]# systemctl restart sysSentry +[root@openEuler ~]# systemctl restart sentryCollector +``` + +可以查看环境上是否存在以下目录,请自行替换[disk]为有效磁盘名 + +```shell +[root@openEuler ~]# ll /sys/kernel/debug/block/[disk]/blk_io_hierarchy/ +``` + +如目录存在,则此时sentryCollector服务运行的为内核无锁采集 + +#### 3)对外接口 + +当前仅提供python语言的接口,需要用户安装pysentry_collect软件包 + +**接口一、** 查看磁盘类型 + +| 接口 | get_disk_type(disk) | +| ------ | ------------------------------------------------------------ | +| 描述 | 从采集模块中查询磁盘类型 | +| 参数 | disk – 磁盘名,例:sda,必选参数 | +| 约束 | 磁盘名不超过32个字符 | +| 返回值 | 返回值格式为:{"ret": value1, "message":value2}
value1取值为0或者其他正整数,0表示成功,其他非零表示失败;
message是个字符串,表示表示磁盘类型,字符串类型,如果ret为非零,则message为空字符串,当前支持的message对应磁盘类型如下:
"message": "0" -- nvme_ssd
"message": "1" -- sata_ssd
"message": "2" -- sata_hdd
返回值示例:
\- 磁盘类型不支持:{"ret": 8, "message": ""} # ret结果非0
- 函数执行成功:{"ret": 0, "message": "1"} # 磁盘为sata ssd类型 | + +示例: + +```shell +[root@openEuler ~]# python3 +Python 3.7.9 (default, Dec 11 2023, 19:40:40) +[GCC 7.3.0] on linux +Type "help", "copyright", "credits" or "license" for more information. +>>> from sentryCollector.collect_plugin import get_disk_type, Disk_Type +>>> res = get_disk_type("sda") +>>> res +{'ret': 0, 'message': '1'} +>>> curr_disk_type = int(res['message']) +>>> curr_disk_type +1 +>>> Disk_Type[curr_disk_type] +'sata_ssd' +``` + +**接口二、** 查询采集是否合法 + +| 接口 | is_iocollect_valid(period, disk_list=None, stage=None) | +| ------ | ------------------------------------------------------------ | +| 描述 | 确认是否在采集范围内,确认周期是否合法 | +| 参数 | period – 用户采集周期,整形,单位秒,必选参数。
disk_list – 磁盘列表,默认为None,代表关注所有磁盘,可选参数。可传入自定义列表,例:[“sda”, “sdb”, “sdv”]。
stage – 采集阶段,默认为None,代表关注所有采集阶段,可选参数。可传入自定义阶段列表,例:["wbt", "bio"]。 | +| 约束 | 1. 采集周期取值在1到300之间
2. 磁盘列表磁盘个数不超过10个,如果超过10个,默认取前10个,磁盘列表种的磁盘名不超过32个字符
3. 采集阶段个数不超过15个,阶段名字符不超过20个字符 | +| 返回值 | 返回值格式为:{"ret": value1, "message":value2}
value1取值为0或者其他正整数,0表示成功,其他非零表示失败,
message是个字符串,表示有效的磁盘和该磁盘对应的stage,字符串类型,如果字符串为空说明全都不支持,格式如下:
{“disk_name1”: [“stage1”, "stage2"], “disk_name2”: [“stage1”, "stage2"], ...}
返回值示例:
- 验证失败:{"ret": 1, "message": {}} # ret结果非0
- 验证成功,所有盘均不支持采集:{"ret": 0, "message": {}}
- 部分盘不支持(message中返回支持的盘和对应的阶段):{"ret": 0, "message": {“sda”: [“bio”, “gettag”], “sdb”: [“bio”, “gettag”]}} | + +示例: + +```shell +[root@openEuler ~]# python3 +Python 3.7.9 (default, Dec 11 2023, 19:40:40) +[GCC 7.3.0] on linux +Type "help", "copyright", "credits" or "license" for more information. +>>> from sentryCollector.collect_plugin import is_iocollect_valid +>>> is_iocollect_valid(1, ["sda"]) +{'ret': 0, 'message': '{"sda": ["throtl", "wbt", "gettag", "plug", "deadline", "hctx", "requeue", "rq_driver", "bio"]}'} +``` + +**接口三、** 查询指定数据 + +| 接口 | get_io_data(period, disk_list, stage, iotype) | +| ------ | ------------------------------------------------------------ | +| 功能 | 确认是否在采集范围内,确认周期是否合法 | +| 参数 | 1. period – 用户采集周期,整形,单位秒,必选参数
2. disk_list -- 磁盘列表,必选参数,例:[“sda”, “sdb”, “sdv”]。
3. stage – 读取的阶段,必选参数,例:[“bio”, “gettag”, “wbt”]。
4. iotype – IO类型,列表中对应要获取的IO数据类型,仅支持read/write/flush/discard,必选参数,例:[“read”, “write”] | +| 约束 | 1. 采集周期取值在1到300之间,并且为period_time值的整数倍,且倍数不超过max_save(两个数值请参考/etc/sysSentry/sentryCollector.conf)
2. 磁盘列表磁盘个数不超过10个,如果超过10个,默认取前10个,磁盘列表种的磁盘名不超过32个字符l 采集阶段个数不超过15个,阶段名字符不超过20个字符
3. IO类型个数不超过4个,字符长度不超过7个(最长的长度是discard) | +| 返回值 | 返回值格式为:{"ret": value1, "message":value2}
value1取值为0或者其他正整数,0表示成功,其他非零表示失败,
message是个字符串,表示采集模块处理过的当前周期数据,字符串类型,格式如下:
”{“disk_name1”: {“stage1”: {“read”: [latency, iodump, iolength, iops],“write”: [write_latency, write_iodump, iolength, iops]},“stage2”: {…}},…}”
返回值示例:
- 获取数据失败:{"ret": 1, "message": {}} # ret结果非0
- 获取数据成功:{"ret": 0, "message": "{“sda”: {“bio”: {“read”: [0.1, 0, 100, 19], “write”: [0.5, 3, 100, 12]}, “wbt”: {}}, “sdb”…}"}
其中[0.5, 3, 100, 12]对应[时延ns,iodumps数量,io队列长度,iops] | + +示例: + +```shell +[root@openEuler ~]# python3 +Python 3.7.9 (default, Dec 11 2023, 19:40:40) +[GCC 7.3.0] on linux +Type "help", "copyright", "credits" or "license" for more information. +>>> from sentryCollector.collect_plugin import get_io_data +>>> get_io_data(1, ["sda"], ["bio"], ["read"]) +{'ret': 0, 'message': '{"sda": {"bio": {"read": [0, 0, 0, 0]}}}'} +``` + +## 二、对新增插件进行管理 + +### 1. 插件管理配置文件.mod + +**前置要求:** 已完成sysSentry安装与部署,并完成新插件的功能开发 + +#### step1. 编写配置文件 + +用户编写的新插件可以通过sysSentry进行管理,为了达到此目的,需要用户为新插件增加对应的配置文件,该文件应放置在`/etc/sysSentry/tasks/`目录下,文件名为`[插件名].mod`,假设插件名为test,配置文件参考: + +```shell +[root@openEuler ~]# cat /etc/sysSentry/tasks/test.mod +[common] +enabled=yes # 是否加载插件 +task_start=/usr/bin/test # 插件启动命令 +task_stop=pkill -f /usr/bin/test # 插件停止命令 +type=oneshot # 插件任务类型 +``` + +详细配置方法请参考`《安装和使用》- 部署sysSentry - 配置介绍 - 4.巡检插件管理配置` + +#### step2. 配置文件加载 + +完成配置文件编写,并放置在指定目录下后,需要将配置文件加载到sysSentry框架中 + +```shell +[root@openEuler ~]# sentryctl reload <插件名> +``` + +其中插件名与.mod文件名称一致,重载插件后,可以通过sysSentry框架管理插件运行状态: + +```shell +# 查看现有插件列表,列表中应包含新插件名 +[root@openEuler ~]# sentryctl list + +# 启动新插件 +[root@openEuler ~]# sentryctl start <插件名> + +# 查看插件状态 +[root@openEuler ~]# sentryctl status <插件名> + +# 停止新插件 +[root@openEuler ~]# sentryctl stop <插件名> +``` + +**Note:**通过get_alarm获取插件告警结果需要继续完成`2.插件告警上报` 和`3.通过get_alarm获取告警信息`,通过get_result获取插件运行结果需要完成`5.插件结果上报`。 + +### 2. 插件告警上报 + +**前置要求:** 已完成`1.插件管理配置文件.mod` + +用户可通过告警上报接口将插件的告警信息上报到xalarmd服务,并通过get_alarm接口查看告警内容 + +```she +[root@openEuler ~]# sentryctl get_alarm <插件名> +``` + +提供python与c两种语言的对外接口: + +#### 1)python代码告警上报 + +需要安装pysentry_notify软件包 + +``` +[root@openEuler ~]# yum install -y pysentry_notify +``` + +接口:告警信息上报 + +| 接口 | xalarm_report(alarm_id, alarm_level, alarm_type, puc_paras) | +| ------ | ------------------------------------------------------------ | +| 描述 | 巡检插件可以通过该接口上报告警信息到xalarmd服务 | +| 参数 | 1. alarm_id:告警id,整数类型
2. alarm_level:告警级别,枚举类型,取值为:MINOR_ALM、MAJOR_ALM、CRITICAL_ALM
3. alarm_type:告警类别,枚举类型,取值为:ALARM_TYPE_OCCUR和ALARM_TYPE_RECOVER
4. punc_params:告警描述信息,字符串类型 | +| 约束 | 1. 告警id限制取值范围为1001-1128。目前1001(内存巡检)、1002(慢IO检测)已被占用,不建议使用
2. 告警描述信息最大长度为8191。 | +| 返回值 | 若上报告警成功,则返回值为Ture,否则返回值为False。 | + +示例: + +```shell +[root@openEuler ~]# python3 +Python 3.7.9 (default, Dec 11 2023, 19:40:40) +[GCC 7.3.0] on linux +Type "help", "copyright", "credits" or "license" for more information. +>>> from xalarm.sentry_notify import xalarm_report, MAJOR_ALM, ALARM_TYPE_OCCUR +>>> xalarm_report(1003, MAJOR_ALM, ALARM_TYPE_OCCUR, "this is a major alarm") +True +``` + +#### 2)c代码告警上报 + +需要安装libxalarm软件包 + +``` +[root@openEuler ~]# yum install -y libxalarm +``` +开发环境还需要安装libxalarm-devel包(构建依赖,非运行依赖) +``` +[root@openEuler ~]# yum install -y libxalam-devel +``` + +接口:告警信息上报 + +| 接口 | int xalarm_Report(unsigned short usAlarmId, unsigned char ucAlarmLevel, unsigned char ucAlarmType, char *pucParas); | +| ------ | ------------------------------------------------------------ | +| 描述 | sysSentry告警上报接口,用于向xalarmd上报需要转发的告警。 | +| 参数 | 1. usAlarmId:告警id
2. usAlarmLevel:告警级别,取值为:MINOR_ALM、MAJOR_ALM、CRITICAL_ALM
3. ucAlarmType:告警类别,取值范围为ALARM_TYPE_OCCUR和ALARM_TYPE_RECOVER
4. pucParas:告警描述信息,长度上限为8191个字符。 | +| 约束 | 1. 告警id限制取值范围为1001-1128。目前1001(内存巡检)、1002(慢IO检测)已被占用,不建议使用
2. 告警描述信息最大长度为8191。 | +| 返回值 | 返回0表示成功,失败返回-1。 | + +示例: + +```shell +[root@openEuler ~]# cat send_alarm.c +#include +#include +#include +#include + +#define ALARMID 1002 + +int main(int argc, char **argv) +{ + int alarmId = ALARMID; + int level = MAJOR_ALM; + int type = ALARM_TYPE_OCCUR; + unsigned char *msg = "test messages\0"; + + int ret = xalarm_Report(alarmId, level, type, msg); + + if (ret == -1) { + printf("send failed.\n"); + } + + return 0; +} +[root@openEuler ~]# gcc send_alarm.c -o send_alarm -lxalarm +``` + +### 3. 通过get_alarm获取告警信息 + +**前置要求:** 已完成`1.插件管理配置文件.mod`和`2.插件告警上报` + +用户需要根据`2.插件告警上报` 中的alarm_id更新插件的mod文件 + +``` +# 假设插件名称为test +# alarm_id = 1100 +[root@openEuler ~]# cat /etc/sysSentry/tasks/test.mod +[common] +enabled=yes +task_start=/usr/bin/test +task_stop=pkill -f /usr/bin/test +type=oneshot +alarm_id=1100 # 新增alarm_id信息 +alarm_clear_time=5 # 新增告警清理时间,单位秒,最大值为15 +``` + +更新后重新sysSentry服务 + +``` +[root@openEuler ~]# systemctl restart sysSentry +``` + +### 4. 告警订阅 + +**前置要求:** 已完成`1.插件管理配置文件.mod`和`2.插件告警上报` + +用户可通过创建新的进程订阅并接收告警上报内容,提供python与c两种语言的对外接口 + +#### 1)python代码注册并获取告警内容 + +需要安装pyxalarm软件包 + +``` +[root@openEuler ~]# yum install -y pyxalarm +``` + +结构体一、告警消息结构体定义 + +``` +class Xalarm: + def __init__(self, alarm_id, alarm_type, alarm_level, + tv_sec, tv_usec, msg1): + self._alarm_id = alarm_id # 告警id + self._alarm_type = alarm_type # 告警类型 + self._alarm_level = alarm_level # 告警级别 + self.timetamp = TimevalStu(tv_sec, tv_usec) # 时间戳 + self._msg1 = msg1 # 字符串类型,告警消息 +``` + +接口一、告警订阅 + +| 接口 | xalarm_register(callback:callable, id_filter: list[bool]) -> int | +| -------- | ------------------------------------------------------------ | +| 功能描述 | 用于接收告警的用户注册告警接收,最大支持100个用户创建连接 | +| 参数说明 | 1. callback:callable类型,回调函数,要求回调函数必须满足def callback_func(alarm_info: Xalarm) -> None的定义
2. id_filter: list[bool]类型,告警类型id列表,若设置id_filter[i]为True,则表明用户设置接收alarm id为1001+i的告警,id_filter长度为128;若设置id_filter[i]为False,表明用户不接收alarm id为1001+i的告警 | +| 返回值 | 返回值为整型数字,该值为保留参数,仅做结果判断,用于取消告警、更新告警时回传 | + +接口二、取消告警订阅 + +| 接口 | xalarm_unregister(client_id: int)->None | +| -------- | ----------------------------------------------------- | +| 功能描述 | 用于接收告警的用户取消告警订阅 | +| 参数说明 | client_id: int类型,调用xalarm_register接口后的返回值 | +| 返回值 | 无 | + +接口三、更新告警订阅 + +| 接口 | xalarm_upgrade(id_filter:list[bool], client_id:int)->bool | +| ------ | ------------------------------------------------------------ | +| 描述 | 用于更新用户订阅的告警 | +| 参数 | 1. id_filter: list[bool]类型,告警类型id列表,若设置id_filter[i]为True,则表明用户设置接收alarm id为1001+i的告警,id_filter长度为128;若设置id_filter[i]为False,表明用户不接收alarm id为1001+i的告警
2. client_id:int类型,调用xalarm_register接口后的返回值 | +| 返回值 | bool类型,若为True这表明更新订阅告警成功,否则表明更新告警订阅失败 | + +接口四、获取告警id信息 + +| 接口 | xalarm_getid(palarm: Xalarm) -> int | +| ------ | ------------------------------------------------------------ | +| 描述 | 用于获取指定告警的id信息 | +| 参数 | palarm: Xalarm类类型,告警消息结构体,详情参考:结构体一、警消息结构体定义 | +| 返回值 | int类型,返回告警id | + +接口五、获取告警类型信息 + +| 接口 | xalarm_gettype(palarm: Xalarm) -> int | +| ------ | ------------------------------------------------------------ | +| 描述 | 用于获取指定告警的类型信息 | +| 参数 | palarm: Xalarm类类型,告警消息结构体,详情参考:告警消息结构体定义 | +| 返回值 | 枚举类型alarm_type,告警类别,取值为:ALARM_TYPE_OCCUR和ALARM_TYPE_RECOVER | + + 接口六、获取告警等级信息 + +| 接口 | xalarm_getlevel(palarm: Xalarm) -> int | +| ------ | ------------------------------------------------------------ | +| 描述 | 用于获取指定告警的等级信息 | +| 参数 | palarm: Xalarm类类型,告警消息结构体,详情参考:告警消息结构体定义 | +| 返回值 | alarm_type类型,告警级别,取值为:MINOR_ALM、MAJOR_ALM、CRITICAL_ALM | + + 接口七、获取告警时间信息 + +| 接口 | xalarm_gettime(palarm: Xalarm) -> int | +| ------ | ------------------------------------------------------------ | +| 描述 | 用于获取指定告警的时间信息 | +| 参数 | palarm: Xalarm类类型,告警消息结构体,详情参考:告警消息结构体定义 | +| 返回值 | 时间戳,TimevalStu类型,包含两个字段tv_sec和tv_usec,分别表示当前时间的秒数和微秒数 | + + 接口八、获取告警描述信息 + +| 接口 | xalarm_getdesc(palarm: Xalarm) -> int | +| ------ | ------------------------------------------------------------ | +| 描述 | 用于获取指定告警的描述信息 | +| 参数 | palarm: Xlarm类类型,告警消息结构体,详情参考:告警消息结构体定义 | +| 返回值 | 字符串类型,返回当前告警消息的描述信息 | + +示例: + +``` +[root@openEuler ~]# cat regi_xalarm.py +import sys +from xalarm.register_xalarm import ( + xalarm_register, + xalarm_unregister, + xalarm_upgrade, + xalarm_getid, + xalarm_getlevel, + xalarm_gettype, + xalarm_gettime, + xalarm_getdesc, + Xalarm, + MAX_NUM_OF_ALARM_ID) +from datetime import datetime +from time import sleep + +def milliseconds_to_formatted_date(milliseconds): + seconds = milliseconds / 1000.0 + dt_object = datetime.fromtimestamp(seconds) + formatted_date = dt_object.strftime('%Y-%m-%d %H:%M:%S') + return formatted_date + +id_filter = [True for _ in range(MAX_NUM_OF_ALARM_ID)] + +def xalarm_callback(alarm_info: Xalarm) -> None: + id_number = xalarm_getid(alarm_info) + if id_number == 0: + print("Recv unexpected alarm id 0.") + return + level = xalarm_getlevel(alarm_info) + type_number = xalarm_gettype(alarm_info) + time_msec = xalarm_gettime(alarm_info) + desc = xalarm_getdesc(alarm_info) + print(f"Recv from id: {id_number}: Level={level}, Type={type_number}, Time={milliseconds_to_formatted_date(time_msec)}, Desc={desc}") + + +if __name__ == "__main__": + client_id = xalarm_register(xalarm_callback, id_filter) + if client_id < 0: + print("connect xalarmd service error!") + sys.exit(1) + sleep(10) + xalarm_unregister(client_id) +``` + +#### 2)c代码注册并获取告警内容 + +需要安装libxlaram软件包 + +``` +[root@openEuler ~]# yum install -y libxlaram +``` +开发环境还需要安装libxalarm-devel包(构建依赖,非运行依赖) +``` +[root@openEuler ~]# yum install -y libxalam-devel +``` + +结构体一、告警消息结构体定义 + +``` +struct alarm_info { + unsigned short usAlarmId; + unsigned char ucAlarmLevel; + unsigned char ucAlarmType; + struct timeval AlarmTime; + char pucParas[ALARM_INFO_MAX_PARAS_LEN]; +}; +``` + +接口一、注册告警 + +| 接口 | int xalarm_Register(alarm_callback_func callback, struct alarm_subscription_info id_filter) | +| ------ | ------------------------------------------------------------ | +| 描述 | sysSentry告警转发子系统xalarmd告警注册接口。 | +| 参数 | 1. callback:用户自定义的告警信息处理函数回调。
2. id_filter:用户需要注册接收的告警id列表。
- alarm_subscription_info.id_list:保存告警id的数组,长度为128;数组中一个元素对应用户订阅的一个告警id;支持的告警id范围为[1001, 1128],共128种。
- alarm_subscription_info.len:用户自定义需要接收的告警id个数,不超过128。len的大小需与用户填充到id_list数组的告警id个数一致。如果len小于用户实际填充id_list的元素个数,仅数组中下标为[0, len)的告警id生效。 | +| 返回值 | client_id,大于0的整数,当前注册告警用户的唯一标识;失败时返回-1。 | + +接口二、取消告警订阅 + +| 接口 | void xalarm_UnRegister(int client_id) | +| -------- | ------------------------------------------------ | +| 功能描述 | sysSentry告警转发子系统xalarmd告警取消订阅接口。 | +| 参数说明 | client_id:注册订阅告警时返回的用户唯一标识。 | + +接口三、更新告警订阅 + +| 接口 | bool xalarm_Upgrade(struct alarm_subscription_info id_filter, int client_id) | +| ------ | ------------------------------------------------------------ | +| 描述 | sysSentry告警转发子系统xalarmd告警更新接口,用于更新用户需要订阅的告警类型。 | +| 参数 | 1. id_filter:用户需要订阅的告警id列表,定义及用法与xalarm_Register接口中的id_filter参数一致;新的列表将覆盖刷新当前已有的告警id列表。
2. client_id:用户调用xalarm_Register注册时返回的用户标识。 | +| 返回值 | 布尔型,表示本次更新订阅告警类型是否成功。 | + +用户自定义callback回调函数,回调函数定义: + +``` +typedef void (*alarm_callback_func)(struct alarm_info *palarm); +``` + +下述`接口四`至`接口八`可以被回调函数触发,用于辅助用户获取告警信息。 + +接口四、获取告警id信息 + +| 接口 | unsigned short xalarm_getid(const struct alarm_info *palarm); | +| ------ | ------------------------------------------------------------ | +| 描述 | 获取告警id接口 | +| 参数 | const struct alarm_info *palarm | +| 返回值 | 非0:告警ID。0:获取不到告警ID信息。 | + +接口五、获取告警类型信息 + +| 接口 | unsigned short xalarm_gettype(const struct alarm_info *palarm); | +| ------ | ------------------------------------------------------------ | +| 描述 | 获取告警类型接口 | +| 参数 | const struct alarm_info *palarm | +| 返回值 | 告警类型,1:ALARM_TYPE_OCCUR,2:ALARM_TYPE_RECOVER | + +接口六、获取告警等级信息 + +| 接口 | unsigned short xalarm_getlevel(const struct alarm_info *palarm); | +| ------ | ------------------------------------------------------------ | +| 描述 | 获取告警级别接口 | +| 参数 | const struct alarm_info *palarm | +| 返回值 | 告警级别,1:MINOR_ALM,2:MAJOR_ALM,3:CRITICAL_ALM,0:获取不到告警级别。 | + +接口七、获取告警时间信息 + +| 接口 | long long xalarm_gettime(const struct alarm_info *palarm); | +| ------ | ------------------------------------------------------------ | +| 描述 | 获取告警时间接口 | +| 参数 | const struct alarm_info *palarm | +| 返回值 | long long类型的正整数,表示UTC时间,单位毫秒(ms)。0:时间存在异常。 | + +接口八、获取告警描述信息 + +| 接口 | char * xalarm_getdesc(const struct alarm_info *palarm); | +| ------ | ------------------------------------------------------- | +| 描述 | 获取描述信息接口 | +| 参数 | const struct alarm_info *palarm | +| 返回值 | 正常:字符串,最长为8191个字符。异常:NULL | + +示例: + +``` +[root@openEuler ~]# cat regi_xalarm.c +#include +#include +#include +#include + +#define SLEEP_TIME 10 +#define ALARM_ID_1 1001 +#define ALARM_ID_2 1002 +#define ALARM_ID_3 1003 +#define ID_LIST_LENGTH 3 + +void RefreshOutput(void) +{ + int ret = fflush(stdout); + if (ret != 0) { + printf("failed to fflush\n"); + } +} + +void callback(struct alarm_info *param) +{ + int alarmid, alarmlevel, alarmtype; + long long alarmtime; + char *pucParas; + + alarmid = xalarm_getid(param); + alarmlevel = xalarm_getlevel(param); + alarmtype = xalarm_gettype(param); + alarmtime = xalarm_gettime(param); + pucParas = xalarm_getdesc(param); + + printf("[alarmid:%d] [alarmlevel:%d] [alarmtype:%d] [alarmtime:%lld ms] [msg:%s]\n", + alarmid, alarmlevel, alarmtype, alarmtime, pucParas); + + RefreshOutput(); +} + +int main(int argc, char **argv) +{ + int clientId; + int ret; + struct alarm_subscription_info id_filter; + + printf("demo start\n"); + + clientId = xalarm_Register(callback, id_filter); + + if (clientId < 0) { + printf("demo register failed\n"); + return -1; + } else { + printf("xalarm register success, client id is %d\n", clientId); + } + printf("demo waiting alarm\n"); + RefreshOutput(); + sleep(SLEEP_TIME); + + xalarm_UnRegister(clientId); + printf("unregister xalarm success\n"); + RefreshOutput(); + return 0; +} + +[root@openEuler ~]# gcc regi_xalarm.c -o regi_xalarm -lxalarm +``` + +### 5. 插件结果上报 + +**前置要求:** 已完成`1.插件管理配置文件.mod` + +用户可通过sysSentry提供的接口将插件巡检结果上报给sysSentry服务,并通过get_result命令查看结果 + +```shell +[root@openEuler ~]# sentryctl get_result <插件名> +``` + +提供python与c两种语言的对外接口: + +#### 1)python巡检结果上报接口 + +结构体:ResultLevel + +``` +class ResultLevel(Enum): + """result level for report_result""" + PASS = 0 + FAIL = 1 + SKIP = 2 + MINOR_ALM = 3 + MAJOR_ALM = 4 + CRITICAL_ALM = 5 +``` + +接口:结果上报 + +| 接口 | int report_result(task_name: str, result_level : ResultLevel, report_data : str) -> int | +| ------ | ------------------------------------------------------------ | +| 描述 | 用于模块工具向sysSentry上报巡检结果 | +| 参数 | 1. task_name:巡检任务名称。
2. result_level:巡检结果异常等级。
3. report_data:巡检结果详细信息,应为json格式转换而成的字符串。 | +| 返回值 | 正常:0,异常:非0 | + +示例: + +``` +[root@openEuler ~]# python3 +Python 3.7.9 (default, Dec 11 2023, 19:40:40) +[GCC 7.3.0] on linux +Type "help", "copyright", "credits" or "license" for more information. +>>> import json +>>> from syssentry.result import ResultLevel, report_result +>>> report_result("test", ResultLevel.PASS, json.dumps({})) +0 +``` + +#### 2)c巡检结果上报接口 + +需要安装libxlaram软件包 + +``` +[root@openEuler ~]# yum install -y libxlaram +``` +开发环境还需要安装libxalarm-devel包(构建依赖,非运行依赖) +``` +[root@openEuler ~]# yum install -y libxalam-devel +``` + +结构体:RESULT_LEVEL + +```c +enum RESULT_LEVEL { + RESULT_LEVEL_PASS = 0, + RESULT_LEVEL_FAIL = 1, + RESULT_LEVEL_SKIP = 2, + RESULT_LEVEL_MINOR_ALM = 3, + RESULT_LEVEL_MAJOR_ALM = 4, + RESULT_LEVEL_CRITICAL_ALM = 5, +}; +``` + +接口:结果上报 + +| 接口 | int report_result(const char *task_name, enum RESULT_LEVEL result_level, const char *report_data); | +| ------ | ------------------------------------------------------------ | +| 描述 | 用于模块工具向sysSentry上报巡检结果 | +| 参数 | 1. task_name:巡检任务名称。
2. result_level:巡检结果异常等级。
3. report_data:巡检结果详细信息,应为json格式转换而成的字符串。 | +| 返回值 | 正常:0,异常:非0 | + +示例: + +``` +[root@openEuler ~]# cat report_res.c +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + enum RESULT_LEVEL result_lv = 0; + result_lv = RESULT_LEVEL_PASS; + details = "{\"a\": 1, \"b\": 2}"; + int res = report_result(task_name, result_lv, details); + if (res == -1) { + printf("failed send result to sysSentry\n"); + } + + return 0; +} +[root@openEuler ~]# gcc report_res.c -o report_res -lxalarm +``` + +## 三、FAQ + +TBC \ No newline at end of file diff --git "a/docs/zh/docs/sysSentry/\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250.md" "b/docs/zh/docs/sysSentry/\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250.md" new file mode 100644 index 0000000000000000000000000000000000000000..0cdfc3dccb5f99a1e06d98be43ab04ce7cc01e50 --- /dev/null +++ "b/docs/zh/docs/sysSentry/\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250.md" @@ -0,0 +1,270 @@ +# sysSentry软件安装与使用 + + +### 一、安装sysSentry + +#### 操作系统 + +openEuler-20.03-LTS-SP4 + +#### 环境准备 + +- 安装openEuler-20.03-LTS-SP4系统,安装方法参考 《[安装指南](https://docs.openeuler.org/zh/docs/20.03_LTS_SP4/docs/Installation/installation.html)》。 +- 安装sysSentry需要使用root权限。 + +#### 配置yum源 + +在/etc/yum.repos.d/创建.repo文件(eg. /etc/yum.repos.d/openEuler.repo),使用编辑器打开.repo文件添加如下内容: + +``` +[osrepo] +name=osrepo +baseurl=https://repo.openeuler.org/openEuler-20.03-LTS-SP4/OS/$basearch/ +enabled=1 +gpgcheck=0 + +[everything] +name=everything +baseurl=https://repo.openeuler.org/openEuler-20.03-LTS-SP4/everything/$basearch/ +enabled=1 +gpgcheck=0 + +[update] +name=update +baseurl=https://repo.openeuler.org/openEuler-20.03-LTS-SP4/update/$basearch/ +enabled=1 +gpgcheck=0 + +[source] +name=update +baseurl=https://repo.openeuler.org/openEuler-20.03-LTS-SP4/source/ +enabled=1 +gpgcheck=0 +``` + +#### 安装sysSentry + +``` +yum install -y sysSentry libxalarm pyxalarm +``` + + + +### 二、部署sysSentry + +#### 1、配置介绍 + +1. sysSentry服务配置,路径/etc/sysSentry/inspect.conf + + | 配置段 | 配置项 | 配置项说明 | 默认值 | 必选 | + | --------- | -------- | ------------------------------------------------------- | ------ | ---- | + | [inspect] | Interval | 默认周期类型巡检任务间隔时间,单位秒 | 3 | Y | + | [log] | level | 日志打印等级,分为debug/info/warning/error/critical五级 | info | Y | + + 示例: + + ``` + [inspect] + Interval=3 + + [log] + level=info + ``` + +2. sentryCollector服务配置,路径/etc/sysSentry/collector.conf + + | 配置段 | 配置项 | 配置项说明 | 默认值 | 必选 | + | -------- | ----------- | ------------------------------------------------------------ | ------- | ---- | + | [common] | modules | 采集哪些模块的数据,多个模块可用逗号拼接,如io、network、memory等,当前仅支持io | io | Y | + | [io] | period_time | IO数据的采集周期,整形类型,单位为秒,默认值为1,范围为1~300,仅在modules配置io时生效 | 1 | N | + | | max_save | 最多保存多少组IO数据,整形类型,默认值为10,范围为1~300,仅在modules配置io时生效 | 10 | N | + | | disk | 需要采集数据的磁盘名称,由逗号分隔,default表示当前环境上所有盘,仅在modules配置io时生效 | default | N | + | [log] | level | 日志打印等级,分为debug/info/warning/error/critical五级 | info | Y | + + 示例: + + ```shell + [common] + modules=io + + [io] + period_time=1 + max_save=10 + disk=default + + [log] + level=info + ``` + +3. xalarmd服务配置,路径/etc/sysSentry/xalarm.conf + + | 配置段 | 配置项 | 配置项说明 | 默认值 | 必选 | + | -------- | ------- | ------------------------------------------------------------ | --------- | ---- | + | [filter] | id_mask | 需要上报的告警类型id,不同id使用“,”分割,也可以用“-”连接连续的告警范围 | 1001-1128 | Y | + | [log] | level | 日志打印等级,分为debug/info/warning/error/critical五级 | info | Y | + +4. 巡检插件管理配置,路径/etc/sysSentry/tasks/[插件名].mod + + | 配置段 | 配置项 | 配置项说明 | 必选 | + | -------- | ------------------ | ------------------------------------------------------------ | ---- | + | [common] | enabled | 插件是否使能,类型为yes/no,分别对应使能和不使能 | Y | + | | task_start | 插件任务拉起时执行的命令 | Y | + | | task_stop | 插件任务中止任务时执行的命令 | Y | + | | type | 插件任务类型,类型为oneshot/period,分别对应单次/周期执行 | Y | + | | interval | 插件任务间隔,该配置仅对period类型任务有效,表示该巡检任务周期性拉起的时间间隔,单位秒 | N | + | | heartbeat_interval | 任务心跳检查间隔,单位秒。当框架收到该巡检任务的心跳间隔超过设定值时,框架判定巡检任务状态已失败,并停止巡检任务;不配置该字段时,框架默认关闭对该模块的心跳检查,仅配置时使能心跳检查 | N | + | | onstart | 是否在sysSentry服务启动时拉起该任务,值为yes/no,未配置时period任务默认启动,oneshot任务默认不启动 | N | + | | env_file | 指定环境变量的文件路径,该文件内容应为key=value的格式,如配置该参数,在启动任务前会将该文件中的值导入环境变量 | N | + | | conflict | 如果当前环境已存在与task_start进程同样的进程时如何处理,非必选配置参数,参数为up/down/kill:
a) up:当前环境已存在同样的进程时,正常拉起巡检任务;配置为up与不配置conflict参数行为一致;
b) down:当前环境已存在同样的进程时,不再拉起巡检任务;
c) kill:当前环境已存在同样的进程时,先将现有进程杀死,随后拉起巡检任务 | N | + | | alarm_id | 告警上报id,id数值为整型,未配置则无法通过get_alarm查询告警信息,范围1001~1128 | N | + | | alarm_clear_time | 告警清理时间,单位秒,数值为整型,超时告警信息将被清除,未配置则无法通过get_alarm查询告警信息,范围0~2^31 - 1 | N | + + 示例: + + ``` + # avg_block_io插件的配置文件如下,路径/etc/sysSentry/tasks/avg_block_io.mod + [common] + enabled=yes + task_start=/usr/bin/python3 /usr/bin/avg_block_io + task_stop=pkill -f /usr/bin/avg_block_io + type=oneshot + alarm_id=1002 + alarm_clear_time=5 + ``` + +#### 2、启动巡检框架 + +``` +# 依次执行以下命令, +systemctl start xalarmd +systemctl start sysSentry +systemctl start sentryCollector +# 执行成功后可通过status命令查看状态为running +systemctl status xalarmd +systemctl status sysSentry +systemctl status sentryCollector +``` + +#### 3、配置巡检任务 + +sysSentry巡检框架以巡检模块(module)的形式管理巡检任务,每个巡检模块由/etc/sysSentry/tasks/目录下对应的.mod配置文件定义,巡检模块的名称即为.mod文件的名称,.mod配置文件用于配置巡检任务的运行参数。 + +#### 4、管理巡检任务 + +- 启动指定巡检任务 + +``` +sentryctl start +``` + +- 终止指定巡检任务 + +``` +sentryctl stop +``` + +- 列出所有已加载的巡检任务及状态 + +``` +sentryctl list +``` + +- 查询指定巡检任务的状态 + +``` +sentryctl status +``` + +巡检状态回显信息: + +| 状态 | 描述 | +| ------- | ------------------------------------------------------------ | +| RUNNING | 巡检任务正在运行 | +| WAITING | 仅period类型巡检任务可设置此状态,表示period巡检任务等待下一次被调度执行 | +| EXITED | 巡检任务尚未执行,或者oneshot类型的巡检任务执行结束处于此状态 | +| FAILED | 巡检任务未拉起成功,或者巡检任务未正常退出 | + +- 重载指定任务配置 + +``` +sentryctl reload +``` + +- 查询指定任务的告警信息 + +```shell +sentryctl get_alarm [options] +``` + +options参数说明: + +| 参数 | 描述 | +| -------------------------------------- | ---------------------------------------------------------- | +| -s TIME_RANGE, --time_range TIME_RANGE | 展示用户指定时间长度内的告警信息,TIME_RANGE为整形,单位秒 | +| -d, --detailed | 打印详细告警信息 | + +回显信息为列表,内部数据为json格式,以平均阈值算法为例,返回内容格式如下: + +```json +[ + { + "alarm_id": 1002, + "alarm_type": 1, # 1:alarm_occur, 2: alarm_recover + "alarm_level": 1, # 1: minor_alm, 2: major_alm, 3: critical_alm + "timestamp": "YYYY-mm-DD HH:MM:SS", + "alarm_info": { + "driver_name": "sda", + "reason": "disk_slow", + "block_stack": "bio", + "io_type": "read", + "alarm_source": "avg_block_io", + "details": { + "latency": "gettag: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], rq_driver: [0,0,0,0,0,437.9,0,0,0,0,517,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], bio: [0,0,0,0,0,521.1,0,0,0,0,557.8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], wbt: [0,0,0,0,0,0,8.5,0,0,0,0,12.0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]", + "iodump": "gettag: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], rq_driver: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], bio: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], wbt: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]" + } + } + }, + ... +] +``` + +alarm_type共两种,1代表告警发生,2代表告警恢复 + +alarm_level共三种,1代表minor_alarm,2代表major_alarm,3代表critical_alarm + + + +- 查询指定巡检任务的巡检结果 + + 注:仅在巡检停止后可查看有效信息 + +``` +sentryctl get_result +``` + +回显信息格式为json格式,内容格式如下: + +``` +{ + "result": "xxx", + "start_time": "YYYY-mm-DD HH:MM:SS", + "end_time": "YYYY-mm-DD HH:MM:SS", + "error_msg" : "xxx", + "details":{} # detail信息因巡检任务不同而不同,具体信息由巡检模块提供 +} +``` + +"result"和"error_msg"对应关系如下: + +| result | 对应error_msg信息 | +| ------------ | ------------------------------------------------------------ | +| PASS | "" | +| SKIP | "not supported.maybe some rpm package not be installed." | +| FAIL | "FAILED. config may be incorrect or the command may be invalid/killed!" | +| MINOR_ALM | "the command output shows that the status is 'INFO' or 'GENERAL_WARN'." | +| MAJOR_ALM | "the command output shows that the status is 'WARN' or 'IMPORTANT_WARN'." | +| CRITICAL_ALM | "the command output shows that the status is 'FAIL' or 'EMERGENCY_WARN'." | + +### 三、常见问题Q&A + +- TBC \ No newline at end of file diff --git "a/docs/zh/docs/sysSentry/\345\271\263\345\235\207\351\230\210\345\200\274\346\205\242\347\233\230\346\243\200\346\265\213.md" "b/docs/zh/docs/sysSentry/\345\271\263\345\235\207\351\230\210\345\200\274\346\205\242\347\233\230\346\243\200\346\265\213.md" new file mode 100644 index 0000000000000000000000000000000000000000..6a5cd4a8fd4107c2fea14f3080c2086dfbd7486d --- /dev/null +++ "b/docs/zh/docs/sysSentry/\345\271\263\345\235\207\351\230\210\345\200\274\346\205\242\347\233\230\346\243\200\346\265\213.md" @@ -0,0 +1,163 @@ +# 平均阈值慢盘检测插件 + +用户可通过平均阈值慢盘检测插件进行慢盘故障检测。 + +### 一、规格要求 + +- 仅支持openEuler-20.03-LTS-SP4版本,并使用4.19.90内核 +- 仅支持对nvme-ssd、sata-ssd、sata-hdd盘进行慢盘检测 + +### 二、安装插件 + +#### 1. 前置条件 + +已安装sysSentry巡检插件,sentryCollector采集服务已配置io相关采集项(请参考《安装和使用》进行配置) + +#### 2. 安装软件包 + +``` +yum install -y avg_block_io pysentry_notify pysentry_collect +``` + +#### 3. (可选)重编内核并重启机器 + +注:该操作为可选步骤,重编内核可以支撑插件进行更详细的慢盘检测 + +##### step1. 下载kernel-source包并解压 + +``` +yumdownloader kernel-source-4.19.90-2409.3.0.0294.oe2003sp4 +# 请跟据机器架构替换[$ARCH]为x86_64或aarch64 +rpm2cpio kernel-source-4.19.90-2409.3.0.0294.oe2003sp4.[$ARCH].rpm |cpio -div +cd usr/src/linux-4.19.90-2409.3.0.0294.oe2003sp4.[$ARCH]/ +``` + +##### step2. 配置&构建 + +``` +yum install -y openssl-devel bc rsync gcc gcc-c++ flex bison m4 ncurses-devel elfutils-libelf-devel + +# 搜索BLK_IO_HIERARCHY_STATS,对应的config全部打开后保存退出 +make menuconfig + +修改Makefile中的EXTRAVERSION = .blk_io (这里修改会体现在最终构建出来的内核版本号上) + +# 编译 +make -j 200 && make modules_install && make install +``` + +##### step3. 使用新内核重启 + +``` +grubby --info ALL # 查看新编的内核对应的index +grubby --set-default-index N # N对应新编内核的index +reboot +``` + +##### step4. 重新启动sysSentry相关服务 + +``` +systemctl restart xalarmd +systemctl restart sysSentry +systemctl restart sentryCollector +``` + +#### 4. 将avg_block_io加入框架管理 + +``` +sentryctl reload avg_block_io +``` + +### 三、配置文件说明 + +avg_block_io插件配置文件路径:/etc/sysSentry/plugins/avg_block_io.ini,配置文件修改会在下一次启动巡检任务时生效。 + +| 配置段 | 配置项 | 配置项说明 | 默认值 | 必选项 | +| -------------------- | ---------------- | ------------------------------------------------------------ | ---------- | ------ | +| [log] | level | 记录日志的等级,可配置范围是debug/info/warning/error/critical,未配置或值异常时使用默认参数 | info | Y | +| [common] | disk | 磁盘名称,由逗号分隔,default表示当前环境上所有盘,配置异常时仅保留正确字段 | default | Y | +| | stage | 监控阶段,由逗号分隔,目前已支持throtl/wbt/gettag/plug/deadline/hctx/requeue/rq_driver/bio九个阶段,根据盘种类不同提供的stage可能有不同,配置default表示盘支持的所有阶段,未配置时使用默认配置,配置异常时报错退出;注:用户自行配置时,必须包含bio阶段 | default | Y | +| | iotype | io类别,由逗号分隔,共支持两种场景:read、write,未配置时使用默认配置,配置异常时报错退出 | read,write | Y | +| | period_time | 数据采集周期,整形类型,单位为秒,范围为1~max(采集周期),未配置时使用默认配置,配置异常时报错退出;注:采集周期=period_time * max_save(请参考sentryCollector配置文件) | 1 | Y | +| [algorithm] | win_size | 平均阈值算法窗口长度,整形类型,该字段值越大,算法统计结果越稳定。范围为win_threshold~300,未配置时使用默认配置,配置异常时报错退出 | 30 | Y | +| | win_threshold | 平均阈值算法超阈值数量,整形类型,该字段值越小,算法上报异常速度越快,误报越高。范围为1~win_size,未配置时使用默认配置,配置异常时报错退出 | 6 | Y | +| [latency_] | read_avg_lim | 读时延平均值上限,单位us,代表窗口中读IO平均时延限制,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | - | Y | +| | write_avg_lim | 写时延平均值上限,单位us,代表窗口中写IO平均时延限制,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | - | Y | +| | read_avg_time | 读时延倍数,整形类型,代表读时延数据超过read_avg_lim数据多少倍时,记为异常数据,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | - | Y | +| | write_avg_time | 写时延倍数,整形类型,代表写时延数据超过write_avg_lim数据多少倍时,记为异常数据,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | - | Y | +| | read_tot_lim | 读时延绝对上限,单位us,读时延超过此数据即为异常数据,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | - | Y | +| | write_tot_lim | 写时延绝对上限,单位us,写时延超过此数据即为异常数据,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | - | Y | +| [iodump] | read_iodump_lim | 读iodump绝对上限,整形类型,读iodump数量超过此数据即为异常数据,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | 0 | Y | +| | write_iodump_lim | 写iodump绝对上限,整形类型,写iodump数量超过此数据即为异常数据,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | 0 | Y | +| [\_] | read_avg_lim | 指定stage阶段的读时延平均值上限,单位us,代表窗口中读IO平均时延限制,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | - | N | +| | read_tot_lim | 指定stage阶段的读时延绝对上限,单位us,读时延超过此数据即为异常数据,数值越大,算法漏报率越高,未配置时使用默认配置,配置异常时报错退出 | - | N | + +**注:** + +1. latency_、iodump、_配置段的所有参数调整均会影响算法的准确性,且优劣并存:若数值越大,算法漏报率越高,则数值越小,算法误报率越高。需要根据经验进行取舍。 + +1. 为磁盘类型,目前仅支持三类:sata_ssd、nvme_ssd、sata_hdd +2. period_time配置需满足以下几条: + 1. 如果巡检插件周期不满足采集模块周期的整数倍,请求不合法 + 2. 如果巡检插件周期超过采集模块存储数据能力,请求不合法 + 3. 如果巡检插件磁盘名与采集模块磁盘名不一致,请求不合法 +3. \\_中的stage可以为common.stage参数支持的任意阶段,该部分为可选配置,如果配置后,在进行到对应阶段的故障检测时将使用该部分的参数,而不是latency_或iodump中的参数 + +### 四、使用平均阈值慢盘检测插件 + +1. 启动巡检 + + ``` + sentryctl start avg_block_io + ``` + +2. 查看巡检插件状态 + + ``` + sentryctl status avg_block_io + ``` + + 状态为RUNNING即为运行中,状态为EXITED为退出 + +3. 查看告警信息 + + ``` + sentryctl get_alarm avg_block_io -s 1 -d + ``` + + 示例: + ``` + [ + { + "alarm_id": 1002, + "alarm_type": 1, + "alarm_level": 1, + "timestamp": "2024-10-23 11:56:51", + "alarm_info": { + "alarm_source": "avg_block_io", + "driver_name": "sda", + "io_type": "write", + "reason": "IO press", + "block_stack": "bio,wbt", + "alarm_type": "latency", + "details": { + "latency": "gettag: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], rq_driver: [0,0,0,0,0,437.9,0,0,0,0,517,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], bio: [0,0,0,0,0,521.1,0,0,0,0,557.8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], wbt: [0,0,0,0,0,0,8.5,0,0,0,0,12.0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]", + "iodump": "gettag: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], rq_driver: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], bio: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], wbt: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]" + } + } + } + ] + ``` +4. 停止巡检 + + ``` + sentryctl stop avg_block_io + ``` + +5. 查看巡检结果信息 + + ``` + sentryctl get_result avg_block_io + ``` + + 注:仅在巡检停止后可查看有效信息 \ No newline at end of file diff --git "a/docs/zh/docs/sysSentry/\346\217\222\344\273\266\344\273\213\347\273\215.md" "b/docs/zh/docs/sysSentry/\346\217\222\344\273\266\344\273\213\347\273\215.md" new file mode 100644 index 0000000000000000000000000000000000000000..3a2eadbc242c0239c767b4a41dd9e287544f0a10 --- /dev/null +++ "b/docs/zh/docs/sysSentry/\346\217\222\344\273\266\344\273\213\347\273\215.md" @@ -0,0 +1,4 @@ +sysSentry巡检框架可对巡检能力进行管理,所有巡检能力均以插件的形式存在,不同插件支持不同巡检能力。sysSentry针对openEuler-20.03-LTS-SP4提供的插件如下: + +- 平均阈值慢盘巡检插件,基于平均阈值实现系统慢盘检测。 +- AI阈值慢盘巡检插件,基于AI阈值算法实现系统慢盘检测。 diff --git a/docs/zh/menu/index.md b/docs/zh/menu/index.md index b0a7d6f4e7036433cb0a53085ab2fccdbca89ac3..d73a3096296ee187956dec43900ced21b0300bce 100644 --- a/docs/zh/menu/index.md +++ b/docs/zh/menu/index.md @@ -188,3 +188,9 @@ headless: true - [镜像裁剪定制工具使用指南]({{< relref "./docs/TailorCustom/overview.md" >}}) - [isocut 使用指南]({{< relref "./docs/TailorCustom/isocut使用指南.md" >}}) - [eNFS用户指南]({{< relref "./docs/eNFS/enfs使用指南.md" >}}) +- [sysSentry用户指南]({{< relref "./docs/sysSentry/sysSentry用户指南.md" >}}) + - [安装和使用]({{< relref "./docs/sysSentry/安装和使用.md" >}}) + - [二次开发指南]({{< relref "./docs/sysSentry/二次开发指南.md" >}}) + - [插件介绍]({{< relref "./docs/sysSentry/插件介绍.md" >}}) + - [平均阈值慢盘检测插件]({{< relref "./docs/sysSentry/平均阈值慢盘检测.md" >}}) + - [AI阈值慢盘检测插件]({{< relref "./docs/sysSentry/AI阈值慢盘检测插件.md" >}})