promexporter

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: Apache-2.0, MIT Imports: 2 Imported by: 0

README

Prometheus Groupcache Exporter

This exporter extracts statistics from group instances and exports as Prometheus metrics.

Example

import (
	"github.com/mailgun/groupcache/v2"
	"github.com/mailgun/groupcache/v2/promexporter"
	"github.com/prometheus/client_golang/prometheus"
)

// ...

collector := promexporter.NewExporter()
prometheus.MustRegister(collector)

// Collector will discover newly created group.
group := groupcache.NewGroup("mygroup", cacheSize, getter)

Metrics

Exported from groupcache's CacheStats()
  • groupcache_cache_bytes{group,type="main|hot"}: Gauge of current bytes in use
  • groupcache_cache_evictions_nonexpired_total{group,type="main|hot"}: Count of cache evictions for non-expired keys due to memory full
  • groupcache_cache_evictions_total{group,type="main|hot"}: Count of cache evictions
  • groupcache_cache_gets_total{group,type="main|hot"}: Count of cache gets
  • groupcache_cache_hits_total{group,type="main|hot"}: Count of cache hits
  • groupcache_cache_items{group,type="main|hot"}: Gauge of current items in use
Exported from groupcache's Stats()
  • groupcache_get_from_peers_latency_lower{group}: Represent slowest duration to request value from peers
  • groupcache_gets_total{group}: Count of cache gets (including from peers, from either main or hot caches)
  • groupcache_hits_total{group}: Count of cache hits (from either main or hot caches)
  • groupcache_loads_deduped_total{group}: Count of loads after singleflight
  • groupcache_loads_total{group}: Count of (gets - hits)
  • groupcache_local_load_errs_total{group}: Count of load errors from local cache
  • groupcache_local_loads_total{group}: Count of loads from local cache
  • groupcache_peer_errors_total{group}: Count of errors from peers
  • groupcache_peer_loads_total{group}: Count of loads or cache hits from peers
  • groupcache_server_requests_total{group}: Count of gets received from peers

Attribution

This package source originated from https://github.com/udhos/groupcache_exporter. See LICENSE for MIT license details impacting the contents of this package directory in addition to the LICENSE at the root of this repo for co-existing Apache license details.

Documentation

Overview

Package promexporter exports Prometheus metrics for groupcache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exporter

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

Exporter implements interface prometheus.Collector to extract metrics from groupcache.

func NewExporter

func NewExporter(opts ...Option) *Exporter

NewExporter creates Exporter. namespace is usually the empty string.

func (*Exporter) Collect

func (e *Exporter) Collect(ch chan<- prometheus.Metric)

Collect is called by the Prometheus registry when collecting metrics.

func (*Exporter) Describe

func (e *Exporter) Describe(ch chan<- *prometheus.Desc)

Describe sends metrics descriptors.

type GroupProvider

type GroupProvider interface {
	Groups() []*groupcache.Group
}

type GroupStatistics

type GroupStatistics interface {
	// Name returns the group's name
	Name() string

	// Gets represents any Get request, including from peers
	Gets() int64

	// CacheHits represents either cache was good
	CacheHits() int64

	// GetFromPeersLatencyLower represents slowest duration to request value from peers
	GetFromPeersLatencyLower() float64

	// PeerLoads represents either remote load or remote cache hit (not an error)
	PeerLoads() int64

	// PeerErrors represents a count of errors from peers
	PeerErrors() int64

	// Loads represents (gets - cacheHits)
	Loads() int64

	// LoadsDeduped represents after singleflight
	LoadsDeduped() int64

	// LocalLoads represents total good local loads
	LocalLoads() int64

	// LocalLoadErrs represents total bad local loads
	LocalLoadErrs() int64

	// ServerRequests represents gets that came over the network from peers
	ServerRequests() int64

	MainCacheItems() int64
	MainCacheBytes() int64
	MainCacheGets() int64
	MainCacheHits() int64
	MainCacheEvictions() int64
	MainCacheEvictionsNonExpired() int64

	HotCacheItems() int64
	HotCacheBytes() int64
	HotCacheGets() int64
	HotCacheHits() int64
	HotCacheEvictions() int64
	HotCacheEvictionsNonExpired() int64
}

GroupStatistics is a plugable interface to extract metrics from a groupcache implementation. GroupStatistics is used by Exporter to collect the group statistics. The user must provide a concrete implementation of this interface that knows how to extract group statistics from the actual groupcache implementation.

type Option

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

func WithGroups

func WithGroups(groups GroupProvider) Option

Set function used to get groups to export. Called on every scrape.

func WithLabels

func WithLabels(labels map[string]string) Option

Set labels added to exported metrics.

func WithNamespace

func WithNamespace(namespace string) Option

Set namespace of exported metrics. Namespace serves as the prefix to metric names, like: `<namespace>_groupcache_cache_bytes`.

Jump to

Keyboard shortcuts

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