通用数据指标查询系统
1. 性能指标-通用查询
由于性能数据指标,经常要做多维度多指标交叉查询,所以提供一个指标查询方式,该方式采用JSON语言方式进行描述如下方式所示。
示例
一个指标趋势图的示例:
{
"timePeriod": 180,
"endTime":"2020-02-19 23:10"
"datasource": "APP_BASE_DATA",
"metrics": [
"loadDuration",
"viewDuration",
"slowLoadPercent",
"throughput"
],
"dimensions": [
"timeStr"
],
"orderByExprs": "slowLoadPercent desc",
"havingExprs": "viewDuration>10",
"render":"csv",
"top": {
"metric": "loadDuration",
"direction": "desc",
"dimensions": [
"mobileAppId"
],
"limit": 5
}
}
属性说明
property | description | 是否必选 |
---|---|---|
timePeriod | 开始时间-结束时间 间隔分钟数 | yes |
endTime | 截止时间,格式YYYY-MM-DD hh:mm,不指定为当前时间 | no |
datasource | 指标数据源 | yes |
metrics | 指标项 | yes |
filters | 过滤条件,只支持filter1 and filter2 | yes |
dimensions | 分组维度 | no |
orderByExprs | 排序表达式,必须为metric中的项 | no |
havingExprs | 分组过滤表达式,意义参考sql having,字段必须为metric | no |
render | 渲染器,支持list,csv,chart | no |
top | 二次查询,意为,先基于top进行查询,然后将返回值in,可以理解为in 子查询,常用在报表的topN趋势图中 | no |
DSL->SQL
相当于转换为SQL的示例,非标准SQL模式:
SELECT
[dimensions],
[metric]
FROM
[datasource]
WHERE
[time]<=[endtime] AND [time]>[endTime-timePeriod] AND [filters] AND [top.dimensions] IN (topQuery)
GROUP BY [dimensions]
HAVING [havingExprs]
ORDER BY [orderByExprs]
渲染器
渲染模型,目前支持以下:
- list
- csv
- chart
- object
list
简化的json格式:
[
{
"requestCount": "879",
"uriId": "1",
"requestType": "2",
"trafficConsumption": "3",
"responseTime": "3172",
"networkErrorCount": "83",
"requestTypeName": "CDN-自身服务",
"slowCount": "170",
"httpErrorRate": "8.3",
"networkErrorRate": "9.44",
"networkSpeed": "1",
"uriName": "/user",
"throughput": "14.65",
"httpErrorCount": "73"
}
]
csv
csv 表格格式:
timeStr,视图加载毫秒,慢加载占比%,慢展现占比%,视图展现毫秒
2019-4-23 8:00:00,1525,0,0,2430
2019-4-26 8:00:00,987,0,0,2460
2019-4-28 8:00:00,978,0,0,2521
2019-4-30 8:00:00,286,0,0,286
2019-5-5 8:00:00,835,0,0,892
2019-5-6 8:00:00,517,0,0,685
2019-5-10 8:00:00,111,0,0,292
2019-5-13 8:00:00,80,0,0,216
2019-5-14 8:00:00,589,0,0,652
object
和list不同的模式为,会将指标的单位和格式化字符串输出:
[
{
"loadDuration": {
"format": "987",
"label": "视图加载",
"unit": "毫秒",
"value": 987
},
"slowLoadPercent": {
"format": "0",
"label": "慢加载占比",
"unit": "%",
"value": 0
},
"timeStr": 1556236800000,
"throughput": {
"format": "0",
"label": "慢展现占比",
"unit": "%",
"value": 0
},
"viewDuration": {
"format": "2460",
"label": "视图展现",
"unit": "毫秒",
"value": 2460
}
}
]
chart
hightchart 格式的数据样式:
{
"series": [
{
"data": [
{
"x": 1556236800000,
"y": 987,
"tooltip": {
"data": [
{
"unit": "毫秒",
"title": "视图加载",
"value": 987
},
{
"unit": "%",
"title": "慢加载占比",
"value": 0
},
{
"unit": "%",
"title": "慢展现占比",
"value": 0
},
{
"unit": "毫秒",
"title": "视图展现",
"value": 2460
}
],
"title": "04-26 08:00--04-27 08:00"
}
}
],
"name": "视图加载",
"type": "line",
"yAxis": 0,
"zIndex": 1
}
],
"yAxis": [
{
"i18n": "app.unit.ms",
"opposite": false,
"tickUnit": "毫秒"
},
{
"i18n": "app.unit.percent",
"opposite": true,
"tickUnit": "%"
}
]
}
查询示例
时间趋势图
{
"timePeriod": 43200,
"datasource": "APP_BASE_DATA",
"metrics": [
"loadDuration",
"viewDuration",
"slowLoadPercent",
"throughput"
],
"dimensions": [
"timeStr"
],
"havingExprs": "viewDuration>10"
}
TOP5 时间趋势图
{
"timePeriod": 43200,
"datasource": "APP_BASE_DATA",
"filters": [
{
"name": "regionId",
"value": [4811,4812,4813,4814,4815],
"operator": "IN"
}
],
"metrics": [
"loadDuration",
"viewDuration",
"slowLoadPercent"
],
"dimensions": ["timeStr"]
}
TOP10 按慢加载率降序平均耗时>10
{
"timePeriod": 43200,
"datasource": "APP_BASE_DATA",
"metrics": [
"loadDuration",
"viewDuration",
"slowLoadPercent",
"throughput"
],
"dimensions": [
"mobileAppId"
],
"orderByExprs": "slowLoadPercent desc",
"havingExprs": "viewDuration>10",
"limit":10
}
Endpoint
Method: POST
Type: RAW
URL: {{host}}/adhoc/query
Headers
Key | Value |
---|---|
Accept | application/json, text/plain, / |
Content-Type | application/json |
Body
{
"timePeriod": {{timePeriod}},
"endTime": {{endTime}},
"datasource": "APP_NETWORK_DATA",
"metrics": [
"responseTime",
"successCount"
],
"dimensions": [
"timeStr",
"hostId"
],
"filters": [
{
"name": "mobileAppId",
"value": [
{{mobileAppId}}
],
"operator": "IN"
},
{
"name": "hostId",
"value": [
0
],
"operator": "!="
}
],
"top": {
"metric": "throughput",
"direction": "desc",
"dimensions": [
"hostId"
],
"limit": 5
},
"limit": -1,
"render": "object"
}