1 首先创建一个数据保留

curl -POST 'http://10.10.9.10:8086/query?pretty=true'  --data-urlencode "q=CREATE RETENTION POLICY \"2hours\" ON \"k8s\" DURATION 2h REPLICATION 1"

  # 查询数据保留

curl -GET 'http://10.10.9.10:8086/query?pretty=true'  --data-urlencode "q=SHOW RETENTION POLICIES ON k8s"


2 创建持续性数据处理,提供后续查询
   

curl -POST 'http://10.10.9.10:8086/query?pretty=true'  --data-urlencode "q=CREATE CONTINUOUS QUERY current_pods_query ON k8s BEGIN SELECT max(value) AS value INTO k8s.\"2hours\".current_pods FROM k8s.\"default\".uptime WHERE type = 'pod' GROUP BY time(5m), namespace_name, nodename, pod_name END" 

 # 查询持续性查询
 

 curl -GET 'http://10.10.9.10:8086/query?pretty=true'  --data-urlencode "q=SHOW CONTINUOUS QUERIES"

 #查询结果
   

curl -GET 'http://10.10.9.10:8086/query?pretty=true'  --data-urlencode "db=k8s" --data-urlencode "q=select * from k8s.\"2hours\".current_pods "

3 更改grafana面板podname变量的查询语句
  #查询存在两个小时的pod
 

curl -GET 'http://10.10.9.10:8086/query?pretty=true'  --data-urlencode "db=k8s" --data-urlencode "q=SHOW TAG VALUES FROM k8s.\"2hours\".current_pods WITH KEY = \"pod_name\" "

#执行完查询的时候可能没有数据,不要担心,需要等几分钟
#更改变量

SHOW TAG VALUES FROM k8s."2hours".current_pods WITH KEY = "pod_name" WHERE "namespace_name" =~ /$namespace$/

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