2019-07-08 19:22:37 -06:00
|
|
|
// Copyright 2019 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package debug
|
|
|
|
|
|
|
|
import (
|
2020-03-10 21:09:39 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/debug/tag"
|
2020-03-07 11:38:47 -07:00
|
|
|
"golang.org/x/tools/internal/telemetry/event"
|
2020-03-17 14:00:16 -06:00
|
|
|
"golang.org/x/tools/internal/telemetry/export/metric"
|
2019-07-08 19:22:37 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// the distributions we use for histograms
|
|
|
|
bytesDistribution = []int64{1 << 10, 1 << 11, 1 << 12, 1 << 14, 1 << 16, 1 << 20}
|
|
|
|
millisecondsDistribution = []float64{0.1, 0.5, 1, 2, 5, 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000}
|
|
|
|
|
|
|
|
receivedBytes = metric.HistogramInt64{
|
|
|
|
Name: "received_bytes",
|
|
|
|
Description: "Distribution of received bytes, by method.",
|
2020-03-10 21:52:14 -06:00
|
|
|
Keys: []event.Key{tag.RPCDirection, tag.Method},
|
2019-07-08 19:22:37 -06:00
|
|
|
Buckets: bytesDistribution,
|
2020-03-17 14:00:16 -06:00
|
|
|
}
|
2019-07-08 19:22:37 -06:00
|
|
|
|
|
|
|
sentBytes = metric.HistogramInt64{
|
|
|
|
Name: "sent_bytes",
|
|
|
|
Description: "Distribution of sent bytes, by method.",
|
2020-03-10 21:52:14 -06:00
|
|
|
Keys: []event.Key{tag.RPCDirection, tag.Method},
|
2019-07-08 19:22:37 -06:00
|
|
|
Buckets: bytesDistribution,
|
2020-03-17 14:00:16 -06:00
|
|
|
}
|
2019-07-08 19:22:37 -06:00
|
|
|
|
|
|
|
latency = metric.HistogramFloat64{
|
|
|
|
Name: "latency",
|
|
|
|
Description: "Distribution of latency in milliseconds, by method.",
|
2020-03-10 21:52:14 -06:00
|
|
|
Keys: []event.Key{tag.RPCDirection, tag.Method},
|
2019-07-08 19:22:37 -06:00
|
|
|
Buckets: millisecondsDistribution,
|
2020-03-17 14:00:16 -06:00
|
|
|
}
|
2019-07-08 19:22:37 -06:00
|
|
|
|
|
|
|
started = metric.Scalar{
|
|
|
|
Name: "started",
|
|
|
|
Description: "Count of RPCs started by method.",
|
2020-03-10 21:52:14 -06:00
|
|
|
Keys: []event.Key{tag.RPCDirection, tag.Method},
|
2020-03-17 14:00:16 -06:00
|
|
|
}
|
2019-07-08 19:22:37 -06:00
|
|
|
|
|
|
|
completed = metric.Scalar{
|
|
|
|
Name: "completed",
|
|
|
|
Description: "Count of RPCs completed by method and status.",
|
2020-03-10 21:52:14 -06:00
|
|
|
Keys: []event.Key{tag.RPCDirection, tag.Method, tag.StatusCode},
|
2020-03-17 14:00:16 -06:00
|
|
|
}
|
2019-07-08 19:22:37 -06:00
|
|
|
)
|
2020-03-17 14:00:16 -06:00
|
|
|
|
2020-03-20 06:29:48 -06:00
|
|
|
func registerMetrics(m *metric.Config) {
|
2020-03-17 14:00:16 -06:00
|
|
|
receivedBytes.Record(m, tag.ReceivedBytes)
|
|
|
|
sentBytes.Record(m, tag.SentBytes)
|
|
|
|
latency.Record(m, tag.Latency)
|
2020-03-24 19:30:31 -06:00
|
|
|
started.Count(m, tag.Started)
|
|
|
|
completed.Count(m, tag.Latency)
|
2020-03-17 14:00:16 -06:00
|
|
|
}
|