我有内容
{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"__name__":"process_status","process_id":"process_fly1","instance":"server01","job":"new_job1"},"values":[[1516627862,"1"],[1516627922,"1"],[1516627982,"1"],[1516628042,"1"],[1516628102,"1"],[1516628162,"1"],[1516628222,"1"],[1516628282,"1"],[1516628342,"1"],[1516628402,"1"],[1516628462,"1"],[1516628522,"1"],[1516628582,"1"],[1516628642,"1"],[1516628702,"1"],[1516628762,"1"],[1516628822,"1"],[1516628882,"1"],[1516628942,"1"],[1516629002,"1"],[1516629062,"1"],[1516629122,"1"],[1516629182,"1"],[1516629242,"1"],[1516629302,"1"],[1516629362,"1"],[1516629422,"1"],[1516629482,"1"],[1516629542,"1"],[1516629602,"1"],[1516629662,"1"],[1516629722,"1"],[1516629782,"1"],[1516629842,"1"],[1516629902,"1"],[1516629962,"1"],[1516630022,"1"],[1516630082,"1"],[1516630142,"1"],[1516630202,"1"],[1516630262,"1"],[1516630322,"1"],[1516630382,"1"],[1516630442,"1"],[1516630502,"1"],[1516630562,"1"],[1516630622,"1"],[1516630682,"1"],[1516630742,"1"],[1516630802,"1"],[1516630862,"1"],[1516630922,"1"],[1516630982,"1"],[1516631042,"1"],[1516631102,"1"],[1516631162,"1"],[1516631222,"1"],[1516631282,"1"],[1516631342,"1"],[1516631402,"1"],[1516631462,"1"]]},{"metric":{"__name__":"process_status","process_id":"process_grow","instance":"server01","job":"new_job1"},"values":[[1516627862,"0"],[1516627922,"0"],[1516627982,"0"],[1516628042,"0"],[1516628102,"0"],[1516628162,"0"],[1516628222,"0"],[1516628282,"0"],[1516628342,"0"],[1516628402,"0"],[1516628462,"0"],[1516628522,"0"],[1516628582,"0"],[1516628642,"0"],[1516628702,"0"],[1516628762,"0"],[1516628822,"0"],[1516628882,"0"],[1516628942,"0"],[1516629002,"0"],[1516629062,"0"],[1516629122,"0"],[1516629182,"0"],[1516629242,"0"],[1516629302,"0"],[1516629362,"0"],[1516629422,"0"],[1516629482,"0"],[1516629542,"0"],[1516629602,"0"],[1516629662,"0"],[1516629722,"0"],[1516629782,"0"],[1516629842,"0"],[1516629902,"0"],[1516629962,"0"],[1516630022,"0"],[1516630082,"0"],[1516630142,"0"],[1516630202,"0"],[1516630262,"0"],[1516630322,"0"],[1516630382,"0"],[1516630442,"0"],[1516630502,"0"],[1516630562,"0"],[1516630622,"0"],[1516630682,"0"],[1516630742,"0"],[1516630802,"0"],[1516630862,"0"],[1516630922,"0"],[1516630982,"0"],[1516631042,"0"],[1516631102,"0"],[1516631162,"0"],[1516631222,"0"],[1516631282,"0"],[1516631342,"0"],[1516631402,"0"],[1516631462,"0"]]},
{"metric":{"__name__":"process_status","process_id":"process_fly2","instance":"server01","job":"new_job1"},"values":[[1516627862,"1"],[1516627922,"1"],[1516627982,"1"],[1516628042,"1"],[1516628102,"1"],[1516628162,"1"],[1516628222,"1"],[1516628282,"1"],[1516628342,"1"],[1516628402,"1"],[1516628462,"1"],[1516628522,"1"],[1516628582,"1"],[1516628642,"1"],[1516628702,"1"],[1516628762,"1"],[1516628822,"1"],[1516628882,"1"],[1516628942,"1"],[1516629002,"1"],[1516629062,"1"],[1516629122,"1"],[1516629182,"1"],[1516629242,"1"],[1516629302,"1"],[1516629362,"1"],[1516629422,"1"],[1516629482,"1"],[1516629542,"1"],[1516629602,"1"],[1516629662,"1"],[1516629722,"1"],[1516629782,"1"],[1516629842,"1"],[1516629902,"1"],[1516629962,"1"],[1516630022,"1"],[1516630082,"1"],[1516630142,"1"],[1516630202,"1"],[1516630262,"1"],[1516630322,"1"],[1516630382,"1"],[1516630442,"1"],[1516630502,"1"],[1516630562,"1"],[1516630622,"1"],[1516630682,"1"],[1516630742,"1"],[1516630802,"1"],[1516630862,"1"],[1516630922,"1"],[1516630982,"1"],[1516631042,"1"],[1516631102,"1"],[1516631162,"1"],[1516631222,"1"],[1516631282,"1"],[1516631342,"1"],[1516631402,"1"],[1516631462,"1"]]}]}}
我想获取值< 0.5和name process_id满足掩码 fly
http://server02/api/v1/query_range?query=count(process_status<0.5)&{process_id=~"*fly*"}&start=1516627862.0&end=1516631462.0&step=60
但结果并不好。 如何使REST API请求更好?
答案 0 :(得分:0)
使用普通URL有点令人困惑。尤其是未展开的&
。我建议您通过网络用户界面测试您的查询:http://server02/graph。
您的网址似乎要尝试count(process_status<0.5)&{process_id=~"*fly*"}
之类的内容,但由于网址编码实际上是count(process_status<0.5)
。
=~
匹配器使用正则表达式。因此,您必须撰写process_id=~".*fly.*"
而不是*fly*
。
如果我正确理解了您的问题,您的查询应如下所示:
process_status{process_id=~".*fly.*"} < 0.5
此外,文档应该非常明确:https://prometheus.io/docs/prometheus/latest/querying/basics/
答案 1 :(得分:0)
bool
Prometheus使用正则表达式而不是globs。要处理没有匹配系列的情况,您需要使用返回0/1的count
修饰符然后求和。如果没有时间序列匹配,使用IsChecked
将得到任何结果(与0不同)。