-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbandwidth.go
60 lines (54 loc) · 2.19 KB
/
bandwidth.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
package gonion
// GetBandwidth returns results from https://onionoo.torproject.org/bandwidth.
func GetBandwidth(client HTTPClient, args Params) (*Bandwidth, error) {
bandwidth := &Bandwidth{}
err := getEndp(client, "bandwidth", args, bandwidth)
if err != nil {
return nil, err
}
return bandwidth, nil
}
// Bandwidth represents the datastructure defined by Onionoo.
// See https://metrics.torproject.org/onionoo.html#bandwidth.
type Bandwidth struct {
Version string `json:"version"`
BuildRevision string `json:"build_revision"`
RelaysSkipped *int `json:"relays_skipped,omitempty"`
RelaysPublished string `json:"relays_published"`
Relays []BandwidthNode `json:"relays"`
RelaysTruncated *int `json:"relays_truncated,omitempty"`
BridgesPublished string `json:"bridges_published"`
Bridges []BandwidthNode `json:"bridges"`
BridgesTruncated *int `json:"bridges_truncated,omitempty"`
}
// BandwidthNode is a sub-Bandwidth datastructure.
type BandwidthNode struct {
Fingerprint string `json:"fingerprint"`
WriteHistory *History `json:"write_history,omitempty"`
ReadHistory *History `json:"read_history,omitempty"`
OverloadRateLimits *OverloadRateLimits `json:"overload_ratelimits,omitempty"`
}
// History is a sub-BandwidthNode datastructure.
type History struct {
OneMonth *HistoryEntry `json:"1_month,omitempty"`
SixMonths *HistoryEntry `json:"6_months,omitempty"`
OneYear *HistoryEntry `json:"1_year,omitempty"`
FiveYears *HistoryEntry `json:"5_years,omitempty"`
}
// HistoryEntry is a sub-History datastructure.
type HistoryEntry struct {
First string `json:"first"`
Last string `json:"last"`
Interval int `json:"interval"`
Factor float64 `json:"factor"`
Count int `json:"count"`
Values []*int `json:"values,omitempty"`
}
// OverloadRateLimits is a sub-BandwidthNode datastructure.
type OverloadRateLimits struct {
BurstLimit float64 `json:"burst-limit"`
RateLimit float64 `json:"rate-limit"`
ReadCount float64 `json:"read-count"`
Timestamp float64 `json:"timestamp"`
WriteCount float64 `json:"write-count"`
}