Hello, this is id:heleeen from the Mackerel SRE team.
We've just released v0.0.7 of the Terraform Mackerel Provider, it now supports getting a list of names of service metrics from Mackerel. This allows you to more easily manage your monitoring settings.
mackerelio-labs/mackerel | Terraform Registry
This feature was contributed by one of our Mackerel Ambassadors, @fujiwara. Thank you so much @fujiwara!
How to use mackerel_service_metric_names
The new mackerel_service_metric_names
is a data source to get a name list of service metrics mentioned at the beginning of this article. If you specify only name
, you will get a name list of service metrics of the service.
data "mackerel_service_metric_names" "sample" { name = "sample" }
If you specify prefix
as well, you can filter by forward matching.
data "mackerel_service_metric_names" "sample" { name = "sample" prefix = "service-metric-name.prefix" }
This allows you to get a name list of service metric, which makes it easier to configure monitoring settings to multiple service metrics. Here is an example of the configuration.
data "mackerel_service_metric_names" "sample" { name = "sample" prefix = "service-metric-name.prefix" } resource "mackerel_monitor" "service_metrics" { for_each = data.mackerel_service_metric_names.sample.metric_names name = format("%s is low", each.key) service_metric { service = "sample" metric = each.value operator = "<" duration = 1 warning = 5 critical = 10 } }
This is the result when you runterraform plan
with it.
An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # mackerel_monitor.service_metrics["service-metric-name.prefix.one"] will be created + resource "mackerel_monitor" "service_metrics" { + id = (known after apply) + name = "service-metric-name.prefix.one is low" + notification_interval = 0 + service_metric { + critical = 10 + duration = 1 + max_check_attempts = 1 + metric = "service-metric-name.prefix.one" + operator = "<" + service = "sample" + warning = 5 } } # mackerel_monitor.service_metrics["service-metric-name.prefix.the-other"] will be created + resource "mackerel_monitor" "service_metrics" { + id = (known after apply) + name = "service-metric-name.prefix.the-other is low" + notification_interval = 0 + service_metric { + critical = 10 + duration = 1 + max_check_attempts = 1 + metric = "service-metric-name.prefix.the-other" + operator = "<" + service = "sample" + warning = 5 } }
Monitoring for service metrics can be configured simpler.
Added support for MACKEREL_APIKEY
.
Previously, only MACKEREL_API_KEY
was supported for specifying API keys via environment variables, but now MACKEREL_APIKEY
used by mkr and mackerel-container-agent is also be supported.
Please note that MACKEREL_APIKEY
takes precedence over MACKEREL_API_KEY
. If you have set API keys for different organizations in MACKEREL_API_KEY
and MACKEREL_APIKEY
, the execution destination will be changed.
For more information about the Terraform Mackerel Provider, please refer to the Documentation.
If you have question
You can join the Mackerel User Group with this URL and ask your question.
https://mackerel-ug-slackin.herokuapp.com/
Please take advantage of it!
We hope you find the new features of the Terraform Mackerel Provider useful for your IaC monitoring and management.