Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Log Explorer to Line chart using MQL

Hello!

I am VERY new to using GCP and thus using Monitoring.

I've seen the possibilities of using MQL to fetch logs and turn them into graphs. I've read the documentation already on https://cloud.google.com/monitoring/mql/examples?_ga=2.122959883.-1251670378.1673862564&hl=en but I haven't found a solution to my problem yet. Which is :

From these logs in Log Explorer :

totodede_0-1686689954245.png

That have a filter httpRequest.status = 403

I'd like to make a line chart using this component :

totodede_1-1686690002836.png

With an MQL query.

When asking our dear friend ChatGPT they give me this response which doesn't work as intended :

fetch gce_instance
| metric 'logging.googleapis.com/operation'
| filter httpRequest.status = 403
| group_by [TIMESTAMP_TRUNC(timestamp, HOUR)]
| count()

Error is couldn't find the 'logging.googleapis.com/operation' even though I replace the metric by something known to auto-complete.

I'd like my logs to be in a line chart given X axis is the time (grouped by hours preferably) and Y axis is the number of httpRequest that have status = 403 (which is a count if I understood correctly).

If there is any other way I can organize this information as another form of graph please let me know I'm opened for suggestions.

I hope I provided enough information and if I didn't I'll be sure to reply to any input.

Thank you so much in advance for your help!

0 2 1,643
2 REPLIES 2

Hello @totodede,

Welcome to Google Cloud Community!

You may try performing a simple query and create a chart using MQL. 
Don't hesitate to post back here with any questions. We are delighted to try and help. Thanks!

 

Hi @totodede 

You will first need to create a logs-based metric. You can use the same logging query you used in the Logs Explorer and create a counter logs based metric that counts the number of logs matching the query. There's a button in the Logs Explorer to create a metric as shown below:

 

summitt_3-1687890798782.png

You can then create a chart using this logs-based metric and put it in a Cloud Monitoring dashboard.

Hope that helps,

Summit