title: How to create an alert in Prometheus with time units? Like "average response time surpasses 5 seconds in the last 2 minutes"
body: <pre class="lang-yaml prettyprint-override"><code>  - name: app
      rules:
        - alert: ServerHighLatency
          expr: sum by(applicationName) (rate(http_server_requests_seconds_sum{status!~"4..|5.."}[1m]))/sum by(applicationName) (rate(http_server_requests_seconds_count{status!~"4..|5.."}[1m])) &gt;= 5s
          for: 5s
          labels:
            severity: critical
          annotations:
            summary: "{{ $labels.applicationName }} is responding with high latency(5s+)"
            description: "*Host*: {{ $labels.node }}\n*Datacenter*: {{ $labels.datacenter }}\n*Value*: {{ humanize $value }}\n"
  </code></pre>
  
  <p>But I got parsing error around the final <code>s</code> in the expression, so I guess it is not allowed. When I remove <code>s</code> it works, but is never triggered. I cannot find any examples of alerts to examine the average response time within a range, but only comparison by value, like "some percentile > 0.8", but not with time units. Does it make sense? </p>
  
  <p>Side note: I cannot get <code>{{ $labels.datacenter }}</code> and <code>{{ $labels.node }}</code> working, but <code>{{ $labels.applicationName }}</code> is working, why? Where can I find some good examples and documentations of alerts syntax in Prometheus?</p>