Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter Google Cloud Logs to logs at a certain hour of the day

I'd like to write a query that filters logs to only a particular hour of the day. This should retrieve logs at the same hour every day. For example, lets say the hour is 4pm / 16:00. It should retrieve logs with timestamp values:

  • 2023-04-20T16:00:00Z
  • 2023-04-20T16:12:34Z
  • 2023-04-21T16:00:00Z
  • 3004-01-01T16:00:00Z

I've tried using regex-based matching, but get an error "Field is of incorrect type. Regular expression matches can only be performed against string-compatible fields.":

timestamp=~"\d\d\d\d-\d\d-\d\dT16:\d\d:\d\d(\.\d+)?Z"

I've also tried accessing properties on this object, but that results in the error "Field 'timestamp' cannot have members.":

timestamp.hour=16

Is there some other way to filter logs by hour of day?

like image 827
domdomegg Avatar asked Oct 15 '25 08:10

domdomegg


1 Answers

You can set specific limits on the date and time of log entries to show.

the preview displays exactly the log entries in the indicated 60-minute period and you won't be able to scroll outside of that date range:

timestamp >= "2023-01-18T16:00:00Z"
timestamp <= "2023-01-18T16:59:59Z"

Sample Filter for January 18 16:00:

resource.type="bigquery_resource"
protoPayload.serviceData.jobCompletedEvent.job.jobStatistics.totalBilledBytes>"0"
timestamp >= "2023-01-18T16:00:00Z"
timestamp <= "2023-01-18T216:59:59Z"
like image 92
Siegfred V. Avatar answered Oct 18 '25 13:10

Siegfred V.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!