[home]feature: support home docs i18n en (#94)

* [home]feature: support home docs i18n en

* [home]feature: i18n update introduce

* [web-app]i18n for zh-TW

* [home]feature: i18n update docs
This commit is contained in:
tomsun28
2022-04-17 21:36:13 +08:00
committed by GitHub
parent 630c571f28
commit 81896f9ba1
57 changed files with 4553 additions and 499 deletions

View File

@@ -0,0 +1,132 @@
---
id: extend-http-default
title: HTTP协议系统默认解析方式
sidebar_label: 系统默认解析方式
---
> HTTP接口调用获取响应数据后用HertzBeat默认的解析方式去解析响应数据。
**此需接口响应数据结构符合HertzBeat指定的数据结构规则**
### HertzBeat数据格式规范
注意⚠️ 响应数据为JSON
单层格式key-value
```json
{
"metricName1": "metricValue",
"metricName2": "metricValue",
"metricName3": "metricValue",
"metricName4": "metricValue"
}
```
多层格式数组里面套key-value
```json
[
{
"metricName1": "metricValue",
"metricName2": "metricValue",
"metricName3": "metricValue",
"metricName4": "metricValue"
},
{
"metricName1": "metricValue",
"metricName2": "metricValue",
"metricName3": "metricValue",
"metricName4": "metricValue"
}
]
```
样例:
查询自定义系统的CPU信息其暴露接口为 `/metrics/cpu`,我们需要其中的`hostname,core,useage`指标
若只有一台虚拟机,其单层格式为:
```json
{
"hostname": "linux-1",
"core": 1,
"usage": 78.0,
"allTime": 200,
"runningTime": 100
}
```
若有多台虚拟机,其多层格式为:
```json
[
{
"hostname": "linux-1",
"core": 1,
"usage": 78.0,
"allTime": 200,
"runningTime": 100
},
{
"hostname": "linux-2",
"core": 3,
"usage": 78.0,
"allTime": 566,
"runningTime": 34
},
{
"hostname": "linux-3",
"core": 4,
"usage": 38.0,
"allTime": 500,
"runningTime": 20
}
]
```
**对应的监控配置定义文件YML可以配置为如下**
```yaml
# 此监控类型所属类别service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
category: custom
# 监控应用类型(与文件名保持一致) eg: linux windows tomcat mysql aws...
app: example
name:
zh-CN: 模拟应用类型
en-US: EXAMPLE APP
# 参数映射map. 这些为输入参数变量,即可以用^_^host^_^的形式写到后面的配置中,系统自动变量值替换
# type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
# 强制固定必须参数 - host
configmap:
- key: host
type: 1
- key: port
type: 0
# 指标组列表
metrics:
# 第一个监控指标组 cpu
# 注意:内置监控指标有 (responseTime - 响应时间)
- name: cpu
# 指标组调度优先级(0-127)越小优先级越高,优先级低的指标组会等优先级高的指标组采集完成后才会被调度,相同优先级的指标组会并行调度采集
# 优先级为0的指标组为可用性指标组,即它会被首先调度,采集成功才会继续调度其它指标组,采集失败则中断调度
priority: 0
# 指标组中的具体监控指标
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: hostname
type: 1
instance: true
- field: usage
type: 0
unit: '%'
- field: core
type: 0
# 监控采集使用协议 eg: sql, ssh, http, telnet, wmi, snmp, sdk
protocol: http
# 当protocol为http协议时具体的采集配置
http:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
# url请求接口路径
url: /metrics/cpu
# 请求方式 GET POST PUT DELETE PATCH
method: GET
# 是否启用ssl/tls,即是http还是https,默认false
ssl: false
# 响应数据解析方式: default-系统规则,jsonPath-jsonPath脚本,website-网站可用性指标监控
# 这里使用HertzBeat默认解析
parseType: default
```

View File

@@ -0,0 +1,149 @@
---
id: extend-http-jsonpath
title: HTTP协议JsonPath解析方式
sidebar_label: JsonPath解析方式
---
> HTTP接口调用获取响应数据后用JsonPath脚本解析的解析方式去解析响应数据。
注意⚠️ 响应数据为JSON格式
**使用JsonPath脚本将响应数据解析成符合HertzBeat指定的数据结构规则的数据**
#### JsonPath操作符
[JSONPath在线验证](https://www.jsonpath.cn)
| JSONPATH | 帮助描述 |
| ----------- | ----------- |
| $ | 根对象或元素 |
| @ | 当前对象或元素 |
| . or [] | 子元素操作符 |
| .. | 递归匹配所有子元素 |
| * | 通配符. 匹配所有对象或元素. |
| [] | 下标运算符JsonPath索引从0开始 |
| [,] | 连接运算符将多个结果拼成数组返回JSONPath允许使用别名. |
| [start:end:step] | 数组切片运算符 |
| ?() | 过滤器(脚本)表达式. |
| () | 脚本表达式. |
#### HertzBeat数据格式规范
单层格式key-value
```json
{
"metricName1": "metricValue",
"metricName2": "metricValue",
"metricName3": "metricValue",
"metricName4": "metricValue"
}
```
多层格式数组里面套key-value
```json
[
{
"metricName1": "metricValue",
"metricName2": "metricValue",
"metricName3": "metricValue",
"metricName4": "metricValue"
},
{
"metricName1": "metricValue",
"metricName2": "metricValue",
"metricName3": "metricValue",
"metricName4": "metricValue"
}
]
```
#### 样例
查询自定义系统的数值信息,其暴露接口为 `/metrics/person`,我们需要其中的`type,num`指标
接口返回的原始数据如下:
```json
{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"number": [
{
"type": "core",
"num": 3343
},
{
"type": "home",
"num": 4543
}
]
}
```
我们使用JsonPath脚本解析对应的脚本为: `$.number[*]` ,解析后的数据结构如下:
```json
[
{
"type": "core",
"num": 3343
},
{
"type": "home",
"num": 4543
}
]
```
此数据结构符合HertzBeat的数据格式规范成功提取指标`type,num`值。
**对应的监控配置定义文件YML可以配置为如下**
```yaml
# 此监控类型所属类别service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
category: custom
# 监控应用类型(与文件名保持一致) eg: linux windows tomcat mysql aws...
app: example
name:
zh-CN: 模拟应用类型
en-US: EXAMPLE APP
# 参数映射map. 这些为输入参数变量,即可以用^_^host^_^的形式写到后面的配置中,系统自动变量值替换
# type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
# 强制固定必须参数 - host
configmap:
- key: host
type: 1
- key: port
type: 0
# 指标组列表
metrics:
# 第一个监控指标组 person
# 注意:内置监控指标有 (responseTime - 响应时间)
- name: cpu
# 指标组调度优先级(0-127)越小优先级越高,优先级低的指标组会等优先级高的指标组采集完成后才会被调度,相同优先级的指标组会并行调度采集
# 优先级为0的指标组为可用性指标组,即它会被首先调度,采集成功才会继续调度其它指标组,采集失败则中断调度
priority: 0
# 指标组中的具体监控指标
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: type
type: 1
instance: true
- field: num
type: 0
# 监控采集使用协议 eg: sql, ssh, http, telnet, wmi, snmp, sdk
protocol: http
# 当protocol为http协议时具体的采集配置
http:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
# url请求接口路径
url: /metrics/person
# 请求方式 GET POST PUT DELETE PATCH
method: GET
# 是否启用ssl/tls,即是http还是https,默认false
ssl: false
# 响应数据解析方式: default-系统规则,jsonPath-jsonPath脚本,website-网站可用性指标监控
# 这里使用jsonPath解析
parseType: $.number[*]
```

View File

@@ -0,0 +1,215 @@
---
id: extend-http
title: HTTP协议自定义监控
sidebar_label: HTTP协议自定义监控
---
> 从[自定义监控](extend-point)了解熟悉了怎么自定义类型指标协议等这里我们来详细介绍下用HTTP协议自定义指标监控。
### HTTP协议采集流程
【**HTTP接口调用**】->【**响应校验**】->【**响应数据解析**】->【**默认方式解析JsonPath脚本解析 | XmlPath解析(todo) | Prometheus解析(todo)**】->【**指标数据提取**】
由流程可见我们自定义一个HTTP协议的监控类型需要配置HTTP请求参数配置获取哪些指标对响应数据配置解析方式和解析脚本。
HTTP协议支持我们自定义HTTP请求路径请求header请求参数请求方式请求体等。
**系统默认解析方式**http接口返回hertzbeat规定的json数据结构即可用默认解析方式解析数据提取对应的指标数据详细介绍见 [**系统默认解析**](extend-http-default)
**JsonPath脚本解析方式**用JsonPath脚本对响应的json数据进行解析返回系统指定的数据结构然后提供对应的指标数据详细介绍见 [**JsonPath脚本解析**](extend-http-jsonpath)
### 自定义步骤
配置自定义监控类型需新增配置两个YML文件
1. 用监控类型命名的监控配置定义文件 - 例如example.yml 需位于安装目录 /hertzbeat/define/app/ 下
2. 用监控类型命名的监控参数定义文件 - 例如example.yml 需位于安装目录 /hertzbeat/define/param/ 下
3. 重启hertzbeat系统我们就适配好了一个新的自定义监控类型。
-------
下面详细介绍下这俩文件的配置用法,请注意看使用注释。
### 监控配置定义文件
> 监控配置定义文件用于定义 *监控类型的名称(国际化), 请求参数映射, 指标信息, 采集协议配置信息*等。
样例自定义一个名称为example_http的自定义监控类型其使用HTTP协议采集指标数据。
文件名称: example_http.yml 位于 /define/app/example_http.yml
```yaml
# 此监控类型所属类别service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
category: custom
# 监控应用类型(与文件名保持一致) eg: linux windows tomcat mysql aws...
app: example_http
name:
zh-CN: 模拟应用类型
en-US: EXAMPLE APP
# 参数映射map. 这些为输入参数变量,即可以用^_^host^_^的形式写到后面的配置中,系统自动变量值替换
# type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
# 强制固定必须参数 - host
configmap:
- key: host
type: 1
- key: port
type: 0
- key: username
type: 1
- key: password
type: 2
# 指标组列表
metrics:
# 第一个监控指标组 cpu
# 注意:内置监控指标有 (responseTime - 响应时间)
- name: cpu
# 指标组调度优先级(0-127)越小优先级越高,优先级低的指标组会等优先级高的指标组采集完成后才会被调度,相同优先级的指标组会并行调度采集
# 优先级为0的指标组为可用性指标组,即它会被首先调度,采集成功才会继续调度其它指标组,采集失败则中断调度
priority: 0
# 指标组中的具体监控指标
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: hostname
type: 1
instance: true
- field: usage
type: 0
unit: '%'
- field: cores
type: 0
- field: waitTime
type: 0
unit: s
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
aliasFields:
- hostname
- core1
- core2
- usage
- allTime
- runningTime
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
calculates:
- hostname=hostname
- cores=core1+core2
- usage=usage
- waitTime=allTime-runningTime
# 监控采集使用协议 eg: sql, ssh, http, telnet, wmi, snmp, sdk
protocol: http
# 当protocol为http协议时具体的采集配置
http:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
# url请求接口路径
url: /metrics/cpu
# 请求方式 GET POST PUT DELETE PATCH
method: GET
# 是否启用ssl/tls,即是http还是https,默认false
ssl: false
# 请求头内容
headers:
apiVersion: v1
# 请求参数内容
params:
param1: param1
param2: param2
# 认证
authorization:
# 认证方式: Basic Auth, Digest Auth, Bearer Token
type: Basic Auth
basicAuthUsername: ^_^username^_^
basicAuthPassword: ^_^password^_^
# 响应数据解析方式: default-系统规则,jsonPath-jsonPath脚本,website-网站可用性指标监控
# todo xmlPath-xmlPath脚本,prometheus-Prometheus数据规则
parseType: jsonPath
parseScript: '$'
- name: memory
priority: 1
fields:
- field: hostname
type: 1
instance: true
- field: total
type: 0
unit: kb
- field: usage
type: 0
unit: '%'
- field: speed
type: 0
protocol: http
http:
host: ^_^host^_^
port: ^_^port^_^
url: /metrics/memory
method: GET
headers:
apiVersion: v1
params:
param1: param1
param2: param2
authorization:
type: Basic Auth
basicAuthUsername: ^_^username^_^
basicAuthPassword: ^_^password^_^
parseType: default
```
### 监控参数定义文件
> 监控参数定义文件用于定义 *需要的输入参数字段结构定义(前端页面根据结构渲染输入参数框)*。
样例自定义一个名称为example_http的自定义监控类型其使用HTTP协议采集指标数据。
文件名称: example_http.yml 位于 //define/param/example_http.yml
```yaml
# 监控应用类型名称(与文件名保持一致) eg: linux windows tomcat mysql aws...
app: example_http
# 强制固定必须参数 - 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
# 端口默认值
defaultValue: 80
# 参数输入框提示信息
placeholder: '请输入端口'
- 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时,前端用switch展示开关
type: boolean
required: false
- field: method
name: 请求方式
type: radio
required: true
# 当type为radio单选框,checkbox复选框时,option表示可选项值列表 {name1:value1,name2:value2}
options:
- label: GET请求
value: GET
- label: POST请求
value: POST
- label: PUT请求
value: PUT
- label: DELETE请求
value: DELETE
```

View File

@@ -0,0 +1,252 @@
---
id: extend-jdbc
title: JDBC协议自定义监控
sidebar_label: JDBC协议自定义监控
---
> 从[自定义监控](extend-point)了解熟悉了怎么自定义类型指标协议等这里我们来详细介绍下用JDBC(目前支持mysql,mariadb,postgresql,sqlserver)自定义指标监控。
> JDBC协议自定义监控可以让我们很方便的通过写SQL查询语句就能监控到我们想监控的指标
### JDBC协议采集流程
【**系统直连MYSQL**】->【**运行SQL查询语句**】->【**响应数据解析:oneRow, multiRow, columns**】->【**指标数据提取**】
由流程可见我们自定义一个JDBC协议的监控类型需要配置JDBC请求参数配置获取哪些指标配置查询SQL语句。
### 数据解析方式
SQL查询回来的数据字段和我们需要的指标映射就能获取对应的指标数据目前映射解析方式有三种oneRow, multiRow, columns
#### **oneRow**
> 查询一行数据, 通过查询返回结果集的列名称,和查询的字段映射
例如:
查询的指标字段为one tow three four
查询SQLselect one, tow, three, four from book limit 1;
这里指标字段就能和响应数据一一映射为一行采集数据。
#### **multiRow**
> 查询多行数据, 通过查询返回结果集的列名称,和查询的字段映射
例如:
查询的指标字段为one tow three four
查询SQLselect one, tow, three, four from book;
这里指标字段就能和响应数据一一映射为多行采集数据。
#### **columns**
> 采集一行指标数据, 通过查询的两列数据(key-value)key和查询的字段匹配value为查询字段的值
例如:
查询字段one tow three four
查询SQLselect key, value from book;
SQL响应数据
| key | value |
| ----------- | ----------- |
| one | 243 |
| two | 435 |
| three | 332 |
| four | 643 |
这里指标字段就能和响应数据的key映射,获取对应的value为其采集监控数据。
### 自定义步骤
配置自定义监控类型需新增配置两个YML文件
1. 用监控类型命名的监控配置定义文件 - 例如example_sql.yml 需位于安装目录 /hertzbeat/define/app/ 下
2. 用监控类型命名的监控参数定义文件 - 例如example_sql.yml 需位于安装目录 /hertzbeat/define/param/ 下
3. 重启hertzbeat系统我们就适配好了一个新的自定义监控类型。
-------
下面详细介绍下这俩文件的配置用法,请注意看使用注释。
### 监控配置定义文件
> 监控配置定义文件用于定义 *监控类型的名称(国际化), 请求参数映射, 指标信息, 采集协议配置信息*等。
样例自定义一个名称为example_sql的自定义监控类型其使用JDBC协议采集指标数据。
文件名称: example_sql.yml 位于 /define/app/example_sql.yml
```yaml
# 此监控类型所属类别service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
category: db
# 监控应用类型(与文件名保持一致) eg: linux windows tomcat mysql aws...
app: example_sql
name:
zh-CN: 模拟MYSQL应用类型
en-US: MYSQL EXAMPLE APP
# 参数映射map. 这些为输入参数变量,即可以用^_^host^_^的形式写到后面的配置中,系统自动变量值替换
# type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
# 强制固定必须参数 - host
configmap:
- key: host
type: 1
- key: port
type: 0
- key: username
type: 1
- key: password
type: 2
- key: database
type: 1
- key: url
type: 1
# 指标组列表
metrics:
- name: basic
# 指标组调度优先级(0-127)越小优先级越高,优先级低的指标组会等优先级高的指标组采集完成后才会被调度,相同优先级的指标组会并行调度采集
# 优先级为0的指标组为可用性指标组,即它会被首先调度,采集成功才会继续调度其它指标组,采集失败则中断调度
priority: 0
# 指标组中的具体监控指标
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: version
type: 1
instance: true
- field: port
type: 1
- field: datadir
type: 1
- field: max_connections
type: 0
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
aliasFields:
- version
- version_compile_os
- version_compile_machine
- port
- datadir
- max_connections
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
calculates:
- port=port
- datadir=datadir
- max_connections=max_connections
- version=version+"_"+version_compile_os+"_"+version_compile_machine
protocol: jdbc
jdbc:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
platform: mysql
username: ^_^username^_^
password: ^_^password^_^
database: ^_^database^_^
# SQL查询方式 oneRow, multiRow, columns
queryType: columns
# sql
sql: show global variables where Variable_name like 'version%' or Variable_name = 'max_connections' or Variable_name = 'datadir' or Variable_name = 'port';
url: ^_^url^_^
- name: status
priority: 1
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: threads_created
type: 0
- field: threads_connected
type: 0
- field: threads_cached
type: 0
- field: threads_running
type: 0
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
aliasFields:
- threads_created
- threads_connected
- threads_cached
- threads_running
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
calculates:
- threads_created=threads_created
- threads_connected=threads_connected
- threads_cached=threads_cached
- threads_running=threads_running
protocol: jdbc
jdbc:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
platform: mysql
username: ^_^username^_^
password: ^_^password^_^
database: ^_^database^_^
# SQL查询方式 oneRow, multiRow, columns
queryType: columns
# sql
sql: show global status where Variable_name like 'thread%' or Variable_name = 'com_commit' or Variable_name = 'com_rollback' or Variable_name = 'questions' or Variable_name = 'uptime';
url: ^_^url^_^
- name: innodb
priority: 2
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: innodb_data_reads
type: 0
unit: 次数
- field: innodb_data_writes
type: 0
unit: 次数
- field: innodb_data_read
type: 0
unit: kb
- field: innodb_data_written
type: 0
unit: kb
protocol: jdbc
jdbc:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
platform: mysql
username: ^_^username^_^
password: ^_^password^_^
database: ^_^database^_^
# SQL查询方式 oneRow, multiRow, columns
queryType: columns
# sql
sql: show global status where Variable_name like 'innodb%';
url: ^_^url^_^
```
### 监控参数定义文件
> 监控参数定义文件用于定义 *需要的输入参数字段结构定义(前端页面根据结构渲染输入参数框)*。
样例自定义一个名称为example_sql的自定义监控类型其使用JDBC协议采集指标数据。
文件名称: example_sql.yml 位于 /define/param/example_sql.yml
```yaml
app: example_sql
param:
- field: host
name: 主机Host
type: host
required: true
- field: port
name: 端口
type: number
range: '[0,65535]'
required: true
defaultValue: 80
placeholder: '请输入端口'
- field: database
name: 数据库名称
type: text
required: false
- field: username
name: 用户名
type: text
limit: 20
required: false
- field: password
name: 密码
type: password
required: false
- field: url
name: URL
type: text
required: false
```

View File

@@ -1,6 +1,206 @@
---
id: extend-point
title: 进阶扩展
sidebar_label: 扩展点
title: 自定义监控
sidebar_label: 自定义监控
---
> HertzBeat拥有自定义监控能力您只需配置两个YML文件就能适配一款自定义的监控类型。
> 目前自定义监控支持[HTTP协议](extend-http)[JDBC协议](extend-jdbc)(mysql,mariadb,postgresql..)[SSH协议](extend-ssh),后续会支持更多通用协议(ssh telnet wmi snmp)。
### 自定义步骤
配置自定义监控类型需新增配置两个YML文件
1. 用监控类型命名的监控配置定义文件 - 例如example.yml 需位于安装目录 /hertzbeat/define/app/ 下
2. 用监控类型命名的监控参数定义文件 - 例如example.yml 需位于安装目录 /hertzbeat/define/param/ 下
3. 重启hertzbeat系统我们就适配好了一个新的自定义监控类型。
-------
下面详细介绍下这俩文件的配置用法。
### 监控配置定义文件
> 监控配置定义文件用于定义 *监控类型的名称(国际化), 请求参数映射, 指标信息, 采集协议配置信息*等。
样例自定义一个名称为example的自定义监控类型其使用HTTP协议采集指标数据。
文件名称: example.yml 位于 /define/app/example.yml
```yaml
# 此监控类型所属类别service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
category: custom
# 监控应用类型(与文件名保持一致) eg: linux windows tomcat mysql aws...
app: example
name:
zh-CN: 模拟应用类型
en-US: EXAMPLE APP
# 参数映射map. 这些为输入参数变量,即可以用^_^host^_^的形式写到后面的配置中,系统自动变量值替换
# type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
# 强制固定必须参数 - host
configmap:
- key: host
type: 1
- key: port
type: 0
- key: username
type: 1
- key: password
type: 2
# 指标组列表
metrics:
# 第一个监控指标组 cpu
# 注意:内置监控指标有 (responseTime - 响应时间)
- name: cpu
# 指标组调度优先级(0-127)越小优先级越高,优先级低的指标组会等优先级高的指标组采集完成后才会被调度,相同优先级的指标组会并行调度采集
# 优先级为0的指标组为可用性指标组,即它会被首先调度,采集成功才会继续调度其它指标组,采集失败则中断调度
priority: 0
# 指标组中的具体监控指标
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: hostname
type: 1
instance: true
- field: usage
type: 0
unit: '%'
- field: cores
type: 0
- field: waitTime
type: 0
unit: s
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
aliasFields:
- hostname
- core1
- core2
- usage
- allTime
- runningTime
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
calculates:
- hostname=hostname
- cores=core1+core2
- usage=usage
- waitTime=allTime-runningTime
# 监控采集使用协议 eg: sql, ssh, http, telnet, wmi, snmp, sdk
protocol: http
# 当protocol为http协议时具体的采集配置
http:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
# url请求接口路径
url: /metrics/cpu
# 请求方式 GET POST PUT DELETE PATCH
method: GET
# 是否启用ssl/tls,即是http还是https,默认false
ssl: false
# 请求头内容
headers:
apiVersion: v1
# 请求参数内容
params:
param1: param1
param2: param2
# 认证
authorization:
# 认证方式: Basic Auth, Digest Auth, Bearer Token
type: Basic Auth
basicAuthUsername: ^_^username^_^
basicAuthPassword: ^_^password^_^
# 响应数据解析方式: default-系统规则,jsonPath-jsonPath脚本,website-网站可用性指标监控
# todo xmlPath-xmlPath脚本,prometheus-Prometheus数据规则
parseType: jsonPath
parseScript: '$'
- name: memory
priority: 1
fields:
- field: hostname
type: 1
instance: true
- field: total
type: 0
unit: kb
- field: usage
type: 0
unit: '%'
- field: speed
type: 0
protocol: http
http:
host: ^_^host^_^
port: ^_^port^_^
url: /metrics/memory
method: GET
headers:
apiVersion: v1
params:
param1: param1
param2: param2
authorization:
type: Basic Auth
basicAuthUsername: ^_^username^_^
basicAuthPassword: ^_^password^_^
parseType: default
```
### 监控参数定义文件
> 监控参数定义文件用于定义 *需要的输入参数字段结构定义(前端页面根据结构渲染输入参数框)*。
样例自定义一个名称为example的自定义监控类型其使用HTTP协议采集指标数据。
文件名称: example.yml 位于 /define/param/example.yml
```yaml
# 监控应用类型名称(与文件名保持一致) eg: linux windows tomcat mysql aws...
app: example
# 强制固定必须参数 - 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
# 端口默认值
defaultValue: 80
# 参数输入框提示信息
placeholder: '请输入端口'
- 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时,前端用switch展示开关
type: boolean
required: false
- field: method
name: 请求方式
type: radio
required: true
# 当type为radio单选框,checkbox复选框时,option表示可选项值列表 {name1:value1,name2:value2}
options:
- label: GET请求
value: GET
- label: POST请求
value: POST
- label: PUT请求
value: PUT
- label: DELETE请求
value: DELETE
```

View File

@@ -0,0 +1,220 @@
---
id: extend-ssh
title: SSH协议自定义监控
sidebar_label: SSH协议自定义监控
---
> 从[自定义监控](extend-point)了解熟悉了怎么自定义类型指标协议等这里我们来详细介绍下用SSH协议自定义指标监控。
> SSH协议自定义监控可以让我们很方便的通过写sh命令脚本就能监控采集到我们想监控的Linux指标
### SSH协议采集流程
【**系统直连Linux**】->【**运行SHELL命令脚本语句**】->【**响应数据解析:oneRow, multiRow**】->【**指标数据提取**】
由流程可见我们自定义一个SSH协议的监控类型需要配置SSH请求参数配置获取哪些指标配置查询脚本语句。
### 数据解析方式
SHELL脚本查询回来的数据字段和我们需要的指标映射就能获取对应的指标数据目前映射解析方式有两种oneRow, multiRow能满足绝大部分指标需求。
#### **oneRow**
> 查询出一列数据, 通过查询返回结果集的字段值(一行一个值)与字段映射
例如:
需要查询Linux的指标 hostname-主机名称uptime-启动时间
主机名称原始查询命令:`hostname`
启动时间原始查询命令:`uptime | awk -F "," '{print $1}'`
则在hertzbeat对应的这两个指标的查询脚本为(用`;`将其连接到一起)
`hostname; uptime | awk -F "," '{print $1}'`
终端响应的数据为:
```
tombook
14:00:15 up 72 days
```
则最后采集到的指标数据一一映射为:
hostname值为 `tombook`
uptime值为 `14:00:15 up 72 days`
这里指标字段就能和响应数据一一映射为一行采集数据。
#### **multiRow**
> 查询多行数据, 通过查询返回结果集的列名称,和查询的指标字段映射
例如:
查询的Linux内存相关指标字段total-内存总量 used-已使用内存 free-空闲内存 buff-cache-缓存大小 available-可用内存
内存指标原始查询命令为:`free -m`, 控制台响应:
```shell
total used free shared buff/cache available
Mem: 7962 4065 333 1 3562 3593
Swap: 8191 33 8158
```
在heartbeat中multiRow格式解析需要响应数据列名称和指标值一一映射则对应的查询SHELL脚本为
`free -m | grep Mem | awk 'BEGIN{print "total used free buff_cache available"} {print $2,$3,$4,$6,$7}'`
控制台响应为:
```shell
total used free buff_cache available
7962 4066 331 3564 3592
```
这里指标字段就能和响应数据一一映射为采集数据。
### 自定义步骤
配置自定义监控类型需新增配置两个YML文件
1. 用监控类型命名的监控配置定义文件 - 例如example_linux.yml 需位于安装目录 /hertzbeat/define/app/ 下
2. 用监控类型命名的监控参数定义文件 - 例如example_linux.yml 需位于安装目录 /hertzbeat/define/param/ 下
3. 重启hertzbeat系统我们就适配好了一个新的自定义监控类型。
-------
下面详细介绍下这俩文件的配置用法,请注意看使用注释。
### 监控配置定义文件
> 监控配置定义文件用于定义 *监控类型的名称(国际化), 请求参数映射, 指标信息, 采集协议配置信息*等。
样例自定义一个名称为example_linux的自定义监控类型其使用SSH协议采集指标数据。
文件名称: example_linux.yml 位于 /define/app/example_linux.yml
```yaml
# 此监控类型所属类别service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
category: os
# 监控应用类型(与文件名保持一致) eg: linux windows tomcat mysql aws...
app: example_linux
name:
zh-CN: 模拟LINUX应用类型
en-US: LINUX EXAMPLE APP
# 参数映射map. 这些为输入参数变量,即可以用^_^host^_^的形式写到后面的配置中,系统自动变量值替换
# type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
# 强制固定必须参数 - host
configmap:
- key: host
type: 1
- key: port
type: 0
- key: username
type: 1
- key: password
type: 2
# 指标组列表
metrics:
# 第一个监控指标组 basic
# 注意:内置监控指标有 (responseTime - 响应时间)
- name: basic
# 指标组调度优先级(0-127)越小优先级越高,优先级低的指标组会等优先级高的指标组采集完成后才会被调度,相同优先级的指标组会并行调度采集
# 优先级为0的指标组为可用性指标组,即它会被首先调度,采集成功才会继续调度其它指标组,采集失败则中断调度
priority: 0
# 指标组中的具体监控指标
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: hostname
type: 1
instance: true
- field: version
type: 1
- field: uptime
type: 1
# 监控采集使用协议 eg: sql, ssh, http, telnet, wmi, snmp, sdk
protocol: ssh
# 当protocol为http协议时具体的采集配置
ssh:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
username: ^_^username^_^
password: ^_^password^_^
script: (uname -r ; hostname ; uptime | awk -F "," '{print $1}' | sed "s/ //g") | sed ":a;N;s/\n/^/g;ta" | awk -F '^' 'BEGIN{print "version hostname uptime"} {print $1, $2, $3}'
# 响应数据解析方式oneRow, multiRow
parseType: multiRow
- name: cpu
priority: 1
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: info
type: 1
- field: cores
type: 0
unit: 核数
- field: interrupt
type: 0
unit: 个数
- field: load
type: 1
- field: context_switch
type: 0
unit: 个数
# 监控采集使用协议 eg: sql, ssh, http, telnet, wmi, snmp, sdk
protocol: ssh
# 当protocol为http协议时具体的采集配置
ssh:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
username: ^_^username^_^
password: ^_^password^_^
script: "LANG=C lscpu | awk -F: '/Model name/ {print $2}';awk '/processor/{core++} END{print core}' /proc/cpuinfo;uptime | sed 's/,/ /g' | awk '{for(i=NF-2;i<=NF;i++)print $i }' | xargs;vmstat 1 1 | awk 'NR==3{print $11}';vmstat 1 1 | awk 'NR==3{print $12}'"
parseType: oneRow
- name: memory
priority: 2
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: total
type: 0
unit: Mb
- field: used
type: 0
unit: Mb
- field: free
type: 0
unit: Mb
- field: buff_cache
type: 0
unit: Mb
- field: available
type: 0
unit: Mb
# 监控采集使用协议 eg: sql, ssh, http, telnet, wmi, snmp, sdk
protocol: ssh
# 当protocol为http协议时具体的采集配置
ssh:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
username: ^_^username^_^
password: ^_^password^_^
script: free -m | grep Mem | awk 'BEGIN{print "total used free buff_cache available"} {print $2,$3,$4,$6,$7}'
parseType: multiRow
```
### 监控参数定义文件
> 监控参数定义文件用于定义 *需要的输入参数字段结构定义(前端页面根据结构渲染输入参数框)*。
样例自定义一个名称为example_linux的自定义监控类型其使用SSH协议采集指标数据。
文件名称: example_linux.yml 位于 /define/param/example_linux.yml
```yaml
app: example_linux
param:
- field: host
name: 主机Host
type: host
required: true
- field: port
name: 端口
type: number
range: '[0,65535]'
required: true
defaultValue: 22
placeholder: '请输入端口'
- field: username
name: 用户名
type: text
limit: 20
required: true
- field: password
name: 密码
type: password
required: true
```