Documentation
¶
Overview ¶
Package olbermann is a reporter. Give it a metrics struct with tags, and it will report those metrics for you.
Define a struct with tags "type" indicating what kind of data is there, and "report" requesting that a set of quantities be reported.
Example:
type ReportableMetric struct {
Transactions int64 `type:"counter" report:"iter,cum"`
Faults int64 `type:"counter" report:"cum,total"`
ProcessingTime float64 `type:"latency" report:"w50,w90,c90,c99,c99.9"`
}
Then just send ReportableMetric objects or pointers down a channel, olbermann will take care of the rest.
Example ¶
This is not a perfect example, because we can't rely on clocks to generate the right output. So we use a log.Logger that doesn't print times, and we don't use the iter or cum report types on large values in this example. Also, EWMA values take 10 samples to start reporting.
c := make(chan interface{}, 10)
r := &Reporter{C: c}
go r.Feed()
if err := r.Start(exampleValueSet{}, &DstatStyler{Period: time.Second, LinesBetweenHeaders: 0, Logger: log.New(os.Stdout, "example: ", 0)}); err != nil {
return
}
defer r.Close()
gen(c)
close(c)
Output: example: ----------- a ------------ ------------------ b ------------------ example: iter total | ewma1 cum total example: 2.00 2 | 0.00 2.00 2 example: 1.00 4 | 0.00 2.00 4 example: 1.00 7 | 0.00 2.33 7 example: 0.50 9 | 0.00 2.25 9
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var BasicDstatStyler = DstatStyler{Period: time.Second, LinesBetweenHeaders: 24, Logger: log.New(os.Stdout, "", log.LstdFlags)}
A Styler that produces good default output similar to dstat, to standard out, with timestamps, once per second, with headers every 24 lines.
Functions ¶
This section is empty.
Types ¶
type CsvStyler ¶
type CsvStyler struct {
Period time.Duration // How often to print
Writer *bufio.Writer // A writer to print to
}
CsvStyler is a Styler that produces output in csv format.
type DstatStyler ¶
type DstatStyler struct {
Period time.Duration // How often to print
LinesBetweenHeaders int // After how many lines to print header info
Logger *log.Logger // A logger to print to
}
DstatStyler is a Styler that produces output similar to dstat.
type Reporter ¶
type Reporter struct {
C <-chan interface{}
// contains filtered or unexported fields
}
A Reporter represents a central point to collect a metric stream.
Must create with C a channel of structs or pointers to structs defined with tags explaining the metrics to track and how to report them.
Can Start() multiple reporting goroutines off the same Reporter.
Must invoke Feed() on a goroutine to pull metrics off the stream.
Usage:
type ReportableMetric struct {
Ips int64 `type:"counter" report:"iter,cum"`
Ups int64 `type:"counter" report:"iter,cum"`
X float64 `type:"counter" report:"total"`
}
{
metricChannel := make(chan interface{}, 100)
r := olbermann.Reporter{C: metricChannel}
go r.Feed()
if err := r.Start(ReportableMetric{}, &olbermann.BasicDstatStyler); err != nil {
return
}
defer r.Close()
for i := 0; i < 100; i++ {
metricChannel <- &ReportableMetric{1000, 20, 0.5}
}
}
func (*Reporter) Feed ¶
func (r *Reporter) Feed()
Feed is a long-running function that consumes input to the reporter's channel until the channel is closed.
Should be done on a goroutine.
func (*Reporter) Start ¶
Start creates a goroutine printing the Reporter's metrics according to the provided Styler.
You must call Close later.
Needs a sample object to initialize some state, the zero value for the metric will do.
Usage:
if err := r.Start(ReportableMetric{}, &BasicDstatStyler); err != nil {
return
}
defer r.Close()
