Documentation ¶
Overview ¶
Package graphigo provides a simple go client for the graphite monitoring tool. See http://graphite.readthedocs.org/en/latest/overview.html
Example ¶
c := graphigo.NewClient("graphite.your.org:2003") c.Connection = newConnectionMock() // set a custom timeout (seconds) for the graphite connection // if timeout = 0 then the graphigo.DefaultTimeout = 5 seconds is used // Setting Timeout to -1 disables the timeout c.Timeout = 0 // set a custom prefix for all recorded metrics of this client (optional) c.Prefix = "foo.bar.baz" if err := c.Connect(); err != nil { panic(err) } // close the TCP connection properly if you don't need it anymore defer c.Close() // capture and send values using a single line c.SendValue("hello.graphite.world", 42) // capture a metric and send it any time later metric := graphigo.Metric{Name: "test", Value: 3.14} // you can use any type as value defer c.Send(metric) // create a whole bunch of metrics and send them all with one TCP call c.SendAll([]graphigo.Metric{ {Name: "shut", Value: 1}, {Name: "up", Value: 2}, {Name: "and", Value: 3}, {Name: "take", Value: 4}, {Name: "my", Value: 5}, {Name: "money", Value: 6}, })
Output:
Index ¶
Examples ¶
Constants ¶
const ( // DefaultTimeout is the timeout that is applied when connecting to a graphite server. // It is used if no explicit timeout has been configured on a client. DefaultTimeout = 5 // TimeoutDisabled is used to disable the client timeout entirely. TimeoutDisabled = -1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // Address is used when connecting to the graphite server. Use address:port notation. Address string // Timeout is the maximum duration that the client will wait for a response from the server. // If timeout is zero then the DefaultTimeout is used. // Setting Timeout to -1 disables the timeout. Timeout time.Duration // Prefix is prepended to all metric names (separated from original name by a dot). // If Prefix is empty this does nothing. Prefix string // Connection is used to communicate with the graphite client. // You would normally not interfere with this but this can be handy for testing. Connection io.WriteCloser }
Client is a simple TCP client for the graphite monitoring tool.
func NewClient ¶
NewClient creates a new instance of a graphite client. Use the address:port notation to specify the port. Note that the client will not connect to the given address automatically. You still need to call Connect() before you can start sending values.
func (*Client) Close ¶
Close implements the io.Closer interface by closing the clients Connection. If c is nil this will do nothing (noop)
func (*Client) Connect ¶
Connect attempts to establish the connection to the graphite server. This will return an error if a TCP connection can not or has already been established.
If c is nil this will do nothing (noop)
func (*Client) Send ¶
Send sends a graphigo.Metric to graphite. This can be used to send a metric which has been recorded earlier.
Use `SendValue` if you want to create and send a metric in one step. Use `SendAll` if you want to send multiple metrics at once. This will return an error if the client has not yet been connected or the metric name is empty.
If c is nil this will do nothing (noop)
func (*Client) SendAll ¶
SendAll sends multiple graphigo.Metric to graphite. This can be used to send multiple metrics that have been recorded earlier.
Use `Send` if you want to send a single metric. If the client has not yet been connected or if any of the metrics has an empty name this function will return an error.
If c is nil this will do nothing (noop)
func (*Client) SendValue ¶
SendValue creates a new graphigo.Metric with the metric timestamp set to now and sends it to graphite.
Use `Send(Metric)` if you want to split metric recording and sending. This will return an error if the client has not yet been connected or the metric name is empty.
If c is nil this will do nothing (noop)
type Metric ¶
type Metric struct { // The Name of the metric. Name string // The Value of this metric. The client uses %v to format this. Value interface{} // Timestamp represents the time when this metric was recorded. // If this is the zero value the client will assume time.Now() Timestamp time.Time }
Metric holds all information that is send to graphite. The value can be any go type but in practice graphite will probably only accept numeric values.
func (Metric) UnixTimestamp ¶
UnixTimestamp returns the the number of seconds elapsed since January 1, 1970 UTC. If the metrics timestamp is zero it will return time.Now().Unix()