mcorbin / riemann-go-client

Riemann Go client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Riemann client (Golang)

Introduction

A Go client library for Riemann.

Features:

  • Idiomatic concurrency
  • Sending events, queries.
  • Support TCP, UDP, TLS clients.

This client is a fork of Goryman, a Riemann go client written by Christopher Gilbert. Thanks and full credit to him!

The initial Goryman repository has been deleted. We've used @rikatz's fork to create this repository.

We've also renamed the client to riemanngo instead of goryman to make its purpose clearer.

Build Status

Build Status

Installation

To install the package for use in your own programs:

go get github.com/riemann/riemann-go-client

If you're a developer, Riemann uses Google Protocol Buffers, so make sure that's installed and available on your PATH.

go get github.com/golang/protobuf/{proto,protoc-gen-go}

Getting Started

First, we'll need to import the library:

import (
    "github.com/riemann/riemann-go-client/"
)

Next, we'll need to establish a new client. The parameter is the connection timeout duration. You can use a TCP client:

c := riemanngo.NewTcpClient("127.0.0.1:5555")
err := c.Connect(5)
if err != nil {
    panic(err)
}

Or a UDP client:

c := riemanngo.NewUdpClient("127.0.0.1:5555")
err := c.Connect(5)
if err != nil {
    panic(err)
}

You can also create a TLS client. The second parameter is the path to your client certificate, the third parameter the path to your client key. The last parameter allows you to create an insecure connection (insecure certificate check). You can find more informations about how to configure TLS in Riemann here.

c := riemanngo.NewTlsClient("127.0.0.1:5554", "/path/to/cert.pem", "/path/to/key.key", true)
err := c.Connect(5)
if err != nil {
    panic(err)
}

Don't forget to close the client connection when you're done:

defer c.Close()

Sending events is easy (list of valid event properties):

result, err := riemanngo.SendEvent(c, &riemanngo.Event{
		Service: "hello",
		Metric:  100,
		Tags: []string{"riemann ftw"},
	})

The host name and time in events will automatically be replaced with the hostname of the server and the current time if none is specified.

You can also send batch of events:

events = []riemanngo.Event {
    riemanngo.Event{
        Service: "hello",
        Metric:  100,
        Tags: []string{"hello"},
    },
riemanngo.Event{
        Service: "goodbye",
        Metric:  200,
        Tags: []string{"goodbye"},
    },
}

You can also query the Riemann index (using the TCP or TLS client):

events, err := c.QueryIndex("service = \"hello\"")
if err != nil {
    panic(err)
}

Tests

You can lauch tests using

make test

and integration tests using:

make integ-test

This command will download Riemann, start it, launch integration tests, and kill it.

You can also use:

go test -tags=integration

if you already have a Riemann instance listening on localhost

Copyright

See LICENSE document

About

Riemann Go client

License:MIT License


Languages

Language:Go 93.2%Language:Protocol Buffer 3.4%Language:Shell 1.7%Language:Makefile 1.7%