@pitrix/cloudsat-convertor
v1.0.5
Published
cloudsat 监控接口数据转换工具
Downloads
98
Keywords
Readme
data-convertor2.0
cloudsat 监控接口数据转换工具
安装
npm install @QCFE/data-convertor2.0
用法
import Converter from '@QCFE/data-convertor2.0';
const { result, tags, searchMonitorData } = new Converter(resdata, opts).toLineChart(true);
参数说明
resdata
{
"data": [
{
"monitor_data": [{...}],
"resource_id": "lbl-g7i7737y",
"metric_name": "b_rsp_3xx",
"metric_cn_name": "后端 HTTP 3xx 响应数",
"metric_unit": "%",
"create_time": "2022-08-29T16:36:43.061534Z",
"user_id": "usr-rrPKHDpJ",
"description": "后端 HTTP 3xx 响应数",
"step": 10,
"tags": "node_idx=0,eip_id=eip-3mgnl28l"
}
],
"ret_code": 0,
"total_count": 56
}
opts
|参数项|类型|含义|示例|
|---|---|---|---|
|namespace|string|命名空间|可取值:'common'|'namespace-cloudsat-instance'|'namespace-cloudsat-vol'|'namespace-cloudsat-eip'|'namespace-cloudsat-loadbalancer'| 'namespace-cloudsat-loadbalancer-backend'|'namespace-cloudsat-loadbalancer-listener'|'namespace-cloudsat-nat'|
|dateFormat(可选)|string|x轴的时间格式,moment支持的dateFormat格式|'YYYY-MM-DD HH:mm:ss'|
|precision(可选)|number|数据转换后的小数位,默认值:2|-|
|labelByTag(可选)|string|指定tag name成为lenged label,lb, 集群专用|-|
|seriesByTag(可选)|string|指定tag name划分series|-|
|metrics(可选)|Partial<Record<MetricsType, Record<'label', string>>>|详细的mertics label名称配置|{"rx": {"label": "带宽-进"},"tx": {"label": "带宽-出"}
|
|byteTrasnform(可选)|boolean|单位byte是否转化为bit|true|
|lang(可选)|'zh-cn'|'cn'|语言|'zh-cn'|
|showMaxMinMetrics(可选)|string[]|是否展示指标的最大值和最小值,默认不展示|[]|
|legendTruncateLength(可选)|number|legend label展示的宽度,如果超出会默认按...展示|150|
|dimension(可选)|DimensionType|选择展示的数据是平均值,最大值还是最小值,showMaxMinMetrics 没有指定当前meter时生效|'avgValue'
|
实例方法
|方法名|含义|参数| |---|---|---| |toLineChart|返回echart折线图格式的数据|true(默认):同系列不同指标转成相同的单位false:同系统不同值班转换成各自适合的单位| |getData|返回基本的key,value格式数据|true(默认):同系列不同指标转成相同的单位false:同系统不同值班转换成各自适合的单位|
返回值
result(toLineChart)
[
{
"key": "traffic",
{
"key": "traffic",
"value": [
{
"echartData": {
"xAxis": {
"data": [
"2022-08-28 08:20",
"2022-08-28 10:00"
]
},
"series": [
{
"name": "outbound",
"type": "line",
"data": [
{
"value": 400,
"name": "2022-08-28 08:20:00"
},
{
"value": 0,
"name": "2022-08-28 10:00:00"
}
]
},
{
"name": "inbound",
"type": "line",
"data": [
{
"value": 800,
"name": "2022-08-28 08:20:00"
},
{
"value": 0,
"name": "2022-08-28 10:00:00"
},
]
}
],
"legend": {
"data": [
"inbound",
"outbound"
]
}
},
"attrs": [
{
"label": "outbound",
"unit": "bps",
"metric_name": "rx",
"meter_type": "traffic",
"tags": "node_idx=0|eip_id=eip-3mgnl28l",
"step": 6000
},
{
"label": "inbound",
"unit": "bps",
"metric_name": "tx",
"meter_type": "traffic",
"tags": "node_idx=0|eip_id=eip-3mgnl28l",
"step": 6000
}
],
"tags": "node_idx=0|eip_id=eip-3mgnl28l"
}
]
}
}
]
result(getData)
[
{
"key": "traffic",
"value": [
{
"data": [
{
"value": 400,
"time": "2022-08-28 08:20"
},
{
"value": 0,
"time": "2022-08-28 10:00"
}
],
"label": "inbound",
"unit": "bps",
"metric_name": "rx",
"meter_type": "traffic",
"tags": "node_idx=0|eip_id=eip-3mgnl28l",
"step": 6000
},
{
"data": [
{
"value": 800,
"time": "2022-08-28 08:20"
},
{
"value": 0,
"time": "2022-08-28 10:00"
}
],
"label": "outbound",
"unit": "bps",
"metric_name": "tx",
"meter_type": "traffic",
"tags": "node_idx=0|eip_id=eip-3mgnl28l",
"step": 6000
}
]
}
]
tags
"tags": {
"node_idx": [
"0",
"1"
],
"eip_id": [
"eip-3mgnl28l",
"eip-n1ldbmpn"
]
}
searchMonitorData
const monitor = searchMonitorData({key: 'cpu', searchWords: ['node_idx=0']});
|参数|类型|含义|示例| |---|---|---|---| |key|string|metric key|'cpu', 'traffic'...| |searchWords|string[]|查询的关键字,根据 tags 模糊匹配|'node_idx=0'|