-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.go
130 lines (111 loc) · 3.84 KB
/
client.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package pulsaradmin
import (
"fmt"
"net/http"
"net/url"
)
type Client struct {
Key string
debug bool
*http.Client
baseURL *url.URL
}
type TopicStats struct {
AverageMsgSize float64 `json:"averageMsgSize"`
MsgRateIn float64 `json:"msgRateIn"`
MsgRateOut float64 `json:"msgRateOut"`
MsgThroughputIn float64 `json:"msgThroughputIn"`
MsgThroughputOut float64 `json:"msgThroughputOut"`
PendingAddEntriesCount int64 `json:"pendingAddEntriesCount"`
ProducerCount int64 `json:"producerCount"`
Publishers []struct {
Address string `json:"address"`
AverageMsgSize float64 `json:"averageMsgSize"`
ClientVersion string `json:"clientVersion"`
ConnectedSince string `json:"connectedSince"`
Metadata struct {
} `json:"metadata"`
MsgRateIn float64 `json:"msgRateIn"`
MsgThroughputIn float64 `json:"msgThroughputIn"`
ProducerId int64 `json:"producerId"`
ProducerName string `json:"producerName"`
} `json:"publishers"`
Replication struct {
} `json:"replication"`
StorageSize int64 `json:"storageSize"`
Subscriptions struct {
Subscription struct {
BlockedSubscriptionOnUnackedMsgs bool `json:"blockedSubscriptionOnUnackedMsgs"`
Consumers []struct {
Address string `json:"address"`
AvailablePermits int64 `json:"availablePermits"`
BlockedConsumerOnUnackedMsgs bool `json:"blockedConsumerOnUnackedMsgs"`
ClientVersion string `json:"clientVersion"`
ConnectedSince string `json:"connectedSince"`
ConsumerName string `json:"consumerName"`
Metadata struct {
} `json:"metadata"`
MsgRateOut float64 `json:"msgRateOut"`
MsgRateRedeliver float64 `json:"msgRateRedeliver"`
MsgThroughputOut float64 `json:"msgThroughputOut"`
UnackedMessages int64 `json:"unackedMessages"`
} `json:"consumers"`
MsgBacklog int64 `json:"msgBacklog"`
MsgRateExpired float64 `json:"msgRateExpired"`
MsgRateOut float64 `json:"msgRateOut"`
MsgRateRedeliver float64 `json:"msgRateRedeliver"`
MsgThroughputOut float64 `json:"msgThroughputOut"`
NumberOfEntriesSinceFirstNotAckedMessage int64 `json:"numberOfEntriesSinceFirstNotAckedMessage"`
TotalNonContiguousDeletedMessagesRange int64 `json:"totalNonContiguousDeletedMessagesRange"`
Type string `json:"type"`
UnackedMessages int64 `json:"unackedMessages"`
} `json:"subscription"`
} `json:"subscriptions"`
}
type BrokerStatsTopicResult map[string]Namespace
type Namespace map[string]NamespaceBundle
type NamespaceBundle map[string]TopicType
type TopicType map[string]TopicStats
func (c *Client) BrokerStatsTopics() (BrokerStatsTopicResult, error) {
req, err := c.NewRequest("GET", "/admin/v2/broker-stats/topics", nil)
if err != nil {
return nil, err
}
resp := BrokerStatsTopicResult{}
if err := c.Do(req, &resp); err != nil {
return nil, err
}
return resp, nil
}
type optionFn func(*Client)
// WithDebug enables debug output while interacting with MIPS
func WithDebug() optionFn {
return func(c *Client) {
c.debug = true
}
}
// WithURL contains the MIPS target url
func WithURL(u url.URL) optionFn {
return func(c *Client) {
c.baseURL = &u
}
}
// WithKey contains the MIPS API key
func WithKey(key string) optionFn {
return func(c *Client) {
c.Key = key
}
}
// New returns a MIPS API client
func New(options ...optionFn) (*Client, error) {
c := &Client{
Client: http.DefaultClient,
}
for _, optionFn := range options {
optionFn(c)
}
if c.baseURL == nil {
return nil, fmt.Errorf("URL not set")
}
return c, nil
}