mackerel

package module
v0.0.0-...-a2da4af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2020 License: BSD-3-Clause Imports: 18 Imported by: 0

README

mackerelexporter-go

This is the OpenTelemetry Exporter for Mackerel.

GoDoc Actions Status

Hosts

TODO

Graph Definitions

TODO

Example

import (
	"context"
	"os"
	"time"

	"go.opentelemetry.io/otel/api/global"
	"go.opentelemetry.io/otel/api/key"
	"go.opentelemetry.io/otel/api/metric"

	"github.com/lufia/mackerelexporter"
)

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

	hints = []string{
		"storage.#",
	}
)

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

	meter := global.MeterProvider().Meter("example")
	firestoreRead := meter.NewInt64Counter("storage.firestore.read", metric.WithKeys(
		keyHostID, keyHostName, keyGraphClass, keyMetricClass,
	))
	labels := meter.Labels(
		keyHostID.String("10-1-2-241"),
		keyHostName.String("localhost"),
	)
	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)
}

Documentation

Index

Constants

View Source
const (
	UnitDimensionless = unit.Dimensionless
	UnitBytes         = unit.Bytes
	UnitMilliseconds  = unit.Milliseconds
)

Variables

This section is empty.

Functions

func CanonicalMetricName

func CanonicalMetricName(s string) string

CanonicalMetricName returns canonical metric name.

func InstallNewPipeline

func InstallNewPipeline(opts ...Option) (*push.Controller, error)

InstallNewPipeline instantiates a NewExportPipeline and registers it globally.

func JoinMetricName

func JoinMetricName(elem ...string) string

JoinMetricName joins any number of name elements int a single name.

func NewExportPipeline

func NewExportPipeline(opts ...Option) (*push.Controller, error)

NewExportPipeline sets up a complete export pipeline.

func NewGraphDef

func NewGraphDef(name string, kind export.MetricKind, opts GraphDefOptions) (*mackerel.GraphDefsParam, error)

NewGraphDef returns Mackerel's Graph Definition. Each names in arguments must be canonicalized.

func PercentileName

func PercentileName(q float64) string

PercentileName returns "percentile_xx".

func UnmarshalLabels

func UnmarshalLabels(labels []core.KeyValue, v interface{}) error

UnmarshalLabels parses labels and store the result into v.

func WithAPIKey

func WithAPIKey(apiKey string) func(o *options)

WithAPIKey sets the Mackerel API Key.

func WithHints

func WithHints(hints []string) func(o *options)

WithHints sets hints for decision the name of the Graph Definition.

func WithQuantiles

func WithQuantiles(quantiles []float64) func(o *options)

WithQuantiles sets quantiles for recording measure metrics. Each quantiles must be unique and its precision must be greater or equal than 0.01.

Types

type CloudResource

type CloudResource struct {
	Provider string `resource:"provider"`
}

CloudResource represents the standard cloud attributes.

type Exporter

type Exporter struct {
	// contains filtered or unexported fields
}

Exporter is a stats exporter that uploads data to Mackerel.

func NewExporter

func NewExporter(opts ...Option) (*Exporter, error)

NewExporter creates a new Exporter.

func (*Exporter) Export

func (e *Exporter) Export(ctx context.Context, a export.CheckpointSet) error

func (*Exporter) UpsertHost

func (e *Exporter) UpsertHost(r *Resource) (string, error)

UpsertHost update or insert the host with r.

type GraphDefOptions

type GraphDefOptions struct {
	Name      string
	Unit      unit.Unit
	Kind      core.NumberKind
	Quantiles []float64
}

GraphDefOptions represents options for customizing Mackerel's Graph Definition.

type HostResource

type HostResource struct {
	ID   string `resource:"id"`
	Name string `resource:"name"`
}

HostResource represents the standard host attributes.

type InstanceResource

type InstanceResource struct {
	ID string `resource:"id"`
}

InstanceResource represents the standard instance attributes.

type MetricName

type MetricName string

func (MetricName) Match

func (g MetricName) Match(s string) bool

type Option

type Option func(*options)

Option is function type that is passed to NewExporter function.

type Resource

type Resource struct {
	Service ServiceResource `resource:"service"`
	Host    HostResource    `resource:"host"`
	Cloud   CloudResource   `resource:"cloud"`
}

Resource represents a resource constructed with labels.

func (*Resource) CustomIdentifier

func (r *Resource) CustomIdentifier() string

CustomIdentifier returns a proper customIdentifier for the host.

func (*Resource) Hostname

func (r *Resource) Hostname() string

Hostname returns a proper hostname.

type ServiceResource

type ServiceResource struct {
	Name     string           `resource:"name"`
	NS       string           `resource:"namespace"`
	Instance InstanceResource `resource:"instance"`
	Version  string           `resource:"version"`
}

ServiceResource represents the standard service attributes.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL