Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Prometheus – Grafana – Monitoring] Look into rate and irate, min, max, average and latest over a specific time.

Posted on August 14, 2024December 3, 2024 By nim No Comments on [Prometheus – Grafana – Monitoring] Look into rate and irate, min, max, average and latest over a specific time.

Hiện tại mình gặp 1 tình huống:

Mặc dù deploymnet đó mình đã tắt rồi nhưng chart vẫn hiện thị kết quả.

Vậy tại sao chart kia vẫn hiển thị số?

và theo 1 kết luận thì chart đang lấy latest value and not according to follow the time range.

Mình chợt nghĩ ra sử dụng rate và irate

chúng ta sẽ cùng đi vào 1 ví dụ cụ thể:

Contents

Toggle
  • rate and irate in Prometheus.
    • Using rate:
    • Using irate:
  • Using the delta and increase functions with a gauge metric
    • Using delta:
    • Using increase:
    • Finding Minimum Value:
    • Finding Maximum Value:
  • Find the latest and average value:

rate and irate in Prometheus.

Hạy tưởng tượng bạn đang monitoring HTTP request đến 1 server web. Bạn có một counter metrics được gọi là http_requests_total

Data Points:

Giả sử bạn có data points cho http_requests_total:

TimestampValue
10:00:00100
10:01:00150
10:02:00200
10:03:00260
10:04:00300

Using rate:

Chúng ta hay cùng tính toán tỉnh lệ của HTTP request trên giây trong khoản thời gian 2 phút (120s)

rate(http_requests_total[3m])

Xem sét khoảng thời gian 3 phút cuối tại 10:04:00
– Values: 200 (10:02:00), 260 (10:03:00), 300 (10:04:00)
– Change:
+ From 200 to 300: 300−200=100
+ Time span: 120 seconds (2 minutes)

nó sẽ lấy giá trị đầu và giá trị cuối trong khoảng thời gian 3 phút.

Using irate:

irate(http_requests_total[3m])

Tính toán tỉ lệ tăng ngày lập tức giữa 2 data points cũ nhất trong khoảng thời gian 3 phút.

từ lý thuyết bên trên chúng ta sẽ xem sét khoảng thời gian 1 phút trước 10:04:00

Values: 260 (10:03:00), 300 (10:04:00)
Change:
+ From 260 to 300: 300−260=40
+ Time span: 60 seconds (1 minute)

Nó cung cấp tỉ lệ tăng giữa 2 data point gần nhất, phản ánh những thay đôi ngay lập tức hơn

Rate và irate chỉ sử dụng cho metrics count.

Using the delta and increase functions with a gauge metric

Giả sử chúng ta có data points sau đây: memory_usage_bytes:

TimestampValue (Bytes)
10:00:001,000,000,000
10:01:001,200,000,000
10:02:001,400,000,000
10:03:001,100,000,000
10:04:001,500,000,000

Using delta:

Tìm ra memory usage đã được thay đổi như thể nào trong khoảng thời gian 4 phút

delta(memory_usage_bytes[4m])

nó sẽ tính toán sự khách nhau giá trị đầu và giá trị cuối trong khoảng thời gian 4 phút:

Start value (10:00:00): 1,000,000,000 bytes
End value (10:04:00): 1,500,000,000 bytes

Using increase:

Nếu bạn muốn biết tổng cộng tăng bao nhiêu trong khoảng thời gian 4 phút.

increase(memory_usage_bytes[4m])

This function will sum up all positive changes:

  • From 10:00:00 to 10:01:00: 1,200,000,000−1,000,000,000=200,000,000 bytes
  • From 10:01:00 to 10:02:00: 1,400,000,000−1,200,000,000=200,000,000 bytes
  • From 10:02:00 to 10:03:00: 1,100,000,000−1,400,000,000=−300,000,000 bytes (ignored as it’s a decrease)
  • From 10:03:00 to 10:04:00: 1,500,000,000−1,100,000,000=400,000,000 bytes

The result will be:

  • increase=200,000,000+200,000,000+400,000,000=800,000,000 bytes

Vậy, có 1 tổng tăng trưởng là 800 MB in memory usage trong khoảng 4 phút đó, bỏ qua những khúc giảm.

Finding Minimum Value:

min_over_time(memory_usage_bytes[5m])

Nó trả về giá trị nhỏ nhất của memory_usage_bytes trong 5 phút vừa qua

Finding Maximum Value:

max_over_time(memory_usage_bytes[5m])

Nó trả về giá trị lớn nhất của memory_usage_bytes trong 5 phút vừa qua

Find the latest and average value:

last_over_time(memory_usage_bytes[5m])

Nó trả về giá trị gần nhất của memory_usage_bytes trong 5 phút vừa qua

avg_over_time(memory_usage_bytes[5m])

Nó trả về giá trị chung bình of memory_usage_bytes trong 5 phút vừa qua. nó lấy tất các data points trong khoảng thời gian đó. công chúng lại và chia số lượng data points

Kết luận lại mình đã lấy avg_over_time() để giải quyết vấn đề của mình.

Prometheus

Post navigation

Previous Post: [aws] AWS refund
Next Post: [Redis] Redis commands are very helpful

More Related Articles

[Node exporter] Install node_exporter on Linux by a script file! BareMetal
[Prometheus/Istio] Research about Recording Rules in Prometheus and reduce metrics of istio cluster. Isito-EnvoyFilter
[Grafana] Draw table visualization in Grafana Prometheus
[Prometheus/Grafana] Install Prometheus and Grafana on ubuntu. BareMetal
[Promethues] Install Prometheus Operator on Kubernetes. Prometheus
[Grafana/Prometheus] Design chart for bucket metrics to Grafana Grafana

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Laravel] Laravel Helpful June 26, 2025
  • [VScode] Hướng dẫn điều chỉnh font cho terminal June 20, 2025
  • [WordPress] Hướng dấn gửi mail trên WordPress thông qua gmail. June 15, 2025
  • [Bitbucket] Git Clone/Pull/Push with Bitbucket through API Token. June 12, 2025
  • [Teamcity] How to transfer the value from pipeline A to pipeline B June 9, 2025

Archives

  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.