Prometheus Range Functions
Prometheus provides several range functions that are used to specify time ranges for querying data. These functions help define the temporal scope of the query. Here are the main range functions in Prometheus:
1. time():
- This function returns the current server time as the timestamp. It is commonly used to refer to the current time in queries.
- Example usage:
time()
2. timestamp():
- This function returns the timestamp of a given point in time. It takes a date-time string as an argument and returns the corresponding timestamp.
- Example usage:
timestamp("2023-07-02T10:30:00Z")
3. offset():
- The offset() function shifts a time series by a given duration. It is useful for comparing data at different time intervals or for comparing data at the same time interval but at different points in time.
- Example usage:
offset(metric_name[2h])
4. start():
- This function returns the start time of a time range. It is typically used in combination with range functions to specify the beginning of a time interval.
- Example usage:
start()
5. end():
- The end() function returns the end time of a time range. It is often used in combination with range functions to specify the end of a time interval.
- Example usage:
end()
6. s():
- The s() function is used to specify a duration in seconds. It is used to define the length of a time range in terms of seconds.
- Example usage:
metric_name[s]
7. m():
- This function specifies a duration in minutes. It is used to define the length of a time range in terms of minutes.
- Example usage:
metric_name[m]
8. h():
- The h() function defines a duration in hours. It is used to specify the length of a time range in terms of hours.
- Example usage:
metric_name[h]
9. d():
- This function specifies a duration in days. It is used to define the length of a time range in terms of days.
- Example usage:
metric_name[d]
These range functions help you define the time window for querying data in Prometheus. By combining these functions with other PromQL functions, you can effectively analyze and extract insights from time series metrics.