I am really new to GCP and creating metrics. We use Grafana to display the count of event logs with the help of "google_logging_metric" created.
My use case was Let's say we have a log
The Number is {variable}"
Possible values for variable is a 5 digit Number and there will be multiple occurrences of logs with each variable.
I am creating Metric through terraform as follows
resource "google_logging_metric" "" {
name = ""
project = var
filter = "resource.type=\"k8s_container\" resource.labels.container_name=\"\" jsonPayload.message=~\"(The Number is {something should be added here?})\""
metric_descriptor {
metric_kind = "DELTA"
value_type = "INT64"
display_name = ""
labels {
key = "event"
value_type = "STRING"
description = ""
}
}
label_extractors = {
event = "REGEXP_EXTRACT(jsonPayload.message, \"(The Number is {something should be added here?})\")"
}
}
What i like to do was to group the log occurrences like "The Number is XXXXX", "The Number is YYYYY", "The Number is ZZZZZ" on grafana. Can anyone suggest How i can achieve this? Do I have to modify the metric or something on grafana dashboard?
Cloud Logging supports regular expression so if the log entries you need to filter varies between numbers from 1 to 3, you can try something similar as below:
Here is the official documentation about Cloud Logging regex: https://cloud.google.com/blog/products/management-tools/cloud-logging-gets-regular-expression-support