kprom

package module
v1.0.1-0...-5028cac Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

README

kprom

kprom is a plug-in package to provide prometheus metrics through a kgo.Hook.

This package tracks the following metrics under the following names, all metrics being counter vecs:

#{ns}_connects_total{node_id="#{node}"}
#{ns}_connect_errors_total{node_id="#{node}"}
#{ns}_write_errors_total{node_id="#{node}"}
#{ns}_write_bytes_total{node_id="#{node}"}
#{ns}_read_errors_total{node_id="#{node}"}
#{ns}_read_bytes_total{node_id="#{node}"}
#{ns}_produce_bytes_total{node_id="#{node}",topic="#{topic}"}
#{ns}_fetch_bytes_total{node_id="#{node}",topic="#{topic}"}
#{ns}_buffered_produce_records_total
#{ns}_buffered_fetch_records_total

Note that seed brokers use broker IDs prefixed with "seed_", with the number corresponding to which seed it is.

To use,

metrics := kprom.NewMetrics("namespace")
cl, err := kgo.NewClient(
	kgo.WithHooks(metrics),
	// ...other opts
)

You can use your own prometheus registry, as well as a few other options. See the package documentation for more info!

Documentation

Overview

Package kprom provides prometheus plug-in metrics for a kgo client.

This package tracks the following metrics under the following names, all metrics being counter vecs:

#{ns}_connects_total{node_id="#{node}"}
#{ns}_connect_errors_total{node_id="#{node}"}
#{ns}_write_errors_total{node_id="#{node}"}
#{ns}_write_bytes_total{node_id="#{node}"}
#{ns}_read_errors_total{node_id="#{node}"}
#{ns}_read_bytes_total{node_id="#{node}"}
#{ns}_produce_bytes_total{node_id="#{node}",topic="#{topic}"}
#{ns}_fetch_bytes_total{node_id="#{node}",topic="#{topic}"}
#{ns}_buffered_produce_records_total
#{ns}_buffered_fetch_records_total

This can be used in a client like so:

m := kprom.NewMetrics()
cl, err := kgo.NewClient(
        kgo.WithHooks(m),
        // ...other opts
)

More examples are linked in the main project readme: https://github.com/tdx/franz-go/#metrics--logging

By default, metrics are installed under the a new prometheus registry, but this can be overridden with the Registry option.

Note that seed brokers use broker IDs prefixed with "seed_", with the number corresponding to which seed it is.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metrics

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

Metrics provides prometheus metrics to a given registry.

func NewMetrics

func NewMetrics(namespace string, opts ...Opt) *Metrics

NewMetrics returns a new Metrics that adds prometheus metrics to the registry under the given namespace.

func (*Metrics) Handler

func (m *Metrics) Handler() http.Handler

Handler returns an http.Handler providing prometheus metrics.

func (*Metrics) OnBrokerConnect

func (m *Metrics) OnBrokerConnect(meta kgo.BrokerMetadata, _ time.Duration, _ net.Conn, err error)

func (*Metrics) OnBrokerDisconnect

func (m *Metrics) OnBrokerDisconnect(meta kgo.BrokerMetadata, _ net.Conn)

func (*Metrics) OnBrokerRead

func (m *Metrics) OnBrokerRead(meta kgo.BrokerMetadata, _ int16, bytesRead int, _, _ time.Duration, err error)

func (*Metrics) OnBrokerWrite

func (m *Metrics) OnBrokerWrite(meta kgo.BrokerMetadata, _ int16, bytesWritten int, _, _ time.Duration, err error)

func (*Metrics) OnFetchBatchRead

func (m *Metrics) OnFetchBatchRead(meta kgo.BrokerMetadata, topic string, _ int32, fbm kgo.FetchBatchMetrics)

func (*Metrics) OnNewClient

func (m *Metrics) OnNewClient(cl *kgo.Client)

func (*Metrics) OnProduceBatchWritten

func (m *Metrics) OnProduceBatchWritten(meta kgo.BrokerMetadata, topic string, _ int32, pbm kgo.ProduceBatchMetrics)

func (*Metrics) Registry

func (m *Metrics) Registry() prometheus.Registerer

Registry returns the prometheus registry that metrics were added to.

This is useful if you want the Metrics type to create its own registry for you to add additional metrics to.

type Opt

type Opt interface {
	// contains filtered or unexported methods
}

Opt applies options to further tune how prometheus metrics are gathered or which metrics to use.

func Gatherer

func Gatherer(gatherer prometheus.Gatherer) Opt

Registry sets the gatherer to add metrics to, rather than a new registry.

func GoCollectors

func GoCollectors() Opt

GoCollectors adds the prometheus.NewProcessCollector and prometheus.NewGoCollector collectors the the Metric's registry.

func HandlerOpts

func HandlerOpts(opts promhttp.HandlerOpts) Opt

HandlerOpts sets handler options to use if you wish you use the Metrics.Handler function.

This is only useful if you both (a) do not want to provide your own registry and (b) want to override the default handler options.

func Registerer

func Registerer(reg prometheus.Registerer) Opt

Registry sets the registerer to add metrics to, rather than a new registry.

func Registry

func Registry(rg RegistererGatherer) Opt

Registry sets the registerer and gatherer to add metrics to, rather than a new registry. Use this option if you want to configure both Gatherer and Registerer with the same object.

type RegistererGatherer

type RegistererGatherer interface {
	prometheus.Registerer
	prometheus.Gatherer
}

Jump to

Keyboard shortcuts

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