Documentation
¶
Overview ¶
Example of using the graphiteNop feature in action:
package mylib import ( "github.com/marpaia/graphite-golang" "log" ) func init() { // load your configuration file / mechanism config := newConfig() // try to connect a graphite server if config.GraphiteEnabled { Graphite, err = graphite.NewGraphite(config.Graphite.Host, config.Graphite.Port) } else { Graphite = graphite.NewGraphiteNop(config.Graphite.Host, config.Graphite.Port) } // if you couldn't connect to graphite, use a nop if err != nil { Graphite = graphite.NewGraphiteNop(config.Graphite.Host, config.Graphite.Port) } log.Printf("Loaded Graphite connection: %#v", Graphite) Graphite.SimpleSend("stats.graphite_loaded", 1) } func doWork() { // this will work just fine, regardless of if you're working with a graphite // nop or not Graphite.SimpleSend("stats.doing_work", 1) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Graphite ¶
type Graphite struct { Host string Port int Timeout time.Duration // contains filtered or unexported fields }
Graphite is a struct that defines the relevant properties of a graphite connection
func NewGraphite ¶
NewGraphiteHost is a factory method that's used to create a new Graphite connection given a hostname and a port number
func NewGraphiteNop ¶
NewGraphiteNop is a factory method that returns a Graphite struct but will not actually try to send any packets to a remote host and, instead, will just log. This is useful if you want to use Graphite in a project but don't want to make Graphite a requirement for the project.
func (*Graphite) Connect ¶
Given a Graphite struct, Connect populates the Graphite.conn field with an appropriate TCP connection
func (*Graphite) SendMetric ¶
Given a Metric struct, the SendMetric method sends the supplied metric to the Graphite connection that the method is called upon