-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
107 lines (80 loc) · 2.26 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package zabbix
// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2024 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
import (
"fmt"
"time"
)
// ////////////////////////////////////////////////////////////////////////////////// //
func ExampleNewClient() {
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 ExampleClient_Add() {
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()
}
func ExampleClient_Num() {
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 ExampleClient_Clear() {
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 ExampleClient_Send() {
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,
)
}