iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📈

maprobe: A Synthetic Monitoring Agent Integrated with Mackerel - fujiwara-ware 2024 Day 18

に公開

This article is for day 18 of fujiwara-ware advent calendar 2024.

What is maprobe?

https://github.com/fujiwara/maprobe

maprobe is a synthetic monitoring agent that integrates with Mackerel.

https://mackerel.io/ja/

It retrieves host information registered in Mackerel by service or role, and performs synthetic monitoring via ping, TCP, or HTTP for each host, or executes external commands to collect metrics. The collected metrics are sent as Mackerel custom metrics.

Why I made it

Mackerel's monitoring is a "Push" type, where each host sends metrics to the Mackerel server. Therefore, a host being down is detected by the fact that "information has not been sent to the server for a certain period of time."

However, as a limitation of this architecture, it inevitably takes time to detect that a host has gone down and the data stream has been interrupted. I wanted a way to make this faster (back in 2018).

Also, when cloud components (such as Amazon RDS or ElastiCache Redis) are registered as Mackerel hosts via AWS integration, you often want to collect metrics using plugins (such as mackerel-plugin-mysql or mackerel-plugin-redis) for those hosts. However, even though these components are registered as hosts, you cannot run mackerel-agent on them, so there is no place to execute the plugins.

So, I developed maprobe as an agent that performs the following:

  • Retrieves host information registered in Mackerel
  • Performs synthetic monitoring against those hosts and collects metrics
  • Sends those metrics to Mackerel

Basically, I envision placing one instance inside a service's VPC to collect monitoring metrics for hosts within that VPC.

Please refer to the documentation and reference materials for usage instructions.

Usage Example

By preparing a configuration file like the following and running maprobe, it will perform the following monitoring for each host with the service production and the role redis on Mackerel.

  • Connect to port 6379 via TCP, send the string PING, and confirm that the string PONG is returned.
  • Execute mackerel-plugin-redis to collect metrics.
probes:
  - service: production
    role: redis
    tcp:
      host: '{{ .Host.IPAddress.eth0 }}'
      port: 6379
      send: "PING\n"
      expect_pattern: "PONG"
      quit: "QUIT\n"
    command:
      command:
        - "mackerel-plugin-redis"
        - "-host={{ .Host.IPAddress.eth0 }}"
        - "-tempfile=/tmp/redis-{{ .Host.ID }}"

Template notation can be used within the configuration file. {{ .Host.IPAddress.eth0 }} retrieves the IP address of the host's eth0 interface. {{ .Host.ID }} retrieves the host ID. This .Host represents the host information that maprobe retrieves from Mackerel, and its entity is a Go struct (mackerel-client-go#Host).

By using host information, you can dynamically configure addresses that plugins or synthetic monitoring access.

https://pkg.go.dev/github.com/mackerelio/mackerel-client-go#Host

Recent Updates

Recently, I added a feature to send OpenTelemetry metrics.

In 2024, Mackerel began supporting OpenTelemetry metrics. These metrics are not compatible with metrics collected by traditional Mackerel plugins. When considering operational continuity, it is a significant effort to replace all existing metrics with the OTel format. Even when migrating gradually, it is preferable to switch while comparing them against the metrics from existing plugins.

Therefore, I added a feature to maprobe to send OTel metrics to Mackerel.

https://sfujiwara.hatenablog.com/entry/maprobe-otel-metrics

Usage is simple; just add the following to your configuration file. This allows you to convert metrics collected by traditional Mackerel plugins into OTel format and send them to Mackerel.

destination:
  mackerel:
    enabled: true
  otel:
    enabled: true
    endpoint: otlp.mackerelio.com:4317

Summary

maprobe is a synthetic monitoring agent that integrates with Mackerel. Since it also supports OTel, it should be useful when migrating from traditional Mackerel plugins to OTel metrics.

If you are using Mackerel, please give it a try.

Look forward to tomorrow's post!

References

https://sfujiwara.hatenablog.com/entry/2018/04/23/113316

https://sfujiwara.hatenablog.com/entry/maprobe-tips

https://sfujiwara.hatenablog.com/entry/maprobe-otel-metrics

https://speakerdeck.com/fujiwara3/mackerel-day-number-2

https://speakerdeck.com/fujiwara3/mackerel-drinkup-number-7

Discussion