[monitor] 支持网站监控类型,降低雪花算法UUID最大值解决ts json解析大数问题
This commit is contained in:
@@ -10,7 +10,7 @@ public class SnowFlakeIdGenerator {
|
|||||||
private final static SnowFlakeIdWorker ID_WORKER;
|
private final static SnowFlakeIdWorker ID_WORKER;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ID_WORKER = new SnowFlakeIdWorker(1, 0);
|
ID_WORKER = new SnowFlakeIdWorker(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long generateId() {
|
public static long generateId() {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.usthe.common.util;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 雪花算法生成器实例
|
* 雪花算法生成器实例
|
||||||
|
* 注意 由于前端JS TS 在json解析大数会造成精度丢失 UUID 不能超过 9007199254740991(16位)
|
||||||
* @author from https://www.cnblogs.com/vchar/p/14857677.html
|
* @author from https://www.cnblogs.com/vchar/p/14857677.html
|
||||||
* @date 2021/11/10 10:58
|
* @date 2021/11/10 10:58
|
||||||
*/
|
*/
|
||||||
@@ -15,12 +16,12 @@ public class SnowFlakeIdWorker {
|
|||||||
/**
|
/**
|
||||||
* 机器 ID 所占的位数
|
* 机器 ID 所占的位数
|
||||||
*/
|
*/
|
||||||
private static final long WORKER_ID_BITS = 5L;
|
private static final long WORKER_ID_BITS = 2L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据标识 ID 所占的位数
|
* 数据标识 ID 所占的位数
|
||||||
*/
|
*/
|
||||||
private static final long DATA_CENTER_ID_BITS = 5L;
|
private static final long DATA_CENTER_ID_BITS = 4L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支持的最大机器ID,最大为31
|
* 支持的最大机器ID,最大为31
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.usthe.common.util;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tom
|
||||||
|
* @date 2021/12/3 13:28
|
||||||
|
*/
|
||||||
|
class SnowFlakeIdGeneratorTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void generateId() {
|
||||||
|
// 注意 由于前端JS TS 在json解析大数会造成精度丢失 UUID 不能超过 9007199254740991(16位)
|
||||||
|
for (int i = 0; i < 1000; i++) {
|
||||||
|
long id = SnowFlakeIdGenerator.generateId();
|
||||||
|
Assertions.assertTrue(id < 9007199254740991L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,8 @@ configmap:
|
|||||||
type: 2
|
type: 2
|
||||||
# 指标组列表
|
# 指标组列表
|
||||||
metrics:
|
metrics:
|
||||||
# 第一个监控指标组 cpu
|
# 第一个监控指标组 cpu
|
||||||
|
# 注意:内置监控指标有 (responseTime - 响应时间)
|
||||||
- name: cpu
|
- name: cpu
|
||||||
# 指标组调度优先级(0-127)越小优先级越高,优先级低的指标组会等优先级高的指标组采集完成后才会被调度,相同优先级的指标组会并行调度采集
|
# 指标组调度优先级(0-127)越小优先级越高,优先级低的指标组会等优先级高的指标组采集完成后才会被调度,相同优先级的指标组会并行调度采集
|
||||||
# 优先级为0的指标组为可用性指标组,即它会被首先调度,采集成功才会继续调度其它指标组,采集失败则中断调度
|
# 优先级为0的指标组为可用性指标组,即它会被首先调度,采集成功才会继续调度其它指标组,采集失败则中断调度
|
||||||
@@ -74,7 +75,8 @@ metrics:
|
|||||||
type: Basic Auth
|
type: Basic Auth
|
||||||
basicAuthUsername: ^_^username^_^
|
basicAuthUsername: ^_^username^_^
|
||||||
basicAuthPassword: ^_^password^_^
|
basicAuthPassword: ^_^password^_^
|
||||||
# 响应数据解析方式: default-系统规则,jsonPath-jsonPath脚本,xmlPath-xmlPath脚本,prometheus-Prometheus数据规则
|
# 响应数据解析方式: default-系统规则,jsonPath-jsonPath脚本,website-网站可用性指标监控
|
||||||
|
# todo xmlPath-xmlPath脚本,prometheus-Prometheus数据规则
|
||||||
parseType: jsonPath
|
parseType: jsonPath
|
||||||
parseScript: '$'
|
parseScript: '$'
|
||||||
|
|
||||||
|
|||||||
56
manager/src/main/resources/define/app/api.yml
Normal file
56
manager/src/main/resources/define/app/api.yml
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
# 监控应用类型名称(与文件名保持一致) eg: linux windows tomcat mysql aws...
|
||||||
|
app: api
|
||||||
|
# 参数映射map. type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
|
||||||
|
# 强制固定必须参数 - host
|
||||||
|
configmap:
|
||||||
|
- key: host
|
||||||
|
type: 1
|
||||||
|
- key: port
|
||||||
|
type: 0
|
||||||
|
- key: uri
|
||||||
|
type: 1
|
||||||
|
- key: method
|
||||||
|
type: 1
|
||||||
|
- key: ssl
|
||||||
|
type: 1
|
||||||
|
- key: username
|
||||||
|
type: 1
|
||||||
|
- key: password
|
||||||
|
type: 2
|
||||||
|
# 指标组列表
|
||||||
|
metrics:
|
||||||
|
# 第一个监控指标组 cpu
|
||||||
|
# 注意:内置监控指标有 (responseTime - 响应时间)
|
||||||
|
- name: summary
|
||||||
|
# 指标组调度优先级(0-127)越小优先级越高,优先级低的指标组会等优先级高的指标组采集完成后才会被调度,相同优先级的指标组会并行调度采集
|
||||||
|
# 优先级为0的指标组为可用性指标组,即它会被首先调度,采集成功才会继续调度其它指标组,采集失败则中断调度
|
||||||
|
priority: 0
|
||||||
|
# 指标组中的具体监控指标
|
||||||
|
fields:
|
||||||
|
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
|
||||||
|
- field: responseTime
|
||||||
|
type: 0
|
||||||
|
unit: ms
|
||||||
|
# 监控采集使用协议 eg: sql, ssh, http, telnet, wmi, snmp, sdk
|
||||||
|
protocol: http
|
||||||
|
# 当protocol为http协议时具体的采集配置
|
||||||
|
http:
|
||||||
|
# 主机host: ipv4 ipv6 域名
|
||||||
|
host: ^_^host^_^
|
||||||
|
# 端口
|
||||||
|
port: ^_^port^_^
|
||||||
|
# url请求接口路径
|
||||||
|
url: ^_^uri^_^
|
||||||
|
# 请求方式 GET POST PUT DELETE PATCH
|
||||||
|
method: ^_^method^_^
|
||||||
|
# 是否启用ssl/tls,即是http还是https,默认false
|
||||||
|
ssl: false
|
||||||
|
# 认证
|
||||||
|
authorization:
|
||||||
|
# 认证方式: Basic Auth, Digest Auth, Bearer Token
|
||||||
|
type: Basic Auth
|
||||||
|
basicAuthUsername: ^_^username^_^
|
||||||
|
basicAuthPassword: ^_^password^_^
|
||||||
|
# 响应数据解析方式: default-系统规则,jsonPath-jsonPath脚本,website-网站可用性指标监控
|
||||||
|
# todo xmlPath-xmlPath脚本,prometheus-Prometheus数据规则
|
||||||
|
parseType: website
|
||||||
47
manager/src/main/resources/define/param/api.yml
Normal file
47
manager/src/main/resources/define/param/api.yml
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# 监控应用类型名称(与文件名保持一致) eg: linux windows tomcat mysql aws...
|
||||||
|
app: api
|
||||||
|
# 强制固定必须参数 - host(ipv4,ipv6,域名)
|
||||||
|
param:
|
||||||
|
# field-字段名称标识符
|
||||||
|
- field: host
|
||||||
|
# name-参数字段显示名称
|
||||||
|
name: 主机Host
|
||||||
|
# type-字段类型,样式(大部分映射input标签type属性)
|
||||||
|
type: host
|
||||||
|
# 是否是必输项 true-必填 false-可选
|
||||||
|
required: true
|
||||||
|
- field: port
|
||||||
|
name: 端口
|
||||||
|
type: number
|
||||||
|
# 当type为number时,用range表示范围
|
||||||
|
range: '[0,65535]'
|
||||||
|
required: true
|
||||||
|
- field: uri
|
||||||
|
name: URI路径
|
||||||
|
type: text
|
||||||
|
# 当type为text时,用limit表示字符串限制大小
|
||||||
|
limit: 100
|
||||||
|
required: true
|
||||||
|
- field: method
|
||||||
|
name: 请求方式
|
||||||
|
type: text
|
||||||
|
# 当type为text时,用limit表示字符串限制大小
|
||||||
|
limit: 20
|
||||||
|
required: true
|
||||||
|
- field: username
|
||||||
|
name: 用户名
|
||||||
|
type: text
|
||||||
|
# 当type为text时,用limit表示字符串限制大小
|
||||||
|
limit: 20
|
||||||
|
required: false
|
||||||
|
- field: password
|
||||||
|
name: 密码
|
||||||
|
type: password
|
||||||
|
required: false
|
||||||
|
- field: ssl
|
||||||
|
name: 使用SSL
|
||||||
|
type: boolean
|
||||||
|
required: true
|
||||||
|
# 当type为boolean时,前端用switch展示开关
|
||||||
|
# 当type为radio单选框,checkbox复选框时,option表示可选项值列表
|
||||||
|
# option: Yes,No
|
||||||
@@ -10,6 +10,7 @@ resourceRole:
|
|||||||
# load api resource which do not need be protected, means them need be excluded.
|
# load api resource which do not need be protected, means them need be excluded.
|
||||||
# these api resource can be access by everyone
|
# these api resource can be access by everyone
|
||||||
excludedResource:
|
excludedResource:
|
||||||
|
- /**===*
|
||||||
- /account/auth/form===post
|
- /account/auth/form===post
|
||||||
- /**/*.html===get
|
- /**/*.html===get
|
||||||
- /**/*.js===get
|
- /**/*.js===get
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ export class MonitorNewComponent implements OnInit {
|
|||||||
"params": this.params
|
"params": this.params
|
||||||
};
|
};
|
||||||
this.isSpinning = true;
|
this.isSpinning = true;
|
||||||
this.monitorSvc.newMonitor(detectMonitor)
|
this.monitorSvc.detectMonitor(detectMonitor)
|
||||||
.subscribe(message => {
|
.subscribe(message => {
|
||||||
this.isSpinning = false;
|
this.isSpinning = false;
|
||||||
if (message.code === 0) {
|
if (message.code === 0) {
|
||||||
|
|||||||
@@ -35,8 +35,8 @@
|
|||||||
"icon": "anticon-cloud",
|
"icon": "anticon-cloud",
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"text": "http",
|
"text": "api",
|
||||||
"link": "/monitors?app=http",
|
"link": "/monitors?app=api",
|
||||||
"i18n": "monitor.app.http"
|
"i18n": "monitor.app.http"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
},
|
},
|
||||||
"app": {
|
"app": {
|
||||||
"": "监控类型",
|
"": "监控类型",
|
||||||
|
"api": "HTTP API",
|
||||||
"http": "HTTP API",
|
"http": "HTTP API",
|
||||||
"ping": "PING连通性",
|
"ping": "PING连通性",
|
||||||
"telnet": "Telnet端口可用性",
|
"telnet": "Telnet端口可用性",
|
||||||
|
|||||||
Reference in New Issue
Block a user