Skip to content
OpenTelemetry Mackerel Exporter
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.


This is OpenTelemetry Meter Exporter for Mackerel.

GoDoc Actions Status


If you use Go Modules, then you just import OpenTelemetry API and the exporter. Otherwise you can install manually.

$ go get -u
$ go get -u

After installation, you can start to write a program. There is the example at the Example section of this document.



Mackerel manages hosts database in the organization. Official mackerel-agent installed to the host, such as compute instance, bare metal or local machine collects host informations from resources provided by operating system. The exporter won't access external resources. Instead host informations will be generated from labels attached to the metrics.

For example, the host identifier that is unique in the organization refers the label Similarly the host name refers the label The exporter handles metrics attached these labels as host metric in Mackerel.


Like as hosts, both Service and Role are made from labels. Label service.namespace is mapped to Service, and the label is mapped Role.

Where post are metrics?

The metrics with a label below will post as Host Metric.


Also the metrics with these all labels below will post as Host Metric.

  • service.namespace

The metric with a labels below will post as Service Metric.

  • service.namespace

Graph Definitions

The exporter will create the Graph Definition on Mackerel if needed. Most cases it creates automatically based from recorded metric name. However you might think to want to customize the graph by wildcards in the graph name. In this case you can configure the exporter to use pre-defined graph name with WithHints() option.

The hint is the name composed by deleted only the end of the metric name, and it can be replaced each elements by wildcard, # or *. For example the hint http.handlers.# is valid for the metric http.handlers.index.count.

Special case. The exporter will append .min, .max and .percentile_xx implicitly to the end of the name for measure metric in OpenTelemetry. Thus count of elements of the hint will be same as the recorded metric name.


import (



var (
	// These keys are mapped to Mackerel's attributes.
	keyHostID      = key.New("")               // custom identifier
	keyHostName    = key.New("")             // hostname

	hints = []string{

func main() {
	apiKey := os.Getenv("MACKEREL_APIKEY")
	pusher, _ := mackerel.InstallNewPipeline(
	defer pusher.Stop()

	meter := global.MeterProvider().Meter("example")
	firestoreRead := meter.NewInt64Counter("", metric.WithKeys(
		keyHostID, keyHostName, keyGraphClass, keyMetricClass,
	labels := meter.Labels(
	ctx := context.Background()
	firestoreRead.Add(ctx, 100, labels)

	v := firestoreRead.Bind(labels)
	v.Add(ctx, 20)

	m := firestoreRead.Measurement(1)
	meter.RecordBatch(ctx, labels, m)
	time.Sleep(2 * time.Minute)
You can’t perform that action at this time.