google-cloud-logginggoogle-cloud-monitoring

creating monitor dashboard using cloud run service logs


I need assistance in validating the process of creating dashboard in GCP. I have one service running on cloud run. When an event triggers where we log the object in logger statement with message. In this message we have one field with value. We wanted to show the sum of the value of that field each time it get logged in gcp.

Ex:

{"testRecord":{"id":"815582a0f344179be1d","totalAmount":2.00,"totalvalue":0.50}}

I have created log based metrics. These Log-based metrics count the log entries that match a given filter.

Using the regex expression which extracts a value from the field that must contain exactly one regex group (), I can extract the value and then in monitoring dashboard, I can select the metric type as distribution which collects numeric data from log entries.

The issue with this is, logs are only retained till 30 days from creation and log metrcis does not fetches logs before creation, in this case the data will not be accurate.

Can someone please suggest me if we have any alternative way to create monitor dashboard.


Solution

  • To achieve the aggregation and visualization of the TotalAmount field value from the log messages in Google Cloud Platform (GCP), you can use Cloud Monitoring and create a custom metric to aggregate and display the sum of the TotalAmount field over time as per below steps :

    Below is the screenshot for reference :

    image

    image

    image

    You can see the dashboard output as below :

    image

    Refer to this Google Community solution for information.