forked from ipfs-cluster/ipfs-cluster
/
metrics.go
146 lines (120 loc) · 4.3 KB
/
metrics.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
// Package observations sets up metric and trace exporting for IPFS cluster.
package observations
import (
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
logging "github.com/ipfs/go-log/v2"
)
var logger = logging.Logger("observations")
var (
// taken from ocgrpc (https://github.com/census-instrumentation/opencensus-go/blob/master/plugin/ocgrpc/stats_common.go)
// latencyDistribution = view.Distribution(0, 0.01, 0.05, 0.1, 0.3, 0.6, 0.8, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000, 5000, 10000, 20000, 50000, 100000)
// bytesDistribution = view.Distribution(0, 24, 32, 64, 128, 256, 512, 1024, 2048, 4096, 16384, 65536, 262144, 1048576)
// messageCountDistribution = view.Distribution(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536)
)
// attributes
var (
ClientIPAttribute = "http.client.ip"
)
// keys
var (
HostKey = makeKey("host")
RemotePeerKey = makeKey("remote_peer")
)
// metrics
var (
// This metric is managed in state/dsstate.
Pins = stats.Int64("pins", "Total number of cluster pins", stats.UnitDimensionless)
// These metrics are managed by the pintracker/optracker module.
PinsQueued = stats.Int64("pins/pin_queued", "Current number of pins queued for pinning", stats.UnitDimensionless)
PinsPinning = stats.Int64("pins/pinning", "Current number of pins currently pinning", stats.UnitDimensionless)
PinsPinError = stats.Int64("pins/pin_error", "Current number of pins in pin_error state", stats.UnitDimensionless)
// These metrics and managed in the ipfshttp module.
PinsIpfsPins = stats.Int64("pins/ipfs_pins", "Current number of items pinned on IPFS", stats.UnitDimensionless)
PinsPinAdd = stats.Int64("pins/pin_add", "Total number of IPFS pin requests", stats.UnitDimensionless)
PinsPinAddError = stats.Int64("pins/pin_add_errors", "Total number of failed pin requests", stats.UnitDimensionless)
BlocksPut = stats.Int64("blocks/put", "Total number of blocks/put requests", stats.UnitDimensionless)
BlocksAddedSize = stats.Int64("blocks/added_size", "Total size of blocks added in bytes", stats.UnitBytes)
BlocksAdded = stats.Int64("blocks/added", "Total number of blocks added", stats.UnitDimensionless)
BlocksAddedError = stats.Int64("blocks/put_errors", "Total number of block/put errors", stats.UnitDimensionless)
InformerDisk = stats.Int64("informer/disk", "The metric value weight issued by disk informer", stats.UnitDimensionless)
)
// views, which is just the aggregation of the metrics
var (
PinsView = &view.View{
Measure: Pins,
// This would add a tag to the metric if a value for this key
// is present in the context when recording the observation.
//TagKeys: []tag.Key{HostKey},
Aggregation: view.LastValue(),
}
PinsQueuedView = &view.View{
Measure: PinsQueued,
//TagKeys: []tag.Key{HostKey},
Aggregation: view.LastValue(),
}
PinsPinningView = &view.View{
Measure: PinsPinning,
//TagKeys: []tag.Key{HostKey},
Aggregation: view.LastValue(),
}
PinsPinErrorView = &view.View{
Measure: PinsPinError,
//TagKeys: []tag.Key{HostKey},
Aggregation: view.LastValue(),
}
PinsIpfsPinsView = &view.View{
Measure: PinsIpfsPins,
Aggregation: view.LastValue(),
}
PinsPinAddView = &view.View{
Measure: PinsPinAdd,
Aggregation: view.Sum(),
}
PinsPinAddErrorView = &view.View{
Measure: PinsPinAddError,
Aggregation: view.Sum(),
}
BlocksPutView = &view.View{
Measure: BlocksPut,
Aggregation: view.Sum(),
}
BlocksAddedSizeView = &view.View{
Measure: BlocksAddedSize,
Aggregation: view.Sum(),
}
BlocksAddedView = &view.View{
Measure: BlocksAdded,
Aggregation: view.Sum(),
}
BlocksAddedErrorView = &view.View{
Measure: BlocksAddedError,
Aggregation: view.Sum(),
}
InformerDiskView = &view.View{
Measure: InformerDisk,
Aggregation: view.LastValue(),
}
DefaultViews = []*view.View{
PinsView,
PinsQueuedView,
PinsPinningView,
PinsPinErrorView,
PinsIpfsPinsView,
PinsPinAddView,
PinsPinAddErrorView,
BlocksPutView,
BlocksAddedSizeView,
BlocksAddedView,
BlocksAddedErrorView,
InformerDiskView,
}
)
func makeKey(name string) tag.Key {
key, err := tag.NewKey(name)
if err != nil {
logger.Fatal(err)
}
return key
}