附录
说明: API的参数分为可选和必选两类,但是DBMind针对部分必选参数设置了默认值。DBMind后台在收到用户请求后首先会对参数进行校验,其中也包括检查是否有必选参数未传递的情况。因此,当一个参数既是必选参数,又没有默认值,用户又没有传入时,请求会在参数校验阶段报错。
DBMind进程启动后,其提供的HTTP(S)接口信息如下:
表 1 DBMind Restful API列表
须知:
|
| {"access_token":"qmWWgt28VSu0YAH5","token_type":"bearer","expires_in":600} | |||
| {"data":[true,"public","Seq Scan on t2 (cost=0.00..3.25 rows=1 width=70)\n Filter: (c1 = 'dadsadasds'::text)\n",[[["1. MISSING_INDEXES: (0.53) Missing required index.","2. HEAVY_SCAN_OPERATOR: (0.47) Existing expensive seq scans. Detail: (name: Seq Scan on t2, parent: None, rows:t2(100), cost rate: 100.0%)"]],[["1. Recommended index: (schema: public, index: t2(c1)).","2. According to business adjustments, try to avoid it"]]]],"success":true} 说明: 详细参见zh-cn_topic_0000002293307709.md。
| ||||
"detector_name": "EsdTestDetector", |
| ||||
{"data":{"alarm_info":{"alarm_cause":null,"alarm_content":null,"alarm_level":"ERROR","alarm_type":"SYSTEM","extra":null},"detector_info":[...],"duration":10,"forecasting_seconds":0,"running":1},"success":true} | |||||
| {"data":{"header":["user_name","db_name","schema_name","application_name","unique_query_id","start_time","finish_time","duration","n_returned_rows","n_tuples_fetched","n_tuples_returned","n_tuples_inserted","n_tuples_updated","n_tuples_deleted","n_blocks_fetched","n_blocks_hit","n_soft_parse","n_hard_parse","db_time","cpu_time","parse_time","plan_time","data_io_time","lock_wait_time","lwlock_wait_time","query"],"rows":[["user1","db1","public"...]...]},"success":true} | ||||
{"data":["openGauss_blks_hit_ratio","openGauss_blks_read_rate"...],"success":true} | |||||
| {"data":[{"labels":{"device":"device","from_instance":"ip","from_job":"exporter","fstype":"ext4","instance":"ip:port","job":"exporter","mountpoint":"mounpoint"},"name":"os_disk_usage","timestamps":[1684900929939,1684900944939,1684900959939,1684900974939],"values":[0.7115459280083043,0.7115460512887748,0.7115461745692453,0.7115462978497158]}],"success":true} | ||||
| {"data":{"header":["history_alarm_id","instance","metric_name","metric_filter","alarm_type","alarm_level","start_at","end_at","alarm_content","extra_info","anomaly_type","alarm_cause"],"rows":[[65,"ip","os_mem_usage",null,"SYSTEM",30,1684762097001,1684762547001,"mem_usage_spike_detector:Find obvious spikes in memory usage.",null,"Spike"]]},"success":true} | ||||
| |||||
| {"data":[{"advise_indexes":[],"redundant_indexes":[],"total":0,"useless_indexes":[{"columns":"c1","schemaName":"public","statement":"DROP INDEX t1_c1_idx;","tbName":"t1","type":3},{"columns":"c2","schemaName":"public","statement":"DROP INDEX t2_c2_idx;","tbName":"t2","type":3}]},{}],"success":true} |
说明: 在调用/v1/api/app/anomaly-detection/detectors/{name}接口,使用PUT方法新增或修改异常检测器时,需要将检测器信息以json的形式传入,其中的detecor_info字段下的detector_name检测算法以及对应的detector_kwargs检测算法超参数字段的参数范围可以参考如下说明:
- 学生化残差检测器-EsdTestDetector:{“alpha”:0.05}。
- 梯度检测器-GradientDetector:{“max_coef”:1,“side”:[“positive”,[“positive”,“negative”,“both”]]}。
- 单调趋势检测器-IncreaseDetector:{“alpha”:null,“side”:[“positive”,[“positive”,“negative”,“both”]]}。
- 四分位间距检测器-InterQuartileRangeDetector:{“outliers”:[3,3]}。
- 均值漂移检测器-LevelShiftDetector:{“agg”:[“median”,[“median”,“mean”,“std”]],“outliers”:[null,6], “side”:[“both”,[“positive”,“negative”,“both”]],“window”:5}。
- 分位数检测器-QuantileDetector:{“high”:1,“low”:0}。
- 周期数据检测器-SeasonalDetector:{“high_ac_threshold”:0.1,“min_seasonal_freq”:2,“outliers”:[null,3], “period”:null,“side”:[“positive,[“positive”,“negative”,“both”]],“window”:10}"。
- 尖峰检测器-SpikeDetector:{“agg”:[“median”,[“median”,“mean”,“std”]],“outliers”:[null,3], “side”:[“both”,[“positive”,“negative”,“both”]],“window”:1}。
- 阈值检测器-ThresholdDetector:{“high”:null,“low”:null,“percentage”:[null,[0,1]]}。
- 波动率漂移检测器-VolatilityShiftDetector:{“agg”:[“std”,[“median”,“mean”,“std”]],“outliers”:[null,6], “side”:[“both”,[“positive”,“negative”,“both”]],“window”:10}。 此外,在检测器信息json中还会包含alarm_info告警信息字段,其中的两个子字段alarm_type告警类型和alarm_level告警级别的相关补充说明如下,使用/v1/api/summary/alarms接口或/v1/api/summary/alarms/count接口查询落盘的异常告警结果详情或数量时,可以使用上述两个参数字段对结果进行进一步筛选:
- alarm_level参数的所有级别及其对应的权重:CRITICAL、FATAL:50,ERROR:40,WARNING、WARN:30,INFO、NOTICE:20,DEBUG:10、NOTSET:0。
- alarm_type参数的所有类型:SYSTEM、SLOW_QUERY、ALARM_LOG、ALARM、SECURITY、PERFORMANCE。 查询异常告警时,还可以通过anomaly_type字段对异常类型进行筛选,纳管云原生数据库时,DBMind默认支持的检测器异常类型包括如下几种:
- high_disk_usage_detector、high_xlog_count_detector、high_mem_usage_detector、mem_leak_detector、session_mem_increase_detector、shared_mem_increase_detector、other_mem_increase_detector、high_cpu_usage_detector、high_thread_pool_rate_detector、high_io_delay_detector、slow_disk_detector、disk_io_jam_detector、lag_detector、packet_loss_detector、leaked_fd_detector、slow_sql_detector、deadlock_detector、core_detector。
微服务模式接口
DBMind以微服务化模式启动后,具备如下几个特征:
- 与全服务模式不同,微服务模式时无需进行用户管理,因此使用DBMind接口时不再需要身份认证与Token鉴权机制;
- 由于无需身份认证,因此在此模式下强制使用HTTPS的双向认证以保证服务与数据安全;
- 由于无需身份认证与用户管理,因此该模式下的全部接口的实例信息都为必选参数,通过该参数在相应的实例执行相应的任务;
鉴于上述特征,即使接口功能相同,微服务模式下的接口为单独开放的接口,与全服务模式下接口不互通,只有在DBMind以微服务模式启动时才支持调用。通过API的路由版本前缀区分两种模式下的接口,全服务为v1前缀,微服务为v2前缀。其提供的HTTPS接口信息如下:
表 2 DBMind微服务Restful API列表
说明: DBMind在微服务模式下启动时为无状态运行,对纳管的实例不感知。因此,在使用DBMind的V2接口时,后台依然会对涉及实例地址的相关参数进行校验,但仅限于IP合法性校验,无法校验该实例是否被纳管。如果DBMind后台通过用户提供的实例地址进行指标查询与计算时出现查询结果为空的情况,DBMind无法判断是该指标确实为空还是用户输入的实例地址参数有误。
指标单位查询接口
/v1/api/summary/metric-unit/{metric}支持的自研指标列表如表3所示,部分由开源组件node_exporter以及Prometheus采集的指标和云原生未开放采集的自研指标暂不展示:
表 3 自研指标说明
DBMind定时任务
DBMind内嵌了可定期拉起并自动执行的定时任务,可以在DBMind的配置文件confpath/dbmind.conf中开启或关闭特定的定时任务。DBMind已经支持的定时任务,以及其对应的简要说明,可以在dbmind.conf中的[TIMED_TASK_LIST]中查看。
- 要开启一个定时任务:在dbmind.conf中的[TIMED_TASK_LIST]中找到要开启的定时任务的名称,然后将其编辑加入[TIMED_TASK]的TASK字段中并保存,用”,“分割多个定时任务。例如,要开启"清理元数据库中的超期数据"的定时任务,可以在[TIMED_TASK]的TASK字段中编辑加入"discard_expired_results”。
- 要关闭一个定时任务:在dbmind.conf中的[TIMED_TASK]的TASK字段中,将需要关闭的定时任务编辑删除并保存。
在dbmind.conf中[TIMED_TASK]的其他字段下可以自行配置各个定时任务自动执行周期,如:配置"discard_expired_results_interval"对应的值,可以对应地修改“清理元数据库中的超期数据”定时任务的自动执行周期。
修改配置文件后运行如下命令使修改生效:
gs_dbmind service reload -c confpath
表 4 DBMind内嵌的定时任务说明
不建议关闭,该定时任务可定时检测实例的纳管情况,从而在纳管实例发生变化时(如主备倒换、增加纳管、减少纳管、扩缩容等)及时更新异常检测器的检测范围。 | |||||
DBMind的元数据库结构
DBMind元数据库是储存DBMind各类运行数据的数据库,其数据结构如下。
表 5 tb_anomaly_detectors列说明
表 6 tb_existing_indexes列说明
表 7 tb_healing_records列说明
表 8 tb_high_availability_status列说明
表 9 tb_history_alarms列说明
表 10 tb_history_cluster_diagnosis列说明
表 11 tb_index_recommendation列说明
表 12 tb_index_recommendation_stats列说明
表 13 tb_index_recommendation_stmt_details列说明
表 14 tb_index_recommendation_stmt_templates列说明
表 15 tb_knob_recommendation_details列说明
表 16 tb_knob_recommendation_metric_snapshot列说明
表 17 tb_knob_recommendation_warnings列说明
表 18 tb_metric_statistics列说明
表 19 tb_regular_inspections列说明
表 20 tb_security_anomaly_values列说明
表 21 tb_security_metric_models列说明
表 22 tb_slow_queries列说明
表 23 tb_slow_queries_journal列说明
表 24 tb_killed_slow_queries列说明