2018-06-27 04:03:15 +00:00
|
|
|
package observations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.opencensus.io/stats"
|
|
|
|
"go.opencensus.io/stats/view"
|
|
|
|
"go.opencensus.io/tag"
|
|
|
|
|
|
|
|
logging "github.com/ipfs/go-log"
|
|
|
|
)
|
|
|
|
|
|
|
|
var logger = logging.Logger("observations")
|
|
|
|
|
|
|
|
var (
|
|
|
|
// taken from ocgrpc (https://github.com/census-instrumentation/opencensus-go/blob/master/plugin/ocgrpc/stats_common.go)
|
2019-04-29 07:58:28 +00:00
|
|
|
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)
|
2018-06-27 04:03:15 +00:00
|
|
|
)
|
|
|
|
|
2019-04-26 06:33:01 +00:00
|
|
|
// attributes
|
2018-06-27 04:03:15 +00:00
|
|
|
var (
|
|
|
|
ClientIPAttribute = "http.client.ip"
|
|
|
|
)
|
|
|
|
|
2019-04-26 06:33:01 +00:00
|
|
|
// keys
|
2018-06-27 04:03:15 +00:00
|
|
|
var (
|
2019-04-29 07:58:28 +00:00
|
|
|
HostKey = makeKey("host")
|
|
|
|
RemotePeerKey = makeKey("remote_peer")
|
2018-06-27 04:03:15 +00:00
|
|
|
)
|
|
|
|
|
2019-04-26 06:33:01 +00:00
|
|
|
// metrics
|
2018-06-27 04:03:15 +00:00
|
|
|
var (
|
2019-04-26 06:33:01 +00:00
|
|
|
// Pins counts the number of pins ipfs-cluster is tracking.
|
|
|
|
Pins = stats.Int64("cluster/pin_count", "Number of pins", stats.UnitDimensionless)
|
|
|
|
// TrackerPins counts the number of pins the local peer is tracking.
|
|
|
|
TrackerPins = stats.Int64("pintracker/pin_count", "Number of pins", stats.UnitDimensionless)
|
|
|
|
// Peers counts the number of ipfs-cluster peers are currently in the cluster.
|
|
|
|
Peers = stats.Int64("cluster/peers", "Number of cluster peers", stats.UnitDimensionless)
|
|
|
|
// Alerts is the number of alerts that have been sent due to peers not sending "ping" heartbeats in time.
|
|
|
|
Alerts = stats.Int64("cluster/alerts", "Number of alerts triggered", stats.UnitDimensionless)
|
2018-06-27 04:03:15 +00:00
|
|
|
)
|
|
|
|
|
2019-04-26 06:33:01 +00:00
|
|
|
// views, which is just the aggregation of the metrics
|
2018-06-27 04:03:15 +00:00
|
|
|
var (
|
2019-04-26 06:33:01 +00:00
|
|
|
PinsView = &view.View{
|
|
|
|
Measure: Pins,
|
2019-04-29 07:58:28 +00:00
|
|
|
TagKeys: []tag.Key{HostKey},
|
2019-04-26 06:33:01 +00:00
|
|
|
Aggregation: view.LastValue(),
|
2018-06-27 04:03:15 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 06:33:01 +00:00
|
|
|
TrackerPinsView = &view.View{
|
|
|
|
Measure: TrackerPins,
|
2018-06-27 04:03:15 +00:00
|
|
|
TagKeys: []tag.Key{HostKey},
|
2019-04-26 06:33:01 +00:00
|
|
|
Aggregation: view.LastValue(),
|
|
|
|
}
|
|
|
|
|
|
|
|
PeersView = &view.View{
|
|
|
|
Measure: Peers,
|
|
|
|
TagKeys: []tag.Key{HostKey},
|
|
|
|
Aggregation: view.LastValue(),
|
2018-06-27 04:03:15 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 06:33:01 +00:00
|
|
|
AlertsView = &view.View{
|
|
|
|
Measure: Alerts,
|
2019-04-29 07:58:28 +00:00
|
|
|
TagKeys: []tag.Key{HostKey, RemotePeerKey},
|
|
|
|
Aggregation: messageCountDistribution,
|
2018-06-27 04:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DefaultViews = []*view.View{
|
2019-04-26 06:33:01 +00:00
|
|
|
PinsView,
|
|
|
|
TrackerPinsView,
|
|
|
|
PeersView,
|
|
|
|
AlertsView,
|
2018-06-27 04:03:15 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func makeKey(name string) tag.Key {
|
|
|
|
key, err := tag.NewKey(name)
|
|
|
|
if err != nil {
|
|
|
|
logger.Fatal(err)
|
|
|
|
}
|
|
|
|
return key
|
|
|
|
}
|