me3x

package
v0.11.5 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 16 Imported by: 1

Documentation

Overview

Package me3x package contains abstractions for reporting metrics to Graphite or Prometheus.

Index

Constants

This section is empty.

Variables

View Source
var GraphiteTimeout = 1 * time.Minute

GraphiteTimeout is the timeout for sending metrics to Graphite.

Functions

func ToString

func ToString(value interface{}) string

ToString returns a string description of a provided value making use of Labeled.

Types

type AtomicFloat64

type AtomicFloat64 uint64

AtomicFloat64 is an atomic float64 implementation.

func (*AtomicFloat64) Add

func (f *AtomicFloat64) Add(delta float64)

Add adds delta to the value.

func (*AtomicFloat64) Get

func (f *AtomicFloat64) Get() float64

Get returns current value.

func (*AtomicFloat64) Set

func (f *AtomicFloat64) Set(value float64)

Set sets the value.

func (*AtomicFloat64) Swap

func (f *AtomicFloat64) Swap(value float64) float64

Swap updates the value and returns the old one.

type Counter

type Counter interface {

	// Inc increments counter by 1.
	Inc()

	// Add adds delta to the counter.
	Add(delta float64)
}

Counter is a simple metric which can be incremented.

type DummyRegistry

type DummyRegistry struct {
	// Prefix is prefixed used for all metric names.
	Prefix string
	// Log should be set if metric call logging is desired.
	Log bool
}

DummyRegistry is a dummy Registry implementation which does not store any metrics. Optionally may log calls.

func (DummyRegistry) Counter

func (r DummyRegistry) Counter(name string, labels Labels) Counter

func (DummyRegistry) Gauge

func (r DummyRegistry) Gauge(name string, labels Labels) Gauge

func (DummyRegistry) Histogram

func (r DummyRegistry) Histogram(name string, labels Labels, _ []float64) Histogram

func (DummyRegistry) WithPrefix

func (r DummyRegistry) WithPrefix(prefix string) Registry

type Gauge

type Gauge interface {

	// Set sets the current value.
	Set(value float64)

	// Inc increments current value by 1.
	Inc()

	// Dec decrements current value by 1.
	Dec()

	// Add adds delta to the current value.
	Add(delta float64)

	// Sub subtracts delta from the current value.
	Sub(delta float64)
}

Gauge is a metric which value can be set.

type GraphiteClient

type GraphiteClient struct {

	// Address is the address for sending metrics to.
	// See https://graphite.readthedocs.io/en/latest/feeding-carbon.html.
	Address string

	// Clock is used for getting timestamps when sending data.
	Clock syncf.Clock

	// HGBF is histogram bucket format.
	// It is a string pattern used to transform histogram bucket values into metric name suffix.
	HGBF string
	// contains filtered or unexported fields
}

GraphiteClient is a Registry implementation for Graphite.

func (*GraphiteClient) Close

func (c *GraphiteClient) Close() error

Close stops the goroutine if it was started

func (*GraphiteClient) Counter

func (c *GraphiteClient) Counter(name string, labels Labels) Counter

func (*GraphiteClient) Flush

func (c *GraphiteClient) Flush() error

Flush flushes metrics to Graphite.

func (*GraphiteClient) FlushEvery added in v0.10.5

func (c *GraphiteClient) FlushEvery(interval time.Duration)

FlushEvery starts a goroutine which flushes metrics from this GraphiteClient to the Graphite itself.

func (*GraphiteClient) Gauge

func (c *GraphiteClient) Gauge(name string, labels Labels) Gauge

func (*GraphiteClient) Histogram

func (c *GraphiteClient) Histogram(name string, labels Labels, buckets []float64) Histogram

func (*GraphiteClient) WithPrefix

func (c *GraphiteClient) WithPrefix(prefix string) Registry

type GraphiteCounter

type GraphiteCounter AtomicFloat64

GraphiteCounter is a Prometheus counter emulation.

func (*GraphiteCounter) Add

func (c *GraphiteCounter) Add(delta float64)

func (*GraphiteCounter) Inc

func (c *GraphiteCounter) Inc()

func (*GraphiteCounter) Write

