PromQL +チートシートの紹介

PromQLクエリのチートシートをダウンロードする





魅力的なプロメテウスの世界への旅を始めたばかりの場合、PromQLの使用を開始するのは難しい場合があります。このガイドは、それがどのように機能するかを理解するのに役立ちます。この記事には、始めるための興味深く役立つヒントが含まれています。





Prometheusはデータを時系列データモデルとして保存するため、PromQLクエリは従来のSQLとは根本的に異なります。Prometheusでデータを操作する方法を理解することは、効率的なクエリを作成する方法を学ぶための鍵です。





PromQLリクエストのチートシートダウンロードすることを忘れないでください





時系列データベースのしくみ

時系列は、タイムスタンプに関連付けられた値のストリームです。





各時系列は、メトリック名とラベルで識別できます。次に例を示します。





mongodb_up{}
      
      



または





kube_node_labels{cluster="aws-01", label_kubernetes_io_role="master"}
      
      



上記の例では、メトリック名(kube_node_labels



)とラベル(cluster



およびlabel_kubernetes_io_role



)があります。実際、メトリックはラベルでもあります。上記のクエリは次のように記述できます。





{__name__ = "kube_node_labels", cluster="aws-01", label_kubernetes_io_role="master"}

      
      



Prometheusには、次の4種類のメトリックがあります。





  • Gauges () — , . , mongodb_up



    , exporter MongoDB.





  • Counters () _total



    . , http_requests_total



    .





  • Histogram () — , , .





  • Summary ()  , .





PromQL

PromQL , , . http_requests_total



.





, / api 10.2.0.4. host



path



:





http_requests_total{host="10.2.0.4", path="/api"}
      
      



:





name





host





path





status_code





value





http_requests_total







10.2.0.4







/api







200







98







http_requests_total







10.2.0.4







/api







503







20







http_requests_total







10.2.0.4







/api







401







1







. http_requests_total



, , 98 .





 instant vector, . , Prometheus . , .





, instant vector (, ).





offset



(), :





http_requests_total{host="10.2.0.4", path="/api", status_code="200"} offset 1d
      
      



, :





http_requests_total{host="10.2.0.4", path="/api"}[10m]
      
      



:





name





host





path





status_code





value





http_requests_total







10.2.0.4







/api







200







641309@1614690905.515







641314@1614690965.515







641319@1614691025.502







http_requests_total







10.2.0.5







/api







200







641319@1614690936.628







641324@1614690996.628







641329@1614691056.628







http_requests_total







10.2.0.2







/api







401







368736@1614690901.371







368737@1614690961.372







368738@1614691021.372







, , .





range vector — .





PromQL

, PromQL . , ?





, node_cpu_cores



cluster



. , , , :





sum by (cluster) (node_cpu_cores)
      
      



:





cluster





value





foo





100





bar





50





, 100



cluster_foo



50



cluster_bar



.





, PromQL . , node_memory_MemFree_bytes



, , :





node_memory_MemFree_bytes / (1024 * 1024)
      
      



, node_memory_MemTotal_bytes



, , :





(node_memory_MemFree_bytes / node_memory_MemTotal_bytes) * 100
      
      



, 5% :





(node_memory_MemFree_bytes / node_memory_MemTotal_bytes) * 100 < 5
      
      



PromQL

PromQL , . , topk



, , ( ):





topk(2, (node_memory_MemFree_bytes / node_memory_MemTotal_bytes) * 100)
      
      



Prometheus , . pred_linear



, .





, , 24 . pred_linear



node_filesystem_free_bytes



, . 24 :





predict_linear(node_filesystem_free_bytes[1w], 3600 * 24) / (1024 * 1024 * 1024) < 100
      
      



Prometheus rate



. , . , .





, , , 10 . http_requests_total



, :





http_requests_total[10m]
      
      



name





host





path





status_code





value





http_requests_total







10.2.0.4







/api







200







100@1614690905.515







300@1614690965.515







50@1614691025.502







300 50, . rate



. , , :





name





host





path





status_code





value





http_requests_total







10.2.0.4







/api







200







100@1614690905.515







300@1614690965.515







350@1614691025.502







rate(http_requests_total[10m])
      
      



name





host





path





status_code





value





http_requests_total







10.2.0.4







/api







200







0.83







10 0,83 . :





rate(http_requests_total[10m]) = 0
      
      



?

, Prometheus , PromQL .





Cheatsheet PromQL, ​​ PromQL. Cheatsheet Prometheus playground.








All Articles