groupcache_exporter

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: MIT Imports: 1 Imported by: 4

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 Exporter

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

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

func NewExporter

func NewExporter(namespace string, labels map[string]string, groups ...GroupStatistics) *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 {
	// 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() int64

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

	HotCacheItems() int64
	HotCacheBytes() int64
	HotCacheGets() int64
	HotCacheHits() int64
	HotCacheEvictions() 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.

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