saramaprom

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

README

saramaprom

is a library for exporting sarama metrics (provided through go-metrics) to Prometheus. It is a fork of saramaprom with few fixes and tweaks:

  • go-metrics histograms are registered as Prometheus summaries (to better present client side quantiles)
  • removed histogram and timer words from metric names
  • removed configuration of optional labels from saramaprom (we never configure it and it was creating additional unnecessary dimension to metrics due to bad implementation)

Usage

saramaprom periodically refreshes exposed Prometheus metrics based on provided metrics.Registry. The registry of metrics must be shared between sarama consumers/producers and saramaprom library, so typical usage looks like this:

// create shared metric registry
metricRegistry := metrics.NewRegistry()

// create sarama configuration which uses the shared registry
config := sarama.NewConfig()
config.MetricRegistry = metricRegistry

// export metrics from shared metric registry using saramaprom
saramaprom.ExportMetrics(metricRegistry, saramaprom.Options{})

saramaprom.Options enables you to for example configure how often the metrics are refreshed, namespace of the metrics, etc.

Multiple metric registries can be defined to not mix values of several Kafka cluster. But in that case the prometheus metrics have to be distinguished by labels. Use ExtraLabels option for that:

// create new registry and export metrics for cluster Foo 
configFoo := sarama.NewConfig()
configFoo.MetricRegistry = metrics.NewRegistry()
saramaprom.ExportMetrics(configFoo.MetricRegistry, saramaprom.Options{ExtraLabels: map[string]string{"cluster": "foo"}})

// create new registry and export metrics for cluster Bar 
configBar := sarama.NewConfig()
configBar.MetricRegistry = metrics.NewRegistry()
saramaprom.ExportMetrics(configBar.MetricRegistry, saramaprom.Options{ExtraLabels: map[string]string{"cluster": "bar"}})

Documentation

Overview

Package saramaprom provides a Prometheus exporter for the Sarama metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MetricsRegistry

type MetricsRegistry interface {
	Each(func(name string, i interface{}))
}

MetricsRegistry is an interface for 'github.com/rcrowley/go-metrics'.Registry which is used for metrics in sarama.

type Options

type Options struct {
	// PrometheusRegistry is prometheus registry. Default prometheus.DefaultRegisterer.
	PrometheusRegistry prometheus.Registerer

	// Namespace and Subsystem form the metric name prefix.
	// Default Subsystem is "sarama".
	Namespace string
	Subsystem string

	// Extra labels to be added to all metrics. Beware, this will override the default label value if configured with same name.
	ExtraLabels prometheus.Labels

	// RefreshInterval specifies interval between updating metrics. Default 1s.
	RefreshInterval time.Duration
}

Options holds optional params for ExportMetrics.

type Scheduler

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

Scheduler is used to run jobs in specific intervals.

func StartScheduler

func StartScheduler(interval time.Duration, job func()) Scheduler

StartScheduler starts goroutine that will run given job in given intervals until Stop() is called.

func (Scheduler) Stop

func (s Scheduler) Stop()

Stop stops the goroutine running scheduled job.

type StopFunc

type StopFunc func()

StopFunc represents function for stopping scheduled task.

func ExportMetrics

func ExportMetrics(metricsRegistry MetricsRegistry, opt Options) StopFunc

ExportMetrics exports metrics from go-metrics to prometheus by starting background task, which periodically sync sarama metrics to prometheus registry.

Jump to

Keyboard shortcuts

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