func (rs *riemannSink) setupRiemannClient() error { client := riemann_api.NewGorymanClient(rs.config.host) runtime.SetFinalizer(client, func(c riemannClient) { c.Close() }) err := client.Connect() if err != nil { return err } rs.client = client return nil }
func Initialize(logger lager.Logger, riemannAddr string, host string, tags []string, attributes map[string]string) { client := goryman.NewGorymanClient(riemannAddr) riemannClient = client eventHost = host eventTags = tags eventAttributes = attributes go emitLoop() go periodicallyEmit(logger.Session("periodic"), 10*time.Second) }
func main() { cfg, err := config.LoadConfig("./config.toml") if err != nil { fmt.Println(err.Error()) } riemann_client := goryman.NewGorymanClient("localhost:5555") err = riemann_client.Connect() if err != nil { panic(err) } defer riemann_client.Close() for c := range cfg.Checks { go func(chk check.Check) { for { out, status := chk.Run() var state string switch status { case 0: state = "OK" case 1: state = "WARNING" case 2: state = "CRITICAL" default: state = "UNKNOWN" } riemann_client.SendEvent(&goryman.Event{ Service: chk.Service, Tags: append(cfg.GlobalTags, chk.Tags...), State: state, Metric: status, Description: out, Host: chk.Host, Ttl: float32(chk.TTL), }) time.Sleep(time.Duration(chk.Interval) * time.Second) } }(cfg.Checks[c]) } for { time.Sleep(60 * time.Second) } }
func (g *Goshin) Report(reportQueue chan *Metric) { c := goryman.NewGorymanClient(g.Address) defer c.Close() connected := false var connError error for { if connected == false { connError = c.Connect() } if connError != nil { logger.Err(fmt.Sprintf("error : can not connect to host %s", g.Address)) connected = false } else { connected = true } metric := <-reportQueue if connected { g.EnforceState(metric) connError = c.SendEvent(&goryman.Event{ Metric: metric.Value, Ttl: g.Ttl, Service: metric.Service, Description: metric.Description, Tags: g.Tag, Host: g.EventHost, State: metric.State}) if connError != nil { logger.Err(fmt.Sprintf("error : %s", connError)) c.Close() connected = false } } metric = nil } }
func CreateRiemannSink(uri *url.URL, _ extpoints.HeapsterConf) ([]sink_api.ExternalSink, error) { c := riemannConfig{ host: "riemann-heapster:5555", ttl: 60.0, state: "", tags: make([]string, 0), storeEvents: true, } if len(uri.Host) > 0 { c.host = uri.Host } options := uri.Query() if len(options["ttl"]) > 0 { var ttl, err = strconv.ParseFloat(options["ttl"][0], 32) if err != nil { return nil, err } c.ttl = float32(ttl) } if len(options["state"]) > 0 { c.state = options["state"][0] } if len(options["tags"]) > 0 { c.tags = options["tags"] } if len(options["storeEvents"]) > 0 { var storeEvents, err = strconv.ParseBool(options["storeEvents"][0]) if err != nil { return nil, err } c.storeEvents = storeEvents } glog.Infof("Riemann sink URI: '%+v', host: '%+v', options: '%+v', ", uri, c.host, options) rs := &riemannSink{ client: riemann_api.NewGorymanClient(c.host), config: c, } rs.ci = util.NewClientInitializer("riemann", rs.setupRiemannClient, rs.ping, 10*time.Second) runtime.SetFinalizer(rs.client, func(c riemannClient) { c.Close() }) return []sink_api.ExternalSink{rs}, nil }
// NewRiemannPublisher return a publisher to send directly to a riemann instance func NewRiemannPublisher(addr string) RiemannPublisher { p := RiemannPublisher{goryman.NewGorymanClient(addr)} return p }