relay

package
Version: v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2016 License: MPL-2.0 Imports: 8 Imported by: 0

README

pulse logo
Build Status

Pulse

Pulse is a stat collecting and publishing service. It serves historical stats over an http api while live stats are sent to mist for live updates.

Client Example:

package main

import (
  "fmt"
  "math/rand"
  "os"
  "os/exec"
  "strconv"
  "time"

  // if we want to see pulse client logs
  "github.com/jcelliott/lumber"

  pulse "github.com/nanopack/pulse/relay"
)

// address of pulse server
var address = "127.0.0.1:3000"

func main() {
  // because we want to see all pulse client logs
  lumber.Level(lumber.LvlInt("TRACE"))

  // returns system command getter for cpu-used
  var cpuGetter = func() float64 {
    raw, err := exec.Command("bash", "-c", "cat /proc/stat | awk '/cpu / {usage=($2+$4)/($2+$4+$5)} END {print usage}' | tr -d '\n'").Output()
    if err != nil {
      return -1
    }
    floatData, _ := strconv.ParseFloat(string(raw), 64)
    return floatData
  }

  // returns golang func for mock ram-used
  var ramGetter = rand.Float64

  // register a new client
  relay, err := pulse.NewRelay(address, "lester.tester")
  if err != nil {
    fmt.Printf("Unable to connect to pulse server %v\n", err)
    return
  }
  defer relay.Close()

  // add new cpu collector for a container
  cpuCollector := pulse.NewPointCollector(cpuGetter)
  if err := relay.AddCollector("cpu_used", []string{"","service:web1"}, cpuCollector); err != nil {
    fmt.Println(err)
    os.Exit(1)
  }

  // a ram collector for the host
  ramCollector := pulse.NewPointCollector(ramGetter)
  if err := relay.AddCollector("ram_used", nil, ramCollector); err != nil {
    fmt.Println(err)
    os.Exit(1)
  }

  // keep it running for a while
  time.Sleep(time.Minute * 30)
}

open source

Documentation

Overview

Package provides the client the ability to connect to pulse and add metrics/stats to be collected.

Index

Constants

This section is empty.

Variables

View Source
var (
	UnableToIdentify   = errors.New("unable to identify with pulse")
	ReservedName       = errors.New("cannot use - or : or , or _connected in your name")
	DuplicateCollector = errors.New("cannot add a duplicate collector to the set")
)

Functions

This section is empty.

Types

type Collector

type Collector interface {
	Collect() map[string]float64
}

Collector is a stat to be collected

func NewPointCollector

func NewPointCollector(pf func() float64) Collector

func NewSetCollector

func NewSetCollector(sf collectorHandle) Collector

type Relay

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

Relay is a pulse client

func NewRelay

func NewRelay(address, id string) (*Relay, error)

NewRelay creates a new relay

func (*Relay) AddCollector

func (relay *Relay) AddCollector(name string, tags []string, collector Collector) error

AddCollector adds a collector to relay

func (*Relay) Close

func (relay *Relay) Close() error

func (*Relay) Info

func (relay *Relay) Info() map[string]float64

func (*Relay) RemoveCollector

func (relay *Relay) RemoveCollector(name string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL