zabbix

package module
v0.0.0-...-7e22a38 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2015 License: MIT Imports: 14 Imported by: 0

README

go-zabbix

Golang package, implement zabbix sender protocol for send metrics to zabbix.

Example 1:

package main

import (
    "time"
    . "github.com/blacked/go-zabbix"
)

const (
    defaultHost  = `localhost`
    defaultPort  = `10051`
)

func main() {
    var metrics []*Metric
    metrics = append(metrics, NewMetric("localhost", "cpu", "1.22", time.Now().Unix()))
    metrics = append(metrics, NewMetric("localhost", "status", "OK"))

    // Create instance of Packet class
    packet := NewPacket(metrics)

    // Send packet to zabbix
    z := NewSender(defaultHost, defaultPort)
    z.Send(packet)
}

Example 2:

package main
import (
	"fmt"
	"github.com/andresvia/go-zabbix"
	"time"
)
func main() {
	z := zabbix.NewConfiguredSender()
	for {
		z.SendMetric("time_now_unix", fmt.Sprintf("%v", time.Now().Unix()))
		time.Sleep(time.Second * 1)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metric

type Metric struct {
	Host  string `json:"host"`
	Key   string `json:"key"`
	Value string `json:"value"`
	Clock int64  `json:"clock"`
}

Metric class.

func NewMetric

func NewMetric(host, key, value string, clock ...int64) *Metric

Metric class constructor.

type Packet

type Packet struct {
	Request string    `json:"request"`
	Data    []*Metric `json:"data"`
	Clock   int64     `json:"clock"`
}

Packet class.

func NewPacket

func NewPacket(data []*Metric, clock ...int64) *Packet

Packet class constructor.

func (*Packet) DataLen

func (p *Packet) DataLen() []byte

DataLen Packet class method, return 8 bytes with packet length in little endian order.

type Sender

type Sender struct {
	Host string
	Port string
	// contains filtered or unexported fields
}

Sender class.

func NewBufferedSender

func NewBufferedSender(host, port, defaultTechnicalHostname string, bufferSend time.Duration, bufferSize int) *Sender

Creates a buffered Sender with sendBuffer started, is intended for continous sending

func NewConfiguredSender

func NewConfiguredSender(technical_hostname ...string) *Sender

Creates a Buffered sender using default configuration file, optionally the technical hostname can be set if technical hostname not given will try to load the FQDN from `hostname -f` will use technical name "localhost" if everything fails current defaults if configuration file is not found (default zabbix trapper port is 10051) ServerActive = zabbix BufferSend = 5 (seconds) BufferSize = 100 (metrics)

func NewSender

func NewSender(host, port string) *Sender

Sender class constructor.

func (*Sender) Send

func (s *Sender) Send(packet *Packet) []byte

Method Sender class, send packet to zabbix.

func (*Sender) SendMetric

func (s *Sender) SendMetric(key, value string, clock ...int64) error

SendMetric adds the metric defined by key, value and optionally the UNIX epoch using the default technical hostname, to the Buffered Sender will return error if the Sender is not a Buffered Sender or if the buffer is at maximum capacity, the function should return as soon as possible

Jump to

Keyboard shortcuts

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