Skip to main content
Version: v1.5.x

Time Expression

Introduction

HertzBeat supports using expressions to calculate relative time during monitoring collection, allowing for more flexible time definitions in monitoring templates.

Syntax

${FORMATTER [{ + | - }<DURATION> <TIME_UNIT>]}
  • FORMATTER: Determines the format of the expression's result
  • DURATION: Size of the time period, a positive integer
  • TIME_UNIT: Unit of the time period

Supported Formatting Types

Example outputs are based on the current time being 2022-04-24 02:40:00.123

NameDescriptionExample
@nowFormats as yyyy-MM-dd HH:mm:ss2022-04-24 02:40:00
@dateFormats as yyyy-MM-dd2022-04-24
@timestamp10Returns 10-digit timestamp1650768000
@timestampReturns 13-digit timestamp1650768000000
@timeFormats as HH:mm:ss02:40:00
@yearFormats as yyyy2022
@monthFormats as MM04
@dayFormats as dd24
@hourFormats as HH02
@minuteFormats as mm40
@millisecondFormats as SSS123
@secondFormats as ss00

Supported Time Units

NameDescription
yYear
MMonth
dDay
HHour
mMinute
sSecond
wWeek

Where to Use

  • Request parameters for HTTP protocol monitoring types

Usage Examples

  1. Simple expression
    • ${now} gets the current time and formats it as yyyy-MM-dd HH:mm:ss
    • ${time+1h} calculates the time one hour from now and formats it as HH:mm:ss
    • ${time+1h+15s+30s} calculates the time one hour, 15 minutes, and 30 seconds from now and formats it as HH:mm:ss
  2. Complex expression template (if the built-in formatter does not meet your needs, you can combine multiple expressions)
    • ${@year}年${@month}月${@day}日 returns the current date formatted as yyyy年MM月dd日