[collector] jsonPath解析http响应数据和calculates表达式计算实现
This commit is contained in:
@@ -98,6 +98,10 @@ public class Metrics {
|
|||||||
* 指标类型 number:数字 string:字符串
|
* 指标类型 number:数字 string:字符串
|
||||||
*/
|
*/
|
||||||
private String type;
|
private String type;
|
||||||
|
/**
|
||||||
|
* 此字段是否为实例主键
|
||||||
|
*/
|
||||||
|
private boolean instance = false;
|
||||||
/**
|
/**
|
||||||
* 指标单位
|
* 指标单位
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -57,4 +57,9 @@ public interface CommonConstants {
|
|||||||
*/
|
*/
|
||||||
byte SUSPENDING = 0x04;
|
byte SUSPENDING = 0x04;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* null空值占位符
|
||||||
|
*/
|
||||||
|
String NULL_VALUE = " ";
|
||||||
}
|
}
|
||||||
|
|||||||
30
common/src/main/java/com/usthe/common/util/CommonUtil.java
Normal file
30
common/src/main/java/com/usthe/common/util/CommonUtil.java
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -45,6 +45,9 @@ public class IpDomainUtil {
|
|||||||
* @return 存在true
|
* @return 存在true
|
||||||
*/
|
*/
|
||||||
public static boolean isHasSchema(String domainIp) {
|
public static boolean isHasSchema(String domainIp) {
|
||||||
|
if (domainIp == null || "".equals(domainIp)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return DOMAIN_SCHEMA.matcher(domainIp).matches();
|
return DOMAIN_SCHEMA.matcher(domainIp).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,17 +20,21 @@ metrics:
|
|||||||
priority: 0
|
priority: 0
|
||||||
# 指标组中的具体监控指标
|
# 指标组中的具体监控指标
|
||||||
fields:
|
fields:
|
||||||
# 指标信息 包括 field名称, type字段类型:number数字,string字符串, unit:指标单位
|
# 指标信息 包括 field名称, type字段类型:number数字,string字符串,instance是否为实例主键 unit:指标单位
|
||||||
|
- field: hostname
|
||||||
|
type: instance
|
||||||
|
instance: true
|
||||||
- field: usage
|
- field: usage
|
||||||
type: number
|
type: number
|
||||||
unit: '%'
|
unit: '%'
|
||||||
- field: cores
|
- field: cores
|
||||||
type: number
|
type: number
|
||||||
- field: waitime
|
- field: waitTime
|
||||||
type: number
|
type: number
|
||||||
unit: s
|
unit: s
|
||||||
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
|
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
|
||||||
aliasFields:
|
aliasFields:
|
||||||
|
- hostname
|
||||||
- core1
|
- core1
|
||||||
- core2
|
- core2
|
||||||
- usage
|
- usage
|
||||||
@@ -39,6 +43,7 @@ metrics:
|
|||||||
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
|
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
|
||||||
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
|
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
|
||||||
calculates:
|
calculates:
|
||||||
|
- hostname=hostname
|
||||||
- cores=core1+core2
|
- cores=core1+core2
|
||||||
- usage=usage
|
- usage=usage
|
||||||
- waitTime=allTime-runningTime
|
- waitTime=allTime-runningTime
|
||||||
@@ -51,7 +56,7 @@ metrics:
|
|||||||
# 端口
|
# 端口
|
||||||
port: ^_^port^_^
|
port: ^_^port^_^
|
||||||
# url请求接口路径
|
# url请求接口路径
|
||||||
url: /cpu
|
url: /metrics/cpu
|
||||||
# 请求方式 GET POST PUT DELETE PATCH
|
# 请求方式 GET POST PUT DELETE PATCH
|
||||||
method: GET
|
method: GET
|
||||||
# 是否启用ssl/tls,即是http还是https,默认false
|
# 是否启用ssl/tls,即是http还是https,默认false
|
||||||
@@ -69,13 +74,15 @@ metrics:
|
|||||||
type: Basic Auth
|
type: Basic Auth
|
||||||
basicAuthUsername: ^_^username^_^
|
basicAuthUsername: ^_^username^_^
|
||||||
basicAuthPassword: ^_^password^_^
|
basicAuthPassword: ^_^password^_^
|
||||||
# 响应数据解析方式: default-系统规则,json_path-jsonPath脚本,xml_path-xmlPath脚本,prometheus-Prometheus数据规则
|
# 响应数据解析方式: default-系统规则,jsonPath-jsonPath脚本,xmlPath-xmlPath脚本,prometheus-Prometheus数据规则
|
||||||
parseType: jsonPath
|
parseType: jsonPath
|
||||||
parseScript: '$.cpu[:1].*'
|
parseScript: '$'
|
||||||
|
|
||||||
- name: memory
|
- name: memory
|
||||||
priority: 1
|
priority: 1
|
||||||
fields:
|
fields:
|
||||||
|
- field: hostname
|
||||||
|
type: string
|
||||||
- field: total
|
- field: total
|
||||||
type: number
|
type: number
|
||||||
unit: kb
|
unit: kb
|
||||||
@@ -88,7 +95,7 @@ metrics:
|
|||||||
http:
|
http:
|
||||||
host: ^_^host^_^
|
host: ^_^host^_^
|
||||||
port: ^_^port^_^
|
port: ^_^port^_^
|
||||||
url: /memory
|
url: /metrics/memory
|
||||||
method: GET
|
method: GET
|
||||||
headers:
|
headers:
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
@@ -99,5 +106,4 @@ metrics:
|
|||||||
type: Basic Auth
|
type: Basic Auth
|
||||||
basicAuthUsername: ^_^username^_^
|
basicAuthUsername: ^_^username^_^
|
||||||
basicAuthPassword: ^_^password^_^
|
basicAuthPassword: ^_^password^_^
|
||||||
parseType: jsonPath
|
parseType: default
|
||||||
parseScript: '$.memory[:1].*'
|
|
||||||
@@ -14,7 +14,7 @@ param:
|
|||||||
name: 端口
|
name: 端口
|
||||||
type: number
|
type: number
|
||||||
# 当type为number时,用range表示范围
|
# 当type为number时,用range表示范围
|
||||||
range: '[0,255]'
|
range: '[0,65535]'
|
||||||
required: true
|
required: true
|
||||||
- field: username
|
- field: username
|
||||||
name: 用户名
|
name: 用户名
|
||||||
|
|||||||
Reference in New Issue
Block a user