From 78527d48a6af26c26432138e3cd88fe5c163966b Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Sat, 20 Nov 2021 18:13:16 +0800 Subject: [PATCH] =?UTF-8?q?[collector]=20jsonPath=E8=A7=A3=E6=9E=90http?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E6=95=B0=E6=8D=AE=E5=92=8Ccalculates?= =?UTF-8?q?=E8=A1=A8=E8=BE=BE=E5=BC=8F=E8=AE=A1=E7=AE=97=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/usthe/common/entity/job/Metrics.java | 4 +++ .../usthe/common/util/CommonConstants.java | 5 ++++ .../com/usthe/common/util/CommonUtil.java | 30 +++++++++++++++++++ .../com/usthe/common/util/IpDomainUtil.java | 3 ++ .../main/resources/define/app/A-example.yml | 22 +++++++++----- .../main/resources/define/param/A-example.yml | 2 +- 6 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 common/src/main/java/com/usthe/common/util/CommonUtil.java diff --git a/common/src/main/java/com/usthe/common/entity/job/Metrics.java b/common/src/main/java/com/usthe/common/entity/job/Metrics.java index fce17c1..8b0542f 100644 --- a/common/src/main/java/com/usthe/common/entity/job/Metrics.java +++ b/common/src/main/java/com/usthe/common/entity/job/Metrics.java @@ -98,6 +98,10 @@ public class Metrics { * 指标类型 number:数字 string:字符串 */ private String type; + /** + * 此字段是否为实例主键 + */ + private boolean instance = false; /** * 指标单位 */ diff --git a/common/src/main/java/com/usthe/common/util/CommonConstants.java b/common/src/main/java/com/usthe/common/util/CommonConstants.java index 3debb5b..bcbb043 100644 --- a/common/src/main/java/com/usthe/common/util/CommonConstants.java +++ b/common/src/main/java/com/usthe/common/util/CommonConstants.java @@ -57,4 +57,9 @@ public interface CommonConstants { */ byte SUSPENDING = 0x04; + + /** + * null空值占位符 + */ + String NULL_VALUE = " "; } diff --git a/common/src/main/java/com/usthe/common/util/CommonUtil.java b/common/src/main/java/com/usthe/common/util/CommonUtil.java new file mode 100644 index 0000000..ad3bbcb --- /dev/null +++ b/common/src/main/java/com/usthe/common/util/CommonUtil.java @@ -0,0 +1,30 @@ +package com.usthe.common.util; + +import lombok.extern.slf4j.Slf4j; + +/** + * 公共工具类 + * @author tomsun28 + * @date 2021/11/20 17:29 + */ +@Slf4j +public class CommonUtil { + + /** + * 将字符串str转换为double数字类型 + * @param str string + * @return double 数字 + */ + public static Double parseDoubleStr(String str) { + if (str == null || "".equals(str)) { + return null; + } + try { + return Double.parseDouble(str); + } catch (Exception e) { + log.debug(e.getMessage(), e); + return null; + } + } + +} diff --git a/common/src/main/java/com/usthe/common/util/IpDomainUtil.java b/common/src/main/java/com/usthe/common/util/IpDomainUtil.java index 00ad59a..0500aac 100644 --- a/common/src/main/java/com/usthe/common/util/IpDomainUtil.java +++ b/common/src/main/java/com/usthe/common/util/IpDomainUtil.java @@ -45,6 +45,9 @@ public class IpDomainUtil { * @return 存在true */ public static boolean isHasSchema(String domainIp) { + if (domainIp == null || "".equals(domainIp)) { + return false; + } return DOMAIN_SCHEMA.matcher(domainIp).matches(); } diff --git a/manager/src/main/resources/define/app/A-example.yml b/manager/src/main/resources/define/app/A-example.yml index 60abaef..8877769 100644 --- a/manager/src/main/resources/define/app/A-example.yml +++ b/manager/src/main/resources/define/app/A-example.yml @@ -20,17 +20,21 @@ metrics: priority: 0 # 指标组中的具体监控指标 fields: - # 指标信息 包括 field名称, type字段类型:number数字,string字符串, unit:指标单位 + # 指标信息 包括 field名称, type字段类型:number数字,string字符串,instance是否为实例主键 unit:指标单位 + - field: hostname + type: instance + instance: true - field: usage type: number unit: '%' - field: cores type: number - - field: waitime + - field: waitTime type: number unit: s # (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换 aliasFields: + - hostname - core1 - core2 - usage @@ -39,6 +43,7 @@ metrics: # (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值 # eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime calculates: + - hostname=hostname - cores=core1+core2 - usage=usage - waitTime=allTime-runningTime @@ -51,7 +56,7 @@ metrics: # 端口 port: ^_^port^_^ # url请求接口路径 - url: /cpu + url: /metrics/cpu # 请求方式 GET POST PUT DELETE PATCH method: GET # 是否启用ssl/tls,即是http还是https,默认false @@ -69,13 +74,15 @@ metrics: type: Basic Auth basicAuthUsername: ^_^username^_^ basicAuthPassword: ^_^password^_^ - # 响应数据解析方式: default-系统规则,json_path-jsonPath脚本,xml_path-xmlPath脚本,prometheus-Prometheus数据规则 + # 响应数据解析方式: default-系统规则,jsonPath-jsonPath脚本,xmlPath-xmlPath脚本,prometheus-Prometheus数据规则 parseType: jsonPath - parseScript: '$.cpu[:1].*' + parseScript: '$' - name: memory priority: 1 fields: + - field: hostname + type: string - field: total type: number unit: kb @@ -88,7 +95,7 @@ metrics: http: host: ^_^host^_^ port: ^_^port^_^ - url: /memory + url: /metrics/memory method: GET headers: apiVersion: v1 @@ -99,5 +106,4 @@ metrics: type: Basic Auth basicAuthUsername: ^_^username^_^ basicAuthPassword: ^_^password^_^ - parseType: jsonPath - parseScript: '$.memory[:1].*' \ No newline at end of file + parseType: default \ No newline at end of file diff --git a/manager/src/main/resources/define/param/A-example.yml b/manager/src/main/resources/define/param/A-example.yml index 8d909e3..43fdf24 100644 --- a/manager/src/main/resources/define/param/A-example.yml +++ b/manager/src/main/resources/define/param/A-example.yml @@ -14,7 +14,7 @@ param: name: 端口 type: number # 当type为number时,用range表示范围 - range: '[0,255]' + range: '[0,65535]' required: true - field: username name: 用户名