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 ¶
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 ¶
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 ¶
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 ¶
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:
Click to show internal directories.
Click to hide internal directories.