metrics

package
v0.0.0-...-29379b6 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2015 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmitMetric

func EmitMetric(time string, tags []string, metric string, value string, clients map[chan Metric]bool)

func ParseMetrics

func ParseMetrics(statsChannel chan map[string]map[string]string, clients map[chan Metric]bool, wantedMetrics []string)

Types

type KafkaProducer

type KafkaProducer struct {
	Log *gologger.Logger
	// contains filtered or unexported fields
}

func (*KafkaProducer) In

func (k *KafkaProducer) In(c chan Metric)

func (*KafkaProducer) Start

func (k *KafkaProducer) Start(host string, port int)

type Metric

type Metric struct {
	Tags      []string `json:"tags"`
	Value     int      `json:"value"`
	Timestamp string   `json:"timestamp"`
	Type      string   `json:"type"`
}

type MetricsProducer

type MetricsProducer interface {
	Consume(c chan Metric)
	Init()
	Produce()
}

type SSEBroker

type SSEBroker struct {

	// Create a map of Clients, the keys of the map are the channels
	// over which we can push messages to attached Clients.  (The values
	// are just booleans and are meaningless.)
	//
	Clients map[chan Metric]bool

	// Channel into which new Clients can be pushed
	//
	NewClients chan chan Metric

	// Channel into which disconnected Clients should be pushed
	//
	DefunctClients chan chan Metric

	// Channel into which messages are pushed to be broadcast out
	// to attahed Clients.
	//
	MetricsChannel chan Metric

	// the central logger
	Log *gologger.Logger
}

The SSEBroker is responsible for keeping a list of which Clients (browsers) are currently attached and broadcasting events (messages) to those Clients.

func (*SSEBroker) ServeHTTP

func (b *SSEBroker) ServeHTTP(w http.ResponseWriter, r *http.Request)

This SSEBroker method handles and HTTP request at the "/events/" URL.

func (*SSEBroker) Start

func (b *SSEBroker) Start()

This SSEBroker method starts a new goroutine. It handles the addition & removal of Clients, as well as the broadcasting of messages out to Clients that are currently attached.

type SimpleProducer

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

a very simple producer. It consumes the metrics stream and produces output on stdout in JSON format.

func (*SimpleProducer) In

func (s *SimpleProducer) In(c chan Metric)

func (*SimpleProducer) Start

func (s *SimpleProducer) Start()

type Streamer

type Streamer struct {
	Clients map[chan Metric]bool
	Log     *gologger.Logger
	// contains filtered or unexported fields
}

func NewStreamer

func NewStreamer(haRuntime *haproxy.Runtime, frequency int, log *gologger.Logger) *Streamer

Just sets the metrics we want for now...

func (*Streamer) AddClient

func (s *Streamer) AddClient(c chan Metric)

Adds a client to which messages can be multiplexed.

func (*Streamer) Start

func (s *Streamer) Start()

simple wrapper for the actual start command.

func (*Streamer) StartProtected

func (s *Streamer) StartProtected()

Generates an outgoing stream of discrete Metric struct values. This stream can then be consumed by other streams like Kafka or SSE. It also protects against crashes by recovering panics and restarting the routine again.

Jump to

Keyboard shortcuts

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