gmetric

package
v0.0.0-...-1a92b66 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2015 License: BSD-3-Clause Imports: 9 Imported by: 8

Documentation

Overview

Package gmetric provides a client for the ganglia gmetric API.

Example
package main

import (
	"fmt"
	"net"
	"os"
	"time"

	"github.com/facebookgo/ganglia/gmetric"
)

func main() {
	// A Client can connect to multiple addresses.
	client := &gmetric.Client{
		Addr: []net.Addr{
			&net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8649},
		},
	}

	// You only need to Open the connections once on application startup.
	if err := client.Open(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// Defines the Metric.
	metric := &gmetric.Metric{
		Name:         "web_requests",
		Title:        "Number of Web Requests",
		Host:         "web0.app.com",
		ValueType:    gmetric.ValueUint32,
		Units:        "count",
		Slope:        gmetric.SlopeBoth,
		TickInterval: 20 * time.Second,
		Lifetime:     24 * time.Hour,
	}

	// Meta packets only need to be sent every `send_metadata_interval` as
	// configured in gmond.conf.
	if err := client.WriteMeta(metric); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	if err := client.WriteValue(metric, 1); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// Close the connections before terminating your application.
	if err := client.Close(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
Output:

Index

Examples

Constants

View Source
const (
	SlopeZero     = slopeType("zero")
	SlopePositive = slopeType("positive")
	SlopeNegative = slopeType("negative")
	SlopeBoth     = slopeType("both")
)

The slope types supported by Ganglia.

View Source
const (
	ValueString  = valueType("string")
	ValueUint8   = valueType("uint8")
	ValueInt8    = valueType("int8")
	ValueUint16  = valueType("uint16")
	ValueInt16   = valueType("int16")
	ValueUint32  = valueType("uint32")
	ValueInt32   = valueType("int32")
	ValueFloat32 = valueType("float")
	ValueFloat64 = valueType("double")
)

The value types supported by Ganglia.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	io.Writer

	// The target addresses or in gmond.conf parlance the udp_send_channels.
	Addr []net.Addr

	// The actual hostname for the machine. If empty the default will be set
	// based on os.Hostname.
	Host string

	// Optional spoof name for the machine. Since the default is reverse DNS this
	// allows for overriding the hostname to make it useful.
	Spoof string

	// Also known as TMax, it defines the max time interval between which the
	// daemon will expect updates. This should map to how often you publish the
	// metric.
	TickInterval time.Duration

	// Also known as DMax, it defines the lifetime for the metric. That is, once
	// the last received metric is older than the defined value it will become
	// eligible for garbage collection.
	Lifetime time.Duration
	// contains filtered or unexported fields
}

A Client represents a set of connections to write metrics to. The Client is itself a Writer which writes the given bytes to all open connections.

func ClientFromFlag

func ClientFromFlag(name string) *Client

ClientFromFlag defines a new Client via Flags. Note you must call client.Open() before using it.

func (*Client) Close

func (c *Client) Close() error

Close the connections. If an error is returned it will be a MultiError.

func (*Client) Open

func (c *Client) Open() error

Open the connections. If an error is returned it will be a MultiError.

func (*Client) WriteMeta

func (c *Client) WriteMeta(m *Metric) error

WriteMeta writes the Metric metadata.

func (*Client) WriteValue

func (c *Client) WriteValue(m *Metric, val interface{}) error

WriteValue writes a value for the Metric.

type Metric

type Metric struct {
	// The name is used as the file name, and also the title unless one is
	// explicitly provided.
	Name string

	// The title is for human consumption and is shown atop the graph.
	Title string

	// Descriptions serve as documentation.
	Description string

	// The groups ensure your metric is kept alongside sibling metrics.
	Groups []string

	// The units are shown in the graph to provide context to the numbers.
	Units string

	// The actual hostname for the machine.
	Host string

	// Optional spoof name for the machine. Since the default is reverse DNS this
	// allows for overriding the hostname to make it useful.
	Spoof string

	// Defines the value type. You must specify one of the predefined constants.
	ValueType valueType

	// Defines the slope type. You must specify one of the predefined constants.
	Slope slopeType

	// Also known as TMax, it defines the max time interval between which the
	// daemon will expect updates. This should map to how often you publish the
	// metric.
	TickInterval time.Duration

	// Also known as DMax, it defines the lifetime for the metric. That is, once
	// the last received metric is older than the defined value it will become
	// eligible for garbage collection.
	Lifetime time.Duration
}

Metric configuration.

type MultiError

type MultiError []error

MultiError represents a collection of errors.

func (MultiError) Error

func (m MultiError) Error() string

Returns a concatenation of all the contained errors.

Directories

Path Synopsis
Package gmc is a light weight clone of the gmetric CLI.
Package gmc is a light weight clone of the gmetric CLI.

Jump to

Keyboard shortcuts

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