telegraf

package module
v0.0.0-...-e4f1649 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2017 License: MIT Imports: 5 Imported by: 5

README

go-telegraf

Build Status Build Status

A golang library to write metrics to telegraf.

Installation

go get -u "github.com/mdaffin/go-telegraf"

Example

package main

import (
	"log"
	"time"

	"github.com/mdaffin/go-telegraf"
)

func main() {
	client, err := telegraf.NewTCP("127.0.0.1:8094")
	if err != nil {
		log.Fatal("could not connect:", err)
	}
	defer client.Close()

	m := telegraf.MeasureFloat64("cpu", "load_avg", 0.5)

	if err := client.Write(m); err != nil {
		log.Fatal("failed to write metric:", err)
	}
}

Documentation

Overview

Writes metrics to telegraf using the socket_listener. It supports the udp, tcp and unix socket connections.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client connects and writes measurements to telegraf.

Example
client, err := telegraf.NewTCP("127.0.0.1:8094")
if err != nil {
	log.Fatal("could not connect:", err)
}
defer func() { _ = client.Close() }()

m := telegraf.MeasureFloat64("cpu", "load_avg", 0.5)

if err := client.Write(m); err != nil {
	log.Fatal("failed to write metric:", err)
}
Output:

func NewTCP

func NewTCP(addr string) (Client, error)

NewTCP client that connects to the telegraf socket_listener plugin with a tcp address.

Example telegraf configuration.

[[inputs.socket_listener]]
  service_address = "tcp://127.0.0.1:8094"

func NewUDP

func NewUDP(addr string) (Client, error)

NewUDP client that connects to the telegraf socket_listener plugin with a udp address.

Example telegraf configuration.

[[inputs.socket_listener]]
  service_address = "udp://127.0.0.1:8094"

func NewUnix

func NewUnix(addr string) (Client, error)

NewUnix client that connects to the telegraf socket_listener plugin with a unix socket.

Example telegraf configuration.

[[inputs.socket_listener]]
  service_address = "unix:///var/run/telegraf.sock"

func (*Client) Close

func (c *Client) Close() error

Close the connection to telegraf.

func (*Client) Write

func (c *Client) Write(m Measurement) error

Write a metric to telegraf.

func (*Client) WriteAll

func (c *Client) WriteAll(m []Measurement) error

Write a list of metrics to telegraf.

type Measurement

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

Measurement that can be sent to influxdb or telegraf. The measurement consists of three parts, the name of the metric, a set of fields and their values, optional tags and a timestamp.

Example
_ = telegraf.MeasureInt("app", "request_size", 5042).AddString("error", "somethine went wrong").AddTag("path", "/api/testing")
Output:

Example (Complex)
m := telegraf.MeasureInt("app", "request_size", 5042).AddTag("path", "/api/testing")
start := time.Now()
time.Sleep(time.Millisecond * 100)
m = m.AddMillisecondsSince("request_time", start).AddInt("response_size", 3045).AddTag("status_code", "200")
Output:

func MeasureBool

func MeasureBool(name string, field string, value bool) Measurement

MeasureBool creates a new measurement with the given bool field.

func MeasureFloat32

func MeasureFloat32(name string, field string, value float32) Measurement

MeasureFloat32 creates a new measurement with the given float32 field.

func MeasureFloat64

func MeasureFloat64(name string, field string, value float64) Measurement

MeasureFloat64 creates a new measurement with the given float64 field.

func MeasureHoursSince

func MeasureHoursSince(name string, field string, t time.Time) Measurement

MeasureHoursSince creates a new measurement with the given float64 field.

func MeasureInt

func MeasureInt(name string, field string, value int) Measurement

MeasureInt creates a new measurement with the given int field.

func MeasureInt16

func MeasureInt16(name string, field string, value int16) Measurement

MeasureInt16 creates a new measurement with the given int16 field.

func MeasureInt32

func MeasureInt32(name string, field string, value int32) Measurement

MeasureInt32 creates a new measurement with the given int32 field.

func MeasureInt64

func MeasureInt64(name string, field string, value int64) Measurement

MeasureInt64 creates a new measurement with the given int64 field.

func MeasureInt8

func MeasureInt8(name string, field string, value int8) Measurement

MeasureInt8 creates a new measurement with the given int8 field.

func MeasureMillisecondsSince

func MeasureMillisecondsSince(name string, field string, t time.Time) Measurement

MeasureMillisecondsSince creates a new measurement with the given float64 field.

func MeasureMinutesSince

func MeasureMinutesSince(name string, field string, t time.Time) Measurement

MeasureMinutesSince creates a new measurement with the given float64 field.

func MeasureNanosecondsSince

func MeasureNanosecondsSince(name string, field string, t time.Time) Measurement

MeasureNanosecondsSince creates a new measurement with the given uint64 field.

func MeasureSecondsSince

func MeasureSecondsSince(name string, field string, t time.Time) Measurement

MeasureSecondsSince creates a new measurement with the given float64 field.

func MeasureString

func MeasureString(name string, field string, value string) Measurement

MeasureString creates a new measurement with the given string field.

func MeasureUInt

func MeasureUInt(name string, field string, value uint) Measurement

MeasureUInt creates a new measurement with the given uint field.

func MeasureUInt16

func MeasureUInt16(name string, field string, value uint16) Measurement

MeasureUInt16 creates a new measurement with the given uint16 field.

func MeasureUInt32

func MeasureUInt32(name string, field string, value uint32) Measurement

MeasureUInt32 creates a new measurement with the given uint32 field.

func MeasureUInt64

func MeasureUInt64(name string, field string, value uint64) Measurement

MeasureUInt64 creates a new measurement with the given uint64 field.

func MeasureUInt8

func MeasureUInt8(name string, field string, value uint8) Measurement

MeasureUInt8 creates a new measurement with the given uint8 field.

func NewMeasurement

func NewMeasurement(name string) Measurement

NewMeasurement creates a blank measurement without any fields, you must add a field before trying to send it to telegraf using on of the Add* methods. This is useful when you want to add tags before you have a field measurement avaiable.

func (Measurement) AddBool

func (m Measurement) AddBool(name string, value bool) Measurement

AddBool field called name.

func (Measurement) AddFloat32

func (m Measurement) AddFloat32(name string, value float32) Measurement

AddFloat32 field called name.

func (Measurement) AddFloat64

func (m Measurement) AddFloat64(name string, value float64) Measurement

AddFloat64 field called name.

func (Measurement) AddHoursSince

func (m Measurement) AddHoursSince(name string, t time.Time) Measurement

AddHoursSince t as the field called name stored as a float64.

func (Measurement) AddInt

func (m Measurement) AddInt(name string, value int) Measurement

AddInt field called name.

func (Measurement) AddInt16

func (m Measurement) AddInt16(name string, value int16) Measurement

AddInt16 field called name.

func (Measurement) AddInt32

func (m Measurement) AddInt32(name string, value int32) Measurement

AddInt32 field called name.

func (Measurement) AddInt64

func (m Measurement) AddInt64(name string, value int64) Measurement

AddInt64 field called name.

func (Measurement) AddInt8

func (m Measurement) AddInt8(name string, value int8) Measurement

AddInt8 field called name.

func (Measurement) AddMillisecondsSince

func (m Measurement) AddMillisecondsSince(name string, t time.Time) Measurement

AddMillisecondsSince t as the field called name stored as a float64.

func (Measurement) AddMinutesSince

func (m Measurement) AddMinutesSince(name string, t time.Time) Measurement

AddMinutesSince t as the field called name stored as a float64.

func (Measurement) AddNanosecondsSince

func (m Measurement) AddNanosecondsSince(name string, t time.Time) Measurement

AddNanosecondsSince t as the field called name stored as an uint64.

func (Measurement) AddSecondsSince

func (m Measurement) AddSecondsSince(name string, t time.Time) Measurement

AddSecondsSince t as the field called name stored as a float64.

func (Measurement) AddString

func (m Measurement) AddString(name string, value string) Measurement

AddString field called name.

func (Measurement) AddTag

func (m Measurement) AddTag(name string, value string) Measurement

AddTag to the measurement. Tags are global for all fields in this measurement - if you want them to have differenent tags you must create a second measurement with the alternate tags.

func (Measurement) AddTags

func (m Measurement) AddTags(tags map[string]string) Measurement

AddTags to the measurement. Tags are global for all fields in this measurement - if you want them to have differenent tags you must create a second measurement with the alternate tags.

func (Measurement) AddUInt

func (m Measurement) AddUInt(name string, value uint) Measurement

AddUInt field called name.

func (Measurement) AddUInt16

func (m Measurement) AddUInt16(name string, value uint16) Measurement

AddUInt16 field called name.

func (Measurement) AddUInt32

func (m Measurement) AddUInt32(name string, value uint32) Measurement

AddUInt32 field called name.

func (Measurement) AddUInt64

func (m Measurement) AddUInt64(name string, value uint64) Measurement

AddUInt64 field called name.

func (Measurement) AddUInt8

func (m Measurement) AddUInt8(name string, value uint8) Measurement

AddUInt8 field called name.

func (Measurement) Name

func (m Measurement) Name() string

Name of the measurement.

func (Measurement) SetTime

func (m Measurement) SetTime(time time.Time) Measurement

SetTime of the measurement. The default is time.Now(), this can be used to override the default. Set it to a zero time to unset the time, which will cause telegraf or influxdb to set the time when they recieve the measurement instead.

func (Measurement) ToLineProtocal

func (m Measurement) ToLineProtocal() string

ToLineProtocal converts the metric to the influxdb line protocal.

Jump to

Keyboard shortcuts

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