본문 바로가기

빅데이터

프로메테우스 지표 rate와 increase의 차이점

프로메테우스로 다음과 같은 지표들을 쌓을 때가 있습니다.

http_request_count_total{method="POST",router="/"}     10
http_request_count_total{method="POST",router="/"}     15
http_request_count_total{method="POST",router="/"}     20
http_request_count_total{method="POST",router="/"}     40
http_request_count_total{method="POST",router="/"}     45
http_request_count_total{method="POST",router="/"}     60

상기와 같은 지표는 http request때 마다 counter를 1씩 increase한 데이터 입니다. 해당 지표를 그래프로 그려 시간당 데이터 처리량을 나타낼 경우 크게 두가지 방식으로 나타낼 수 있습니다. 

 

- rate : 범위 시간당 초당 호출량
- increase : 범위 시간당 증가율

 

이 2개의 차이점은 하늘과 땅차이입니다. rate는 초당! 호출량을 특정 기간을 기준으로 측정하는 것입니다. 만약 1분동안 호출이 60번이 되었다면 1이 노출됩니다.

rate(http_request_count_total[1m])     1

당연하게도 1분동안 60번이 호출되었으므로 대략 1tps라는 것이 나온 것입니다.

 

tps를 원할때는 rate를 사용하면 되지만 실제 호출 횟수를 그래프로 그리고 나타내고 싶을때는 increase를 사용하면 됩니다. 1분동안 호출이 60번이 되었다면 이 경우 함수를 호출하면 60이 노출됩니다.

increase(http_request_count_total[1m])     60

increase 메서드로 호출된 값을 그라파나로 그리고 싶을때는 반드시 min time interval을 단위시간(여기서는 1m)으로 설정합니다. 그래야지만 정확한 데이터(min, max, avg)를 단위 시간을 기준으로 얻을 수 있기 때문입니다.

프로메테우스 공식 홈페이지 설명

Rate

rate(v range-vector) calculates the per-second average rate of increase of the time series in the range vector. Breaks in monotonicity (such as counter resets due to target restarts) are automatically adjusted for. Also, the calculation extrapolates to the ends of the time range, allowing for missed scrapes or imperfect alignment of scrape cycles with the range's time period. The following example expression returns the per-second rate of HTTP requests as measured over the last 5 minutes, per time series in the range vector:

rate(http_requests_total{job="api-server"}[5m])

rate should only be used with counters. It is best suited for alerting, and for graphing of slow-moving counters. Note that when combining rate() with an aggregation operator (e.g. sum()) or a function aggregating over time (any function ending in _over_time), always take a rate() first, then aggregate. Otherwise rate() cannot detect counter resets when your target restarts.

Increase

increase(v range-vector) calculates the increase in the time series in the range vector. Breaks in monotonicity (such as counter resets due to target restarts) are automatically adjusted for. The increase is extrapolated to cover the full time range as specified in the range vector selector, so that it is possible to get a non-integer result even if a counter increases only by integer increments. The following example expression returns the number of HTTP requests as measured over the last 5 minutes, per time series in the range vector:

increase(http_requests_total{job="api-server"}[5m])

increase should only be used with counters. It is syntactic sugar for rate(v) multiplied by the number of seconds under the specified time range window, and should be used primarily for human readability. Use rate in recording rules so that increases are tracked consistently on a per-second basis.

 

 

https://prometheus.io/docs/prometheus/latest/querying/functions

 

Query functions | Prometheus

An open-source monitoring system with a dimensional data model, flexible query language, efficient time series database and modern alerting approach.

prometheus.io

 

반응형