day_of_month() 函数是一个向量函数,用于提取时间戳向量中每个样本日期所在月份的天数。该函数返回一个向量,其中每个样本的值都是该样本时间戳所在月份的天数(1 到 31)。
day_of_month() 函数通常用于时间序列分析,特别是在需要基于月份中的某一天进行聚合、计算或触发警报时。
day_of_month() 函数的语法如下:
day_of_month(v instant-vector)
参数说明:
v instant-vector: 是你想要提取月份天数的瞬时向量。
假设你有一个记录 HTTP 请求次数的指标 prometheus_http_requests_total,使用 day_of_month(timestamp) 提取每个 http_requests_total 样本的时间戳所在月份的天数:
day_of_month(prometheus_http_requests_total)
如下图:
注意:day_of_month() 函数仅适用于具有时间戳的样本,并且返回的是样本时间戳所在月份的天数,而不是当前时间的天数。如果你想要获取当前时间的天数,你应该使用 Prometheus 服务器本身的当前时间,而不是样本的时间戳。