2

I have an application that I'm setting up logs-based monitoring for. The application will log whenever it completes a certain task. I want to ensure that the application completes this at least once every 6 hours.

I have tried to replicate this rule by configuring monitoring to fire an alert when the metric stays below 1 for the given amount of time.

Unfortunately, when the logs-based metric doesn't receive any logs, it appears to act that there is "no data" instead of a value of 0.

Is it possible to treat segments when no logs are received as a 0 so that the alert will fire?

Screenshot of my metric graph: enter image description here

Screenshot of alert definition: enter image description here You can see that we receive a log for one time frame, but right afterwards the line disappears and an alert isn't triggered.

pgoggijr
  • 414
  • 1
  • 3
  • 15
  • Why not create a 2 logs alert metric instead, so there will always be a data received, then create [labels](https://cloud.google.com/logging/docs/logs-based-metrics/labels) for each? – Alex G Feb 11 '21 at 09:43

1 Answers1

1

Try using absent_for and MQL based Alert.

The absent_for table operation generates a table with two value columns, active and signal. The active column is true when there is data missing from the table input and false otherwise. This is useful for creating a condition query to be used to alert on the absence of inputs.

Example:

 fetch  gce_instance :: compute.googleapis.com/instance/cpu/usage_time
  | absent_for 8h
c69
  • 19,951
  • 7
  • 52
  • 82
  • fetch path has be your own logging metric, of course. But as it is censured on the screenshot, i put gce cpu usage_time as an example. – c69 Feb 12 '21 at 16:04
  • 1
    This is exactly what I needed, thank you! I didn't realize that MQL was capable of more than what is exposed on the UI. – pgoggijr Feb 24 '21 at 14:44