goryman

package
v1.1.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2016 License: MIT, Apache-2.0 Imports: 11 Imported by: 0

README

Riemann client (Golang)

GoDoc

Introduction

Go client library for Riemann.

This client library was inspired by Raidman, and Riemann NodeJS Client.

Features:

  • Idiomatic concurrency
  • Sending events, state updates, queries.
  • Feature parity with the reference implementation written in Ruby.

Installation

To install the package for use in your own programs:

go get github.com/bigdatadev/goryman

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/bigdatadev/goryman"
)

Next we'll need to establish a new client:

c := goryman.NewGorymanClient("localhost:5555")
err := c.Connect()
if err != nil {
    panic(err)
}

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

defer c.Close()

Just like the Riemann Ruby client, the client sends small events over UDP by default. TCP is used for queries, and large events. There is no acknowledgement of UDP packets, but they are roughly an order of magnitude faster than TCP. We assume both TCP and UDP are listening on the same port.

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

err = c.SendEvent(&goryman.Event{
    Service: "moargore",
    Metric:  100,
    Tags: []string{"nonblocking"},
})
if err != nil {
    panic(err)
}

You can also query events:

events, err := c.QueryEvents("host = \"goryman\"")
if err != nil {
    panic(err)
}

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

Integrations

Martini: GoryMartini

Contributing

Just send me a pull request. Please take a look at the project issues and see how you can help. Here are some tips:

  • please add more tests.
  • please check your syntax.

Author

Christopher Gilbert

See LICENSE document

Documentation

Overview

A Riemann client for Go, featuring concurrency, sending events and state updates, queries, and feature parity with the reference implementation written in Ruby.

Copyright (C) 2014 by Christopher Gilbert <christopher.john.gilbert@gmail.com>

Index

Constants

View Source
const MAX_UDP_SIZE = 16384

MAX_UDP_SIZE is the maximum allowed size of a UDP packet before automatically failing the send

Variables

This section is empty.

Functions

func EventToProtocolBuffer

func EventToProtocolBuffer(event *Event) (*proto.Event, error)

EventToProtocolBuffer converts an Event type to a proto.Event

func StateToProtocolBuffer

func StateToProtocolBuffer(state *State) (*proto.State, error)

StateToProtocolBuffer converts a State type to a proto.State

Types

type Event

type Event struct {
	Ttl         float32
	Time        int64
	Tags        []string
	Host        string // Defaults to os.Hostname()
	State       string
	Service     string
	Metric      interface{} // Could be Int, Float32, Float64
	Description string
	Attributes  map[string]string
}

Event is a wrapper for Riemann events

func ProtocolBuffersToEvents

func ProtocolBuffersToEvents(pbEvents []*proto.Event) []Event

ProtocolBuffersToEvents converts an array of proto.Event to an array of Event

type GorymanClient

type GorymanClient struct {
	// contains filtered or unexported fields
}

GorymanClient is a client library to send events to Riemann

func NewGorymanClient

func NewGorymanClient(addr string) *GorymanClient

NewGorymanClient - Factory

func (*GorymanClient) Close

func (c *GorymanClient) Close() error

Close the connection to Riemann

func (*GorymanClient) Connect

func (c *GorymanClient) Connect() error

Connect creates a UDP and TCP connection to a Riemann server

func (*GorymanClient) QueryEvents

func (c *GorymanClient) QueryEvents(q string) ([]Event, error)

Query the server for events

func (*GorymanClient) SendEvent

func (c *GorymanClient) SendEvent(e *Event) error

Send an event

func (*GorymanClient) SendState

func (c *GorymanClient) SendState(s *State) error

Send a state update

type State

type State struct {
	Ttl         float32
	Time        int64
	Tags        []string
	Host        string // Defaults to os.Hostname()
	State       string
	Service     string
	Once        bool
	Metric      interface{} // Could be Int, Float32, Float64
	Description string
	Attributes  map[string]string
}

State is a wrapper for Riemann states

type TcpTransport

type TcpTransport struct {
	// contains filtered or unexported fields
}

TcpTransport is a type that implements the Transport interface

func NewTcpTransport

func NewTcpTransport(conn net.Conn) *TcpTransport

NewTcpTransport - Factory

func (*TcpTransport) Close

func (t *TcpTransport) Close() error

Close will close the TcpTransport

func (*TcpTransport) SendMaybeRecv

func (t *TcpTransport) SendMaybeRecv(message *proto.Msg) (*proto.Msg, error)

TcpTransport implementation of SendMaybeRecv, queues a request to send a message to the server

func (*TcpTransport) SendRecv

func (t *TcpTransport) SendRecv(message *proto.Msg) (*proto.Msg, error)

TcpTransport implementation of SendRecv, queues a request to send a message to the server

type Transport

type Transport interface {
	SendRecv(message *proto.Msg) (*proto.Msg, error)
	SendMaybeRecv(message *proto.Msg) (*proto.Msg, error)
}

Transport is an interface to a generic transport used by the client

type UdpTransport

type UdpTransport struct {
	// contains filtered or unexported fields
}

UdpTransport is a type that implements the Transport interface

func NewUdpTransport

func NewUdpTransport(conn net.Conn) *UdpTransport

NewUdpTransport - Factory

func (*UdpTransport) Close

func (t *UdpTransport) Close() error

Close will close the UdpTransport

func (*UdpTransport) SendMaybeRecv

func (t *UdpTransport) SendMaybeRecv(message *proto.Msg) (*proto.Msg, error)

UdpTransport implementation of SendMaybeRecv, queues a request to send a message to the server

func (*UdpTransport) SendRecv

func (t *UdpTransport) SendRecv(message *proto.Msg) (*proto.Msg, error)

UdpTransport implementation of SendRecv, will automatically fail if called

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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