I have 3 metrics created in my GCP 1) success request count 2) redirected request count and 3) failed request count. All the 3 metrics are created from log-based metric on Kubernetes log.
Here's basically a Terraform resource definition of one metric "Success requests.
resource "google_logging_metric" "success_requests" {
filter = <<-EOT
resource.type="k8s_container"
jsonPayload.message:"Request success"
EOT
name = "success_requests"
project = var.gcp_project_id
metric_descriptor {
metric_kind = "DELTA"
unit = "1"
value_type = "INT64"
}
}
The other 2 basically just filter jsonPayload.message
with Request redirected
and Request failed
.
I want to create a dashboard that shows the success ratio with this formula
success_rate = success_requests / (success_requests + redirected_requests + failed_requests)
I am successful creating a dashboard that shows the three metrics using below MQL.
k8s_container | {
t_0:
metric logging.googleapis.com/user/success_requests;
t_1:
metric logging.googleapis.com/user/redirected_requests;
t_2:
metric logging.googleapis.com/user/failed_requests
} | union
But how do I create a dashboard that display the success rate with formula as mentioned before?
To perform some arithmetic operations using metrics, you need to work with the time series using Arithmetic Computation
After you summarize the three time series you can use div function.
The following query uses time_shift, join, and div to compute the ratio of the mean utilization in each zone between now and one week ago.
You can review more examples of queries using MQL in this Link.
You can review more of Functions implementing the arithmetic operators in MQL in this link.