groupcache_exporter

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2025 License: MIT Imports: 2 Imported by: 14

README

license Go Report Card Go Reference

Prometheus Groupcache exporter

This exporter implements the prometheus.Collector interface in order to expose Prometheus metrics for groupcache.

Example for mailgun groupcache

import "github.com/udhos/groupcache_exporter/groupcache/mailgun"

// ...

appName := filepath.Base(os.Args[0])

cache := startGroupcache()

//
// expose prometheus metrics
//
{
    metricsRoute := "/metrics"
    metricsPort := ":3000"

    log.Printf("starting metrics server at: %s %s", metricsPort, metricsRoute)

    mailgun := mailgun.New(cache)
    labels := map[string]string{
        "app": appName,
    }
    namespace := ""
    collector := groupcache_exporter.NewExporter(namespace, labels, mailgun)

    prometheus.MustRegister(collector)

    go func() {
        http.Handle(metricsRoute, promhttp.Handler())
        log.Fatal(http.ListenAndServe(metricsPort, nil))
    }()
}

Full example: examples/groupcache-exporter-mailgun

Example for modernprogram groupcache

import "github.com/udhos/groupcache_exporter/groupcache/modernprogram"

// ...

appName := filepath.Base(os.Args[0])

cache := startGroupcache()

//
// expose prometheus metrics
//
{
    metricsRoute := "/metrics"
    metricsPort := ":3000"

    log.Printf("starting metrics server at: %s %s", metricsPort, metricsRoute)

    modernprogram := modernprogram.New(cache)
    labels := map[string]string{
        "app": appName,
    }
    namespace := ""
    collector := groupcache_exporter.NewExporter(namespace, labels, modernprogram)

    prometheus.MustRegister(collector)

    go func() {
        http.Handle(metricsRoute, promhttp.Handler())
        log.Fatal(http.ListenAndServe(metricsPort, nil))
    }()
}

Full example: examples/groupcache-exporter-modernprogram

Testing

Build

go install ./...

Run example application

groupcache-exporter-mailgun

Query the metrics endpoint

curl -s localhost:3000/metrics | grep -E ^groupcache
groupcache_cache_bytes{app="groupcache-exporter-mailgun",group="files",type="hot"} 0
groupcache_cache_bytes{app="groupcache-exporter-mailgun",group="files",type="main"} 2954
groupcache_cache_evictions_total{app="groupcache-exporter-mailgun",group="files",type="hot"} 0
groupcache_cache_evictions_total{app="groupcache-exporter-mailgun",group="files",type="main"} 1
groupcache_cache_gets_total{app="groupcache-exporter-mailgun",group="files",type="hot"} 4
groupcache_cache_gets_total{app="groupcache-exporter-mailgun",group="files",type="main"} 16
groupcache_cache_hits_total{app="groupcache-exporter-mailgun",group="files",type="hot"} 0
groupcache_cache_hits_total{app="groupcache-exporter-mailgun",group="files",type="main"} 12
groupcache_cache_items{app="groupcache-exporter-mailgun",group="files",type="hot"} 0
groupcache_cache_items{app="groupcache-exporter-mailgun",group="files",type="main"} 1
groupcache_gets_total{app="groupcache-exporter-mailgun",group="files"} 14
groupcache_hits_total{app="groupcache-exporter-mailgun",group="files"} 12
groupcache_loads_deduped_total{app="groupcache-exporter-mailgun",group="files"} 2
groupcache_loads_total{app="groupcache-exporter-mailgun",group="files"} 2
groupcache_local_load_errs_total{app="groupcache-exporter-mailgun",group="files"} 0
groupcache_local_load_total{app="groupcache-exporter-mailgun",group="files"} 2
groupcache_peer_errors_total{app="groupcache-exporter-mailgun",group="files"} 0
groupcache_peer_loads_total{app="groupcache-exporter-mailgun",group="files"} 0
groupcache_server_requests_total{app="groupcache-exporter-mailgun",group="files"} 0

Documentation

Overview

Package groupcache_exporter exports prometheus metrics for groupcache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheDelta added in v1.3.2

type CacheDelta struct {
	Gets              int64
	Hits              int64
	PeerLoads         int64
	PeerErrors        int64
	Loads             int64
	LoadsDeduped      int64
	LocalLoads        int64
	LocalLoadsErrs    int64
	ServerRequests    int64
	CrosstalkRefusals int64
}

CacheDelta represents deltas for cache stats.

func GetCacheDelta added in v1.3.2

func GetCacheDelta(prev, curr GroupStats) CacheDelta

GetCacheDelta calculates deltas for cache stats.

type CacheTypeDelta added in v1.3.2

type CacheTypeDelta struct {
	Gets                int64
	Hits                int64
	Evictions           int64
	EvictionsNonExpired int64
}

CacheTypeDelta represents deltas for per-type cache stats.

func GetCacheTypeDelta added in v1.3.2

func GetCacheTypeDelta(prev, curr CacheTypeStats) CacheTypeDelta

GetCacheTypeDelta calculates deltas for per-type cache stats.

type CacheTypeStats added in v1.1.0

type CacheTypeStats struct {
	// GaugeCacheItems represents number of items in the main/hot cache
	GaugeCacheItems int64

	// GaugeCacheBytes represents number of bytes in the main/hot cache
	GaugeCacheBytes int64

	// CounterCacheGets represents number of get requests in the main/hot cache
	CounterCacheGets int64

	// CounterCacheHits represents number of hit in the main/hot cache
	CounterCacheHits int64

	// CounterCacheEvictions represents number of evictions in the main/hot cache
	CounterCacheEvictions int64

	// CounterCacheEvictionsNonExpired represents number of evictions for non-expired keys in the main/hot cache
	CounterCacheEvictionsNonExpired int64
}

CacheTypeStats holds stats for the main cache or the hot cache.

type Exporter

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

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

func NewExporter

func NewExporter(options Options) *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 GroupStatistics

type GroupStatistics interface {
	// Collect requests metrics collection from implementation
	Collect() Stats

	// Name returns the group's name
	Name() string
}

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 GroupStats added in v1.1.0

type GroupStats struct {

	// CounterGets represents any Get request, including from peers
	CounterGets int64

	// CounterHits represents either cache was good
	CounterHits int64

	// GaugeGetFromPeersLatencyLower represents slowest duration to request value from peers
	GaugeGetFromPeersLatencyLower float64

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

	// CounterPeerErrors represents a count of errors from peers
	CounterPeerErrors int64

	// CounterLoads represents (gets - cacheHits)
	CounterLoads int64

	// CounterLoadsDeduped represents after singleflight
	CounterLoadsDeduped int64

	// CounterLocalLoads represents total good local loads
	CounterLocalLoads int64

	// CounterLocalLoadsErrs represents total bad local loads
	CounterLocalLoadsErrs int64

	// CounterServerRequests represents gets that came over the network from peers
	CounterServerRequests int64

	// CounterCrosstalkRefusals represents refusals for additional crosstalks
	CounterCrosstalkRefusals int64
}

GroupStats holds general stats for the group.

type Options added in v1.2.0

type Options struct {
	Namespace  string
	Labels     map[string]string
	Debug      bool
	ListGroups func() []GroupStatistics
}

Options define parameters for Exporter.

type Stats added in v1.1.0

type Stats struct {
	// Group holds general stats for the group.
	Group GroupStats

	// Main holds stats for the group main cache.
	Main CacheTypeStats

	// Hot holds stats for the group hot cache.
	Hot CacheTypeStats
}

Stats holds full stats for the group.

Directories

Path Synopsis
examples
groupcache-exporter-google
Package main implements the example.
Package main implements the example.
groupcache-exporter-mailgun
Package main implements the example.
Package main implements the example.
groupcache-exporter-modernprogram
Package main implements the example.
Package main implements the example.
groupcache
google
Package google implements an adapter to extract metrics from google groupcache.
Package google implements an adapter to extract metrics from google groupcache.
mailgun
Package mailgun implements an adapter to extract metrics from mailgun groupcache.
Package mailgun implements an adapter to extract metrics from mailgun groupcache.
modernprogram
Package modernprogram implements an adapter to extract metrics from modernprogram groupcache.
Package modernprogram implements an adapter to extract metrics from modernprogram groupcache.

Jump to

Keyboard shortcuts

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