client_golang: Index | Examples | Files

package graphite

import ""

Package graphite provides a bridge to push Prometheus metrics to a Graphite server.



Package Files


type Bridge Uses

type Bridge struct {
    // contains filtered or unexported fields

Bridge pushes metrics to the configured Graphite server.


b, err := NewBridge(&Config{
    URL:           "",
    Gatherer:      prometheus.DefaultGatherer,
    Prefix:        "prefix",
    Interval:      15 * time.Second,
    Timeout:       10 * time.Second,
    ErrorHandling: AbortOnError,
    Logger:        log.New(os.Stdout, "graphite bridge: ", log.Lshortfile),
if err != nil {

go func() {
    // Start something in a goroutine that uses metrics.

// Push initial metrics to Graphite. Fail fast if the push fails.
if err := b.Push(); err != nil {

// Create a Context to control stopping the Run() loop that pushes
// metrics to Graphite.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Start pushing metrics to Graphite in the Run() loop.

func NewBridge Uses

func NewBridge(c *Config) (*Bridge, error)

NewBridge returns a pointer to a new Bridge struct.

func (*Bridge) Push Uses

func (b *Bridge) Push() error

Push pushes Prometheus metrics to the configured Graphite server.

func (*Bridge) Run Uses

func (b *Bridge) Run(ctx context.Context)

Run starts the event loop that pushes Prometheus metrics to Graphite at the configured interval.

type Config Uses

type Config struct {
    // Whether to use Graphite tags or not. Defaults to false.
    UseTags bool

    // The url to push data to. Required.
    URL string

    // The prefix for the pushed Graphite metrics. Defaults to empty string.
    Prefix string

    // The interval to use for pushing data to Graphite. Defaults to 15 seconds.
    Interval time.Duration

    // The timeout for pushing metrics to Graphite. Defaults to 15 seconds.
    Timeout time.Duration

    // The Gatherer to use for metrics. Defaults to prometheus.DefaultGatherer.
    Gatherer prometheus.Gatherer

    // The logger that messages are written to. Defaults to no logging.
    Logger Logger

    // ErrorHandling defines how errors are handled. Note that errors are
    // logged regardless of the configured ErrorHandling provided Logger
    // is not nil.
    ErrorHandling HandlerErrorHandling

Config defines the Graphite bridge config.

type HandlerErrorHandling Uses

type HandlerErrorHandling int

HandlerErrorHandling defines how a Handler serving metrics will handle errors.

const (
    // Ignore errors and try to push as many metrics to Graphite as possible.
    ContinueOnError HandlerErrorHandling = iota

    // Abort the push to Graphite upon the first error encountered.

These constants cause handlers serving metrics to behave as described if errors are encountered.

type Logger Uses

type Logger interface {
    Println(v ...interface{})

Logger is the minimal interface Bridge needs for logging. Note that log.Logger from the standard library implements this interface, and it is easy to implement by custom loggers, if they don't do so already anyway.

Package graphite imports 12 packages (graph) and is imported by 5 packages. Updated 2019-10-25. Refresh now. Tools for package owners.