本文主要是介绍grafana接入OpenTSDB设置大盘语法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
- 1、filter过滤语法
- 1.1 精准匹配
- 1.2 正则匹配
- 1.3 通配符匹配
- 完整示例
- 1、 展示应用app的CPU利用率监控
- 2)展示应用app的在线核数
1、filter过滤语法
1.1 精准匹配
-
literal_or : tagv的过滤规则: 精确匹配多项迭代值,多项迭代值以’|'分隔,大小写敏感
-
iliteral_or: tagv的过滤规则: 精确匹配多项迭代值,多项迭代值以’|'分隔,忽略大小写
1.2 正则匹配
- regexp: tagv的过滤规则: 正则表达式匹配
- OpenTSDB的正则表达式语法可能与其他数据库不同
1)匹配出以 XX开头
例如,要过滤出字符串以"ab_123"开头的数据,如下:
{"type": "regexp","tagk": "<标签键>","filter": "^(str_pre)","groupBy": false
}
{"type": "regexp","tagk": "app_id","filter": "^(ab_123)","groupBy": false
}
<标签键>是过滤的标签键,正则表达式,^(ab_123)使用了负向前瞻断言(ab_123),表示以"ab_123"开头的字符串。
- 匹配出 以XX开头 或以YY开头
例如,要过滤出字符串以"ab_123"开头或以"ab_666"的数据,如下:
{"type": "regexp","tagk": "<标签键>","filter": "^(str_pre)","groupBy": false
}
{"type": "regexp","tagk": "app_id","filter": "^(ab_123|ab_666)","groupBy": false
}
<标签键>是过滤的标签键,正则表达式,^(ab_123|ab_666)使用了括号和管道符合,表示以"ab_123"或"ab_666"开头的字符串
3)匹配出 不以 XX开头
例如,要过滤出字符串不以"ab_123"或"ab_666"开头的数据,如下:
{"type": "regexp","tagk": "<标签键>","filter": "^(?!str_pre)","groupBy": false
}
{"type": "regexp","tagk": "app_id","filter": "^(?!ab_123|ab_666)","groupBy": false
}
<标签键>是过滤的标签键,正则表达式,^(?!ab_123|ab_666)使用了负向前瞻断言(?!ab_123|ab_666),表示不以"ab_123"或""ab_666"开头的字符串。
1.3 通配符匹配
- wildcard: tagv的过滤规则: 通配符匹配,大小写敏感
- iwildcard: tagv的过滤规则: 通配符匹配,忽略大小写
- not_literal_or: tagv的过滤规则: 通配符取非匹配,大小写敏感
- not_iliteral_or: tagv的过滤规则: 通配符取非匹配,忽略大小写
完整示例
1、 展示应用app的CPU利用率监控
$app_id 为变量,可以写静态,也可以动态
{"time": {"aggregator": "sum","granularity": "20s"},"filters": [{"tags": [{"type": "iliteral_or","tagk": "app_id","filter": "$app_id","groupBy": false},{"type": "iliteral_or","tagk": "priority","filter": "Product","groupBy": false}],"id": "app_info_i"}],"metrics": [{"id": "app_used","metric": "docker.cpu.used","filter": "app_info_i"},{"id": "app_quota","metric": "docker.cpu.quota","filter": "app_info_i"}],"expressions": [{"id": "app_cpu_rate","expr": "(app_used/app_quota)*100"}],"outputs": [{"id": "app_cpu_rate","alias": "XXXCPU利用率"}]
}
2)展示应用app的在线核数
{"time": {"aggregator": "sum","granularity": "1m"},"limit": "avg:top:500","filters": [{"tags": [{"type": "iliteral_or","tagk": "app_id","filter": "$app_id","groupBy": false},{"type": "iliteral_or","tagk": "priority","filter": "Product","groupBy": false}],"id": "app_info_i"}],"metrics": [{"id": "app_quota","metric": "docker.cpu.quota","filter": "app_info_i"}],"expressions": [{"id": "quota_e","expr": "app_quota/100"}],"outputs": [{"id": "quota_e","alias": "cpu(core)"}]
}
这篇关于grafana接入OpenTSDB设置大盘语法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!