This repository was archived by the owner on Sep 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstats.go
95 lines (81 loc) · 2.66 KB
/
stats.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
package tat
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"time"
)
// StatsCountJSON contains all globals counters
type StatsCountJSON struct {
Date int64 `json:"date"`
DateHuman time.Time `json:"dateHuman"`
Version string `json:"version"`
Groups int `json:"groups"`
Messages int `json:"messages"`
Presences int `json:"presences"`
Topics int `json:"topics"`
Users int `json:"users"`
}
// StatsDistributionTopicsJSON is used by GET /distribution/topics
type StatsDistributionTopicsJSON struct {
Total int `json:"total"`
Info string `json:"info"`
Topics []TopicDistributionJSON `json:"topics"`
}
// StatsCount calls GET /stats/count
func (c *Client) StatsCount() (*StatsCountJSON, error) {
body, err := c.reqWant("GET", 200, "/stats/count", nil)
if err != nil {
return nil, err
}
out := &StatsCountJSON{}
if err := json.Unmarshal(body, out); err != nil {
return nil, err
}
return out, nil
}
// StatsDistributionTopics returns Stats Distribution per topics and per users
func (c *Client) StatsDistributionTopics(skip, limit int) (*StatsDistributionTopicsJSON, error) {
v := url.Values{}
v.Set("skip", strconv.Itoa(skip))
v.Set("limit", strconv.Itoa(limit))
path := fmt.Sprintf("/stats/distribution/topics?%s", v.Encode())
body, err := c.reqWant("GET", 200, path, nil)
if err != nil {
return nil, err
}
out := &StatsDistributionTopicsJSON{}
if err := json.Unmarshal(body, out); err != nil {
return nil, err
}
return out, nil
}
// StatsDBStats returns DB Stats
func (c *Client) StatsDBStats() ([]byte, error) {
return c.simpleGetAndGetBytes("/stats/db/stats")
}
// StatsDBServerStatus returns DB Server Status
func (c *Client) StatsDBServerStatus() ([]byte, error) {
return c.simpleGetAndGetBytes("/stats/db/serverStatus")
}
// StatsDBReplSetGetConfig returns DB Relica Set Config
func (c *Client) StatsDBReplSetGetConfig() ([]byte, error) {
return c.simpleGetAndGetBytes("/stats/db/replSetGetConfig")
}
// StatsDBReplSetGetStatus returns Replica Set Status
func (c *Client) StatsDBReplSetGetStatus() ([]byte, error) {
return c.simpleGetAndGetBytes("/stats/db/replSetGetStatus")
}
// StatsDBCollections returns nb msg for each collections
func (c *Client) StatsDBCollections() ([]byte, error) {
return c.simpleGetAndGetBytes("/stats/db/collections")
}
// StatsDBSlowestQueries returns DB slowest Queries
func (c *Client) StatsDBSlowestQueries() ([]byte, error) {
return c.simpleGetAndGetBytes("/stats/db/slowestQueries")
}
// StatsInstance returns DB Instance
func (c *Client) StatsInstance() ([]byte, error) {
return c.simpleGetAndGetBytes("/stats/instance")
}