saramaprom

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

README

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/iamlongalong/saramaprom

Usage

import (
    "context"
    "github.com/Shopify/sarama"
    "github.com/iamlongalong/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. Default nil.
	Labels map[string]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
  • labels – custom labels to distinguish different consumers/producers

Requirements

Go 1.13 or above.

ps

this project is based on saramaprom

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportMetrics

func ExportMetrics(ctx context.Context, metricsRegistry MetricsRegistry, opt Options) error

ExportMetrics exports metrics from go-metrics to prometheus.

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

	// Label specifies value of "label" label. Default "".
	Labels map[string]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
}

Options holds optional params for ExportMetrics.

Jump to

Keyboard shortcuts

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