7999d24f81
this commit updates our monkit dependency to the v3 version where it outputs in an influx style. this makes discovery much easier as many tools are built to look at it this way. graphite and rothko will suffer some due to no longer being a tree based on dots. hopefully time will exist to update rothko to index based on the new metric format. it adds an influx output for the statreceiver so that we can write to influxdb v1 or v2 directly. Change-Id: Iae9f9494a6d29cfbd1f932a5e71a891b490415ff
68 lines
1.2 KiB
Go
68 lines
1.2 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package main
|
|
|
|
import (
|
|
"log"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/zeebo/admission/v2/admproto"
|
|
|
|
"storj.io/common/memory"
|
|
)
|
|
|
|
// Parser is a PacketDest that sends data to a MetricDest
|
|
type Parser struct {
|
|
dest MetricDest
|
|
scratch sync.Pool
|
|
}
|
|
|
|
// NewParser creates a Parser. It sends metrics to dest.
|
|
func NewParser(dest MetricDest) *Parser {
|
|
return &Parser{
|
|
dest: dest,
|
|
scratch: sync.Pool{
|
|
New: func() interface{} {
|
|
var x [10 * memory.KB]byte
|
|
return &x
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
// Packet implements PacketDest
|
|
func (p *Parser) Packet(data []byte, ts time.Time) (err error) {
|
|
data, err = admproto.CheckChecksum(data)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
scratch := p.scratch.Get().(*[10 * memory.KB]byte)
|
|
defer p.scratch.Put(scratch)
|
|
|
|
r := admproto.NewReaderWith((*scratch)[:])
|
|
data, appb, instb, err := r.Begin(data)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
app, inst := string(appb), string(instb)
|
|
var key []byte
|
|
var value float64
|
|
for len(data) > 0 {
|
|
data, key, value, err = r.Next(data)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = p.dest.Metric(app, inst, key, value, ts)
|
|
if err != nil {
|
|
log.Printf("failed to write metric: %v", err)
|
|
continue
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|