| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package debug |
| 6 |
|
| 7 |
import ( |
| 8 |
"golang.org/x/tools/internal/event/export/metric" |
| 9 |
"golang.org/x/tools/internal/event/label" |
| 10 |
"golang.org/x/tools/internal/jsonrpc2" |
| 11 |
) |
| 12 |
|
| 13 |
var ( |
| 14 |
|
| 15 |
bytesDistribution = []int64{1 << 10, 1 << 11, 1 << 12, 1 << 14, 1 << 16, 1 << 20} |
| 16 |
secondsDistribution = []float64{ |
| 17 |
0.0001, |
| 18 |
0.0005, |
| 19 |
0.001, |
| 20 |
0.002, |
| 21 |
0.005, |
| 22 |
0.01, |
| 23 |
0.05, |
| 24 |
0.1, |
| 25 |
0.5, |
| 26 |
1, |
| 27 |
5, |
| 28 |
10, |
| 29 |
50, |
| 30 |
100, |
| 31 |
500, |
| 32 |
1000, |
| 33 |
} |
| 34 |
|
| 35 |
receivedBytes = metric.HistogramInt64{ |
| 36 |
Name: "received_bytes", |
| 37 |
Description: "Distribution of received bytes, by method.", |
| 38 |
Keys: []label.Key{jsonrpc2.RPCDirection, jsonrpc2.Method}, |
| 39 |
Buckets: bytesDistribution, |
| 40 |
} |
| 41 |
|
| 42 |
sentBytes = metric.HistogramInt64{ |
| 43 |
Name: "sent_bytes", |
| 44 |
Description: "Distribution of sent bytes, by method.", |
| 45 |
Keys: []label.Key{jsonrpc2.RPCDirection, jsonrpc2.Method}, |
| 46 |
Buckets: bytesDistribution, |
| 47 |
} |
| 48 |
|
| 49 |
latency = metric.HistogramFloat64{ |
| 50 |
Name: "latency", |
| 51 |
Description: "Distribution of latency in seconds, by method.", |
| 52 |
Keys: []label.Key{jsonrpc2.RPCDirection, jsonrpc2.Method}, |
| 53 |
Buckets: secondsDistribution, |
| 54 |
} |
| 55 |
|
| 56 |
started = metric.Scalar{ |
| 57 |
Name: "started", |
| 58 |
Description: "Count of RPCs started by method.", |
| 59 |
Keys: []label.Key{jsonrpc2.RPCDirection, jsonrpc2.Method}, |
| 60 |
} |
| 61 |
|
| 62 |
completed = metric.Scalar{ |
| 63 |
Name: "completed", |
| 64 |
Description: "Count of RPCs completed by method and status.", |
| 65 |
Keys: []label.Key{jsonrpc2.RPCDirection, jsonrpc2.Method, jsonrpc2.StatusCode}, |
| 66 |
} |
| 67 |
) |
| 68 |
|
| 69 |
func registerMetrics(m *metric.Config) { |
| 70 |
receivedBytes.Record(m, jsonrpc2.ReceivedBytes) |
| 71 |
sentBytes.Record(m, jsonrpc2.SentBytes) |
| 72 |
latency.Record(m, jsonrpc2.Latency) |
| 73 |
started.Count(m, jsonrpc2.Started) |
| 74 |
completed.Count(m, jsonrpc2.Latency) |
| 75 |
} |