zabbix

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: Apache-2.0 Imports: 9 Imported by: 1

README

PkgGoDev GoReportCard GitHub Actions CI Status GitHub Actions CodeQL Status Coverage Status Codebeat badge

InstallationZabbix version supportBuild StatusLicense


zabbix is a Go package for sending metrics data to Zabbix Server 3+.

Installation

Make sure you have a working Go 1.17+ workspace (instructions), then:

go get -d github.com/essentialkaos/go-zabbix

For update to the latest stable release, do:

go get -d -u github.com/essentialkaos/go-zabbix

Zabbix version support

Zabbix Version Support Status
1.x No
2.x No
3.x Yes (Full)
4.x Yes (Full)
5.x Yes (Full)
6.x Yes (Full)

Build Status

Branch Status
master CI
develop CI

License

Apache License, Version 2.0

Documentation

Overview

Package zabbix provides client for sending metrics to Zabbix Server 3+

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Hostname string

	ConnectTimeout time.Duration
	WriteTimeout   time.Duration
	ReadTimeout    time.Duration
	// contains filtered or unexported fields
}

Client is Zabbix client

func NewClient

func NewClient(address, hostname string) (*Client, error)

NewClient creates new client

Example
client, err := NewClient("127.0.0.1:10051", "localhost")

if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}

fmt.Println(client.Hostname)
Output:

localhost

func (*Client) Add

func (c *Client) Add(key string, value interface{}) *Metric

Add adds new metric to stack

Example
client, err := NewClient("127.0.0.1:10051", "localhost")

if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}

client.Add("test1", 1)
client.Add("test2", 2)

retro := time.Date(2019, 5, 1, 14, 34, 11, 0, time.Local)

m := client.Add("test3", 3)
m.Host = "host1.domain.com"
m.Clock = retro.Unix()
m.NS = retro.Nanosecond()

client.Send()
Output:

func (*Client) Clear

func (c *Client) Clear()

Clear clears all metrics in stack

Example
client, err := NewClient("127.0.0.1:10051", "localhost")

if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}

client.Add("test1", 1)
client.Add("test2", 2)
client.Add("test3", 3)

client.Clear()

fmt.Printf("Items in stack: %d", client.Num())
Output:

Items in stack: 0

func (*Client) Num

func (c *Client) Num() int

Num returns number of metrics in stack

Example
client, err := NewClient("127.0.0.1:10051", "localhost")

if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}

client.Add("test1", 1)
client.Add("test2", 2)
client.Add("test3", 3)

fmt.Printf("Items in stack: %d", client.Num())
Output:

Items in stack: 3

func (*Client) Send

func (c *Client) Send() (Response, error)

Send sends data to Zabbix server

Example
client, err := NewClient("127.0.0.1:10051", "localhost")

if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}

client.Add("test1", 1)
client.Add("test2", 2)
client.Add("test3", 3)

resp, err := client.Send()

if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}

fmt.Printf(
	"Metrics sended (processed: %d | failed: %d | total: %d)",
	resp.Processed, resp.Failed, resp.Total,
)
Output:

type Metric

type Metric struct {
	Clock int64
	NS    int
	Host  string
	Key   string
	Value string
	// contains filtered or unexported fields
}

Metric contains information about one metric

type Response

type Response struct {
	Status       string
	Processed    int
	Failed       int
	Total        int
	SecondsSpent float64
}

Response response is parsed Zabbix server response data

Jump to

Keyboard shortcuts

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