package module
Version: v1.0.0 Latest Latest

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

Go to latest
Published: Mar 21, 2016 License: BSD-3-Clause Imports: 6 Imported by: 25



This is yet another implementation of a collectd binary protocol parser in Go, heavenly inspired by gocollectd.


go get github.com/kimor79/gollectd


import (
    collectd github.com/kimor79/gollectd

types, err := collectd.TypesDBFile("/path/to/types.db")

buffer := make([]byte, 1452)
n, _, err := socket.ReadFromUDP(buffer)
packets, err := collectd.Packets(buffer[:n], types)



Parse data from the collectd network plugin This is modeled after collectd's own network.c



View Source
const (
	TypeCounter  = 0
	TypeGauge    = 1
	TypeDerive   = 2
	TypeAbsolute = 3
View Source
const (
	ParseHost           = 0x0000
	ParseTime           = 0x0001
	ParsePlugin         = 0x0002
	ParsePluginInstance = 0x0003
	ParseType           = 0x0004
	ParseTypeInstance   = 0x0005
	ParseValues         = 0x0006
	ParseInterval       = 0x0007
	ParseTimeHR         = 0x0008
	ParseIntervalHR     = 0x0009

	// Notifications
	ParseMessage  = 0x0100
	ParseSeverity = 0x0101

	ParseSignature  = 0x0200
	ParseEncryption = 0x0210


View Source
var ErrorInvalid = errors.New("Invalid packet")
View Source
var ErrorUnknownDataType = errors.New("Unknown data source type")
View Source
var ErrorUnknownType = errors.New("Unknown value type")
View Source
var ErrorUnsupported = errors.New("Unsupported packet")
View Source
var ValueTypeNames = map[string]uint8{
	"absolute": TypeAbsolute,
	"counter":  TypeCounter,
	"derive":   TypeDerive,
	"gauge":    TypeGauge,
View Source
var ValueTypeValues = map[uint8]string{
	TypeAbsolute: "absolute",
	TypeCounter:  "counter",
	TypeDerive:   "derive",
	TypeGauge:    "gauge",


func Packets

func Packets(b []byte, types Types) (*[]Packet, error)


type Packet

type Packet struct {
	Hostname       string
	Interval       uint64
	IntervalHR     uint64
	Plugin         string
	PluginInstance string
	Time           uint64
	TimeHR         uint64
	Type           string
	TypeInstance   string
	Values         []Value

func (Packet) FormatName

func (p Packet) FormatName() string

type Type

type Type struct {
	Name string
	Type uint8
	Min  string
	Max  string

func ParseDataSet

func ParseDataSet(s string) (string, []*Type, error)

ParseDataSet parses one line from a collectd types.db file and returns the data-set name & a Type struct

type Types

type Types map[string][]*Type

func TypesDB

func TypesDB(b []byte) (Types, error)

func TypesDBFile

func TypesDBFile(path string) (Types, error)

type Value

type Value struct {
	Name     string
	Type     uint8
	TypeName string
	Value    float64

Source Files


Path Synopsis

Jump to

Keyboard shortcuts

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