rrd

package module
v0.0.0-...-4a70b1d Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2017 License: BSD-2-Clause Imports: 12 Imported by: 0

README

go-rrd Go Report Card License GoDoc Build Status

go-rrd is a Go client for talking to rrdtool's rrdcached.

Features

Installation

go get -u github.com/multiplay/go-rrd

Examples

Using go-rrd is simple just create a client and then send commands e.g.

package main

import (
	"log"
	"time"

	"github.com/multiplay/go-rrd"
)

func main() {
	c, err := rrd.NewClient("192.168.1.102:10011")
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()

	if err := c.Create(
		"test.rrd",
		[]DS{NewGauge("watts", time.Minute*5, 0, 24000)},
		[]RRA{NewAverage(0.5, 1, 864000)},
	); err != nil {
		log.Fatal(err)
	}
}

Documentation

License

go-rrd is available under the BSD 2-Clause License.

Documentation

Overview

Package rrd provides a client which can talk to rrdtool's rrdcached It supports all known commands and uses native golang types where appropriate.

Index

Constants

View Source
const (
	Gauge    = "GAUGE"
	Counter  = "COUNTER"
	DCounter = "DCOUNTER"
	Derive   = "DERIVE"
	DDerive  = "DDERIVE"
	Absolute = "ABSOLUTE"
	Compute  = "COMPUTE"
)

Data Source Types

View Source
const (
	Average = "AVERAGE"
	Min     = "MIN"
	Max     = "MAX"
	Last    = "LAST"

	HoltWintersPredict          = "HWPREDICT"
	MultipliedHoltWinterPredict = "MHWPREDICT"
	Seasonal                    = "SEASONAL"
	DevSeasonal                 = "DEVSEASONAL"
	DevPredict                  = "DEVPREDICT"
	Failures                    = "FAILURES"
)

Round Robin Algorithms

View Source
const (
	// DefaultPort is the default rrdcached port.
	DefaultPort = 42217
)

Variables

View Source
var (

	// DefaultTimeout is the default read / write / dial timeout for Clients.
	DefaultTimeout = time.Second * 10
)
View Source
var (
	// ErrNilOption is returned by NewClient if an option is nil.
	ErrNilOption = errors.New("nil option")
)

Functions

func IsExist

func IsExist(err error) bool

IsExist returns true if err represents a failure due to a existing rrd, false otherwise.

func IsIllegalUpdate

func IsIllegalUpdate(err error) bool

IsIllegalUpdate returns true if err represents a failure due to an illegal update, false otherwise.

func IsNotExist

func IsNotExist(err error) bool

IsNotExist returns true if err represents a failure due to a non-existing rrd, false otherwise.

func Mapping

func Mapping(name string, idx int) func(d *ds)

Mapping applies a custom mapping to the data source.

func Timeout

func Timeout(timeout time.Duration) func(*Client) error

Timeout sets read / write / dial timeout for a rrdcached Client.

func Unix

func Unix(c *Client) error

Unix sets the client to use a unix socket.

Types

type Client

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

Client is a rrdcached client.

func NewClient

func NewClient(addr string, options ...func(c *Client) error) (*Client, error)

NewClient returns a new rrdcached client connected to addr. By default addr is treated as a TCP address to use UNIX sockets pass Unix as an option. If addr for a TCP address doesn't include a port the DefaultPort will be used.

func (*Client) Batch

func (c *Client) Batch(cmds ...*Cmd) error

Batch initiates the bulk load of multiple commands.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection to the server.

func (*Client) Create

func (c *Client) Create(filename string, ds []DS, rra []RRA, options ...CreateOption) error

Create creates the RRD according to the supplied parameters.

func (*Client) Exec

func (c *Client) Exec(cmd string) ([]string, error)

Exec executes cmd on the server and returns the response.

func (*Client) ExecCmd

func (c *Client) ExecCmd(cmd *Cmd) ([]string, error)

ExecCmd executes cmd on the server and returns the response.

func (*Client) Fetch

func (c *Client) Fetch(filename, cf string, options ...interface{}) (*Fetch, error)

Fetch returns the free text results of a fetch command with the given options.

func (*Client) FetchBin

func (c *Client) FetchBin(filename, cf string, options ...interface{}) (*FetchBin, error)

FetchBin returns the text/binary results of a fetch command with the given options.

func (*Client) First

func (c *Client) First(filename string, rra int) (time.Time, error)

First returns the timestamp of the first CDP for the given RRA.

func (*Client) Flush

func (c *Client) Flush(filename string) error

Flush requests rrdcached flushed all values pending for filename to disk.

func (*Client) FlushAll

func (c *Client) FlushAll() error

FlushAll requests the rrdcached start to flush all pending values to disk.

func (*Client) Forget

func (c *Client) Forget(filename string) error

Forget requests rrdcached remove filename from the cache. Any pending updates WILL BE LOST.

func (*Client) Help

func (c *Client) Help(cmd ...string) ([]string, error)

Help returns command help.

func (*Client) Info

func (c *Client) Info(filename string) ([]*Info, error)

Info returns the configuration information for the specified RRD.

func (*Client) Last

func (c *Client) Last(filename string) (time.Time, error)

Last returns the timestamp of the last update to the specified RRD.

func (*Client) Pending

func (c *Client) Pending(filename string) ([]string, error)

Pending returns any "pending" updates for a file, in order.

func (*Client) Ping

func (c *Client) Ping() error

Ping sends a ping to the server.

func (*Client) Queue

func (c *Client) Queue(filename string) ([]*Queue, error)

Queue returns the files that are on the rrdcached output queue.

func (*Client) Stats

func (c *Client) Stats() (*Stats, error)

Stats returns stats about rrdcached.

func (*Client) Update

func (c *Client) Update(filename string, value Update, values ...Update) error

Update adds more data to filename.

func (*Client) Wrote

func (c *Client) Wrote(filename string) error

Wrote sends a wrote command for filename to rrdcached.

type Cmd

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

Cmd represents a rrdcached command.

func NewCmd

func NewCmd(cmd string) *Cmd

NewCmd creates a new Cmd.

func (*Cmd) String

func (c *Cmd) String() string

func (*Cmd) WithArgs

func (c *Cmd) WithArgs(args ...interface{}) *Cmd

WithArgs sets the command Args.

type CreateOption

type CreateOption string

CreateOption represents a rrd create option.

func NoOverwrite

func NoOverwrite() CreateOption

NoOverwrite returns a new create no overwrite option.

func Source

func Source(file string) CreateOption

Source returns a new create source option.

func Start

func Start(start time.Time) CreateOption

Start returns a new create start time option.

func Step

func Step(step time.Duration) CreateOption

Step returns a new create step option.

func Template

func Template(file string) CreateOption

Template returns a new create template option.

type DS

type DS string

DS represents a RRD data source.

func NewAbsolute

func NewAbsolute(name string, heartbeat time.Duration, min, max int, options ...func(d *ds)) DS

NewAbsolute returns a new ABSOLUTE DS.

func NewCompute

func NewCompute(name, cdef string, options ...func(d *ds)) DS

NewCompute returns a new COMPUTE DS.

func NewCounter

func NewCounter(name string, heartbeat time.Duration, min, max int, options ...func(d *ds)) DS

NewCounter returns a new COUNTER DS.

func NewDCounter

func NewDCounter(name string, heartbeat time.Duration, min, max int, options ...func(d *ds)) DS

NewDCounter returns a new DCOUNTER DS.

func NewDDerive

func NewDDerive(name string, heartbeat time.Duration, min, max int, options ...func(d *ds)) DS

NewDDerive returns a new DDERIVE DS.

func NewDS

func NewDS(raw string) DS

NewDS returns a new DS for the value raw.

func NewDerive

func NewDerive(name string, heartbeat time.Duration, min, max int, options ...func(d *ds)) DS

NewDerive returns a new DERIVE DS.

func NewGauge

func NewGauge(name string, heartbeat time.Duration, min, max int, options ...func(d *ds)) DS

NewGauge returns a new GAUGE DS.

type Error

type Error struct {
	Code int
	Msg  string
}

Error represents a error returned from the rrdcached server.

func NewError

func NewError(code int, msg string) *Error

NewError returns a new Error.

func (*Error) Error

func (e *Error) Error() string

type Fetch

type Fetch struct {
	FetchCommon
	Names []string
	Rows  []FetchRow
}

Fetch represents the data returned by an rrdcached fetch command.

type FetchBin

type FetchBin struct {
	FetchCommon
	DS []*FetchBinDS
}

FetchBin represents the response from a fetchbin command.

type FetchBinDS

type FetchBinDS struct {
	Name    string
	Records int
	Size    int
	Endian  binary.ByteOrder
	Data    []interface{}
}

FetchBinDS represents a row of binary data.

type FetchCommon

type FetchCommon struct {
	FlushVersion int
	Start        time.Time
	End          time.Time
	Step         time.Duration
	Count        int
}

FetchCommon represents the common fields between fetch and fetchbin

type FetchRow

type FetchRow struct {
	Time time.Time
	Data []*float64
}

FetchRow represents a single row of data returned by an rrdcached fetch command.

type Info

type Info struct {
	Key   string
	Value interface{}
}

Info represents the configuration information of an RRD.

type InvalidResponseError

type InvalidResponseError struct {
	Reason string
	Data   []string
}

InvalidResponseError is the error returned when the response data was invalid.

func NewInvalidResponseError

func NewInvalidResponseError(reason string, lines ...string) *InvalidResponseError

NewInvalidResponseError returns a new InvalidResponseError from lines.

func (*InvalidResponseError) Error

func (e *InvalidResponseError) Error() string

type Queue

type Queue struct {
	Size int64
	File string
}

Queue represents a file queue.

type RRA

type RRA string

RRA represents a raw RRA.

func NewAverage

func NewAverage(xff float32, steps, rows int) RRA

NewAverage returns a new AVERAGE RRA.

func NewDevPredict

func NewDevPredict(rows, idx int) RRA

NewDevPredict returns a new HWPREDICT RRA.

func NewDevSeasonal

func NewDevSeasonal(period int, gamma float32, idx int, window float32) RRA

NewDevSeasonal returns a new HWPREDICT RRA.

func NewFailures

func NewFailures(rows, threshold, window, idx int) RRA

NewFailures returns a new HWPREDICT RRA.

func NewHWPredict

func NewHWPredict(rows int, alpha, beta float32, period int, idx int) RRA

NewHWPredict returns a new HWPREDICT RRA.

func NewLast

func NewLast(xff float32, steps, rows int) RRA

NewLast returns a new AVERAGE RRA.

func NewMHWPredict

func NewMHWPredict(rows int, alpha, beta float32, period int, idx int) RRA

NewMHWPredict returns a new HWPREDICT RRA.

func NewMax

func NewMax(xff float32, steps, rows int) RRA

NewMax returns a new AVERAGE RRA.

func NewMin

func NewMin(xff float32, steps, rows int) RRA

NewMin returns a new MIN RRA.

func NewRRA

func NewRRA(val string) RRA

NewRRA returns a new raw RRA set to val.

func NewSeasonal

func NewSeasonal(period int, gamma float32, idx int, window float32) RRA

NewSeasonal returns a new HWPREDICT RRA.

type Stats

type Stats struct {
	QueueLength     int64
	UpdatesReceived int64
	FlushesReceived int64
	UpdatesWritten  int64
	DataSetsWritten int64
	TreeNodesNumber int64
	TreeDepth       int64
	JournalBytes    int64
	JournalRotate   int64
}

Stats represents rrdcached stats.

type Update

type Update string

Update represents a RRD update value.

func NewUpdate

func NewUpdate(ts time.Time, val interface{}, values ...interface{}) Update

NewUpdate returns a new update with the given ts for the provider values

func NewUpdateNow

func NewUpdateNow(val interface{}, values ...interface{}) Update

NewUpdateNow returns a new update with the current time for the provided values.

func NewUpdateRaw

func NewUpdateRaw(val string) Update

NewUpdateRaw returns a new Update for the raw val. It supports the N: prefix for now times.

Jump to

Keyboard shortcuts

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