Metrics exporter from Sarama to Prometheus.
Перейти к файлу
kraxx dbca23a73a update go.mod & go.sum 2022-03-16 13:34:56 -04:00
.gitignore refactoring 2020-09-11 10:44:00 +03:00
LICENSE Initial commit 2020-08-25 10:36:00 +03:00
README.md Update README.md 2021-01-06 18:04:36 +03:00
exporter.go bugfix 2020-09-11 10:44:31 +03:00
go.mod update go.mod & go.sum 2022-03-16 13:34:56 -04:00
go.sum update go.mod & go.sum 2022-03-16 13:34:56 -04:00
saramaprom.go refactoring 2020-09-11 10:44:00 +03:00
saramaprom_test.go init 2020-08-25 13:58:00 +03:00

README.md

saramaprom

GoDoc Go Report

This is a prometheus metrics reporter for the sarama library. It is based on https://github.com/deathowl/go-metrics-prometheus library.

Why

Because go-metrics-prometheus is a general solution it reports metrics with no labels so it's hard to use. Thus a sarama specific solution was made, it reports metrics with labels for brokers, topics and consumer/producer instance.

Installation

go get github.com/iimos/saramaprom

Usage

import (
    "context"
    "github.com/Shopify/sarama"
    "github.com/iimos/saramaprom"
)

ctx := context.Background()
cfg := sarama.NewConfig()
err := saramaprom.ExportMetrics(ctx, cfg.MetricRegistry, saramaprom.Options{})

Posible 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

	// Label specifies value of "label" label. Default "".
	Label string

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

	// OnError is error handler. Default handler panics when error occurred.
	OnError func(err error)

	// Debug turns on debug logging.
	Debug bool
}

Metric names by default:

Gauges:
sarama_batch_size
sarama_compression_ratio
sarama_incoming_byte_rate
sarama_outgoing_byte_rate
sarama_record_send_rate
sarama_records_per_request
sarama_request_latency_in_ms
sarama_request_rate
sarama_request_size
sarama_requests_in_flight
sarama_response_rate
sarama_response_size

Histograms:
sarama_batch_size_histogram
sarama_compression_ratio_histogram
sarama_records_per_request_histogram
sarama_request_latency_in_ms_histogram
sarama_request_size_histogram
sarama_response_size_histogram

Every metric have three labels:

  • broker – kafka broker id
  • topic – kafka topic name
  • label – custom label to distinguish different consumers/producers

Requirements

Go 1.13 or above.