func (c *GraphiteCounter) Write(b *strings.Builder, now string, key string)

type GraphiteGauge

type GraphiteGauge AtomicFloat64

GraphiteGauge is a Prometheus gauge emulation.

func (*GraphiteGauge) Add

func (g *GraphiteGauge) Add(delta float64)

func (*GraphiteGauge) Dec

func (g *GraphiteGauge) Dec()

func (*GraphiteGauge) Inc

func (g *GraphiteGauge) Inc()

func (*GraphiteGauge) Set

func (g *GraphiteGauge) Set(value float64)

func (*GraphiteGauge) Sub

func (g *GraphiteGauge) Sub(delta float64)

func (*GraphiteGauge) Write

func (g *GraphiteGauge) Write(b *strings.Builder, now string, key string)

type GraphiteHistogram

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

GraphiteHistogram is a Prometheus histogram emulation. This is a really primitive emulation.

func (GraphiteHistogram) Observe

func (h GraphiteHistogram) Observe(value float64)

func (GraphiteHistogram) Write

func (h GraphiteHistogram) Write(b *strings.Builder, now string, key string)

type GraphiteMetric

type GraphiteMetric interface {

	// Write writes current metric value to Graphite, resetting the value if necessary.
	Write(b *strings.Builder, now string, key string)
}

GraphiteMetric is a metric which can be sent to Graphite.

type Histogram

type Histogram interface {

	// Observe registers a value within this Histogram.
	Observe(value float64)
}

Histogram is a histogram metric.

type Label

type Label struct {

	// Name is the Label name.
	Name string

	// Value is the Label value.
	Value any
}

Label is a key-value pair.

type Labeled

type Labeled interface {
	Labels() Labels
}

Labeled is a value which has Labels.

type Labels

type Labels []Label

Labels is the Label slice.

func (Labels) Add

func (l Labels) Add(name string, value any) Labels

Add adds a Label to Labels.

func (Labels) AddAll

func (l Labels) AddAll(labels Labels) Labels

AddAll adds all Labels from the other slice to this one.

func (Labels) Map

func (l Labels) Map() map[string]any

Map returns a string-any map based on the labels.

func (Labels) Name added in v0.11.0

func (l Labels) Name(name string) Labels

Name adds a Label with an empty Value to Labels.

func (Labels) Names added in v0.11.0

func (l Labels) Names() []string

Names returns all Label names.

func (Labels) String

func (l Labels) String() string

func (Labels) StringMap

func (l Labels) StringMap() map[string]string

StringMap returns a string-string map based on the labels.

type PrometheusListener

type PrometheusListener struct {
	Address string
	// contains filtered or unexported fields
}

PrometheusListener is a Prometheus-based metric Registry.

func (*PrometheusListener) Close

func (p *PrometheusListener) Close() error

func (*PrometheusListener) CloseWithContext

func (p *PrometheusListener) CloseWithContext(ctx context.Context) error

func (*PrometheusListener) Counter

func (p *PrometheusListener) Counter(name string, labels Labels) Counter

func (*PrometheusListener) Gauge

func (p *PrometheusListener) Gauge(name string, labels Labels) Gauge

func (*PrometheusListener) Histogram

func (p *PrometheusListener) Histogram(name string, labels Labels, buckets []float64) Histogram

func (*PrometheusListener) MustRegister

func (*PrometheusListener) WithPrefix

func (p *PrometheusListener) WithPrefix(prefix string) Registry

type Registry

type Registry interface {

	// WithPrefix returns a copy of this Registry with the new sub-prefix
	// which will be applied to all of new Registry's metrics.
	WithPrefix(prefix string) Registry

	// Counter returns a Counter instance.
	// Labels are used depending on implementation.
	Counter(name string, labels Labels) Counter

	// Gauge returns a Gauge instance.
	// Labels are used depending on implementation.
	Gauge(name string, labels Labels) Gauge

	// Histogram returns a Histogram instance.
	// Labels are used depending on implementation.
	Histogram(name string, labels Labels, buckets []float64) Histogram
}

Registry is an interface representing a named metric registry.

Jump to

Keyboard shortcuts

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