Flesh out available stats more

This commit is contained in:
Justin Li 2014-07-21 11:42:05 -04:00
parent 7a849e6f20
commit 8f6aaa6527

View file

@ -11,23 +11,66 @@ import "time"
const ( const (
Announce = iota Announce = iota
Scrape Scrape
Completed
NewPeer CompletedIPv4
DeletedPeer NewLeechIPv4
NewSeeder DeletedLeechIPv4
DeletedSeeder ReapedLeechIPv4
NewSeedIPv4
DeletedSeedIPv4
ReapedSeedIPv4
CompletedIPv6
NewLeechIPv6
DeletedLeechIPv6
ReapedLeechIPv6
NewSeedIPv6
DeletedSeedIPv6
ReapedSeedIPv6
NewTorrent NewTorrent
DeletedTorrent DeletedTorrent
ReapedTorrent
AcceptedConnection
ClosedConnection
HandledRequest
ErroredRequest
) )
type PeerStats struct {
// Stats for all peers.
Completed uint64
Joined uint64
Left uint64
Reaped uint64
// Stats for seeds only (subset of total).
SeedsJoined uint64
SeedsLeft uint64
SeedsReaped uint64
}
type Stats struct { type Stats struct {
Start time.Time Start time.Time
Announces uint64 Announces uint64
Scrapes uint64 Scrapes uint64
Completed uint64
Peers uint64 IPv4Peers PeerStats
Seeders uint64 IPv6Peers PeerStats
Torrents uint64
TorrentsAdded uint64
TorrentsRemoved uint64
TorrentsReaped uint64
ActiveConnections uint64
ConnectionsAccepted uint64
BytesTransmitted uint64
RequestsHandled uint64
RequestsErrored uint64
events chan int events chan int
} }
@ -60,30 +103,58 @@ func (s *Stats) handleEvents() {
switch event { switch event {
case Announce: case Announce:
s.Announces++ s.Announces++
case Scrape: case Scrape:
s.Scrapes++ s.Scrapes++
case Completed: case CompletedIPv4:
s.Completed++ s.IPv4Peers.Completed++
case NewLeechIPv4:
s.IPv4Peers.Joined++
case DeletedLeechIPv4:
s.IPv4Peers.Left++
case ReapedLeechIPv4:
s.IPv4Peers.Reaped++
case NewSeedIPv4:
s.IPv4Peers.SeedsJoined++
case DeletedSeedIPv4:
s.IPv4Peers.SeedsLeft++
case ReapedSeedIPv4:
s.IPv4Peers.SeedsReaped++
case NewPeer: case CompletedIPv6:
s.Peers++ s.IPv6Peers.Completed++
case NewLeechIPv6:
case DeletedPeer: s.IPv6Peers.Joined++
s.Peers-- case DeletedLeechIPv6:
s.IPv6Peers.Left++
case NewSeeder: case ReapedLeechIPv6:
s.Seeders++ s.IPv6Peers.Reaped++
case NewSeedIPv6:
case DeletedSeeder: s.IPv6Peers.SeedsJoined++
s.Seeders-- case DeletedSeedIPv6:
s.IPv6Peers.SeedsLeft++
case ReapedSeedIPv6:
s.IPv6Peers.SeedsReaped++
case NewTorrent: case NewTorrent:
s.Torrents++ s.TorrentsAdded++
case DeletedTorrent: case DeletedTorrent:
s.Torrents-- s.TorrentsRemoved++
case ReapedTorrent:
s.TorrentsReaped++
case AcceptedConnection:
s.ConnectionsAccepted++
s.ActiveConnections++
case ClosedConnection:
s.ActiveConnections--
case HandledRequest:
s.RequestsHandled++
case ErroredRequest:
s.RequestsErrored++
default: default:
panic("stats: RecordEvent called with an unknown event") panic("stats: RecordEvent called with an unknown event")