/
types.go
159 lines (139 loc) · 4.49 KB
/
types.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package metrics
import (
"fmt"
"time"
"go.sia.tech/core/types"
)
// intervals at which metrics should be aggregated.
const (
Interval5Minutes Interval = iota
Interval15Minutes
IntervalHourly
IntervalDaily
IntervalWeekly
IntervalMonthly
IntervalYearly
)
type (
// Revenue is a collection of metrics related to revenue.
Revenue struct {
RPC types.Currency `json:"rpc"`
Storage types.Currency `json:"storage"`
Ingress types.Currency `json:"ingress"`
Egress types.Currency `json:"egress"`
RegistryRead types.Currency `json:"registryRead"`
RegistryWrite types.Currency `json:"registryWrite"`
}
// DataMetrics is a collection of metrics related to data usage.
DataMetrics struct {
RHP RHPData `json:"rhp"`
}
// RHPData is a collection of data metrics related to the RHP.
RHPData struct {
// Ingress returns the number of bytes received by the host.
Ingress uint64 `json:"ingress"`
// Egress returns the number of bytes sent by the host.
Egress uint64 `json:"egress"`
}
// Contracts is a collection of metrics related to contracts.
Contracts struct {
Pending uint64 `json:"pending"`
Active uint64 `json:"active"`
Rejected uint64 `json:"rejected"`
Failed uint64 `json:"failed"`
Successful uint64 `json:"successful"`
LockedCollateral types.Currency `json:"lockedCollateral"`
RiskedCollateral types.Currency `json:"riskedCollateral"`
}
// Accounts is a collection of metrics related to ephemeral accounts.
Accounts struct {
Active uint64 `json:"active"`
Balance types.Currency `json:"balance"`
}
// Pricing is a collection of metrics related to the host's pricing settings.
Pricing struct {
ContractPrice types.Currency `json:"contractPrice"`
IngressPrice types.Currency `json:"ingressPrice"`
EgressPrice types.Currency `json:"egressPrice"`
BaseRPCPrice types.Currency `json:"baseRPCPrice"`
SectorAccessPrice types.Currency `json:"sectorAccessPrice"`
StoragePrice types.Currency `json:"storagePrice"`
CollateralMultiplier float64 `json:"collateralMultiplier"`
}
// Registry is a collection of metrics related to the host's registry.
Registry struct {
Entries uint64 `json:"entries"`
MaxEntries uint64 `json:"maxEntries"`
Reads uint64 `json:"reads"`
Writes uint64 `json:"writes"`
}
// Storage is a collection of metrics related to storage.
Storage struct {
TotalSectors uint64 `json:"totalSectors"`
PhysicalSectors uint64 `json:"physicalSectors"`
LostSectors uint64 `json:"lostSectors"`
ContractSectors uint64 `json:"contractSectors"`
TempSectors uint64 `json:"tempSectors"`
Reads uint64 `json:"reads"`
Writes uint64 `json:"writes"`
SectorCacheHits uint64 `json:"sectorCacheHits"`
SectorCacheMisses uint64 `json:"sectorCacheMisses"`
}
// RevenueMetrics is a collection of metrics related to revenue.
RevenueMetrics struct {
Potential Revenue `json:"potential"`
Earned Revenue `json:"earned"`
}
// Metrics is a collection of metrics for the host.
Metrics struct {
Accounts Accounts `json:"accounts"`
Revenue RevenueMetrics `json:"revenue"`
Pricing Pricing `json:"pricing"`
Contracts Contracts `json:"contracts"`
Storage Storage `json:"storage"`
Registry Registry `json:"registry"`
Data DataMetrics `json:"data"`
Balance types.Currency `json:"balance"`
Timestamp time.Time `json:"timestamp"`
}
// Interval is the interval at which metrics should be aggregated.
Interval uint8
)
// String returns the interval as a string
func (i Interval) String() string {
switch i {
case Interval5Minutes:
return "5m"
case Interval15Minutes:
return "15m"
case IntervalHourly:
return "hourly"
case IntervalDaily:
return "daily"
case IntervalWeekly:
return "weekly"
case IntervalMonthly:
return "monthly"
case IntervalYearly:
return "yearly"
}
return "unknown"
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (i *Interval) UnmarshalText(buf []byte) error {
values := map[string]Interval{
Interval5Minutes.String(): Interval5Minutes,
Interval15Minutes.String(): Interval15Minutes,
IntervalHourly.String(): IntervalHourly,
IntervalDaily.String(): IntervalDaily,
IntervalWeekly.String(): IntervalWeekly,
IntervalMonthly.String(): IntervalMonthly,
IntervalYearly.String(): IntervalYearly,
}
val, ok := values[string(buf)]
if !ok {
return fmt.Errorf("invalid interval: %v", string(buf))
}
*i = val
return nil
}