Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2p/protocols: accounting metrics rpc #18336

Merged
merged 10 commits into from
Dec 22, 2018
Prev Previous commit
Next Next commit
p2p/protocols: accounting api documentation added (#847)
  • Loading branch information
Jerzy committed Dec 6, 2018
commit b8454e6d9e93bc3448acf30fecbd3a131d2e0d4c
10 changes: 9 additions & 1 deletion p2p/protocols/accounting_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

const AccountingVersion = "1.0"

var errNoAccountingMetrics = errors.New("no accounting metrics")
var errNoAccountingMetrics = errors.New("accounting metrics not enabled")

type AccountingApi struct {
metrics *AccountingMetrics
Expand All @@ -16,55 +16,63 @@ func NewAccountingApi(m *AccountingMetrics) *AccountingApi {
return &AccountingApi{m}
}

// BalanceCredit returns total amount of units credited by local node
func (self *AccountingApi) BalanceCredit() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
}
return mBalanceCredit.Count(), nil
}

// BalanceCredit returns total amount of units debited by local node
func (self *AccountingApi) BalanceDebit() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
}
return mBalanceDebit.Count(), nil
}

// BytesCredit returns total amount of bytes credited by local node
func (self *AccountingApi) BytesCredit() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
}
return mBytesCredit.Count(), nil
}

// BalanceCredit returns total amount of bytes debited by local node
func (self *AccountingApi) BytesDebit() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
}
return mBytesDebit.Count(), nil
}

// MsgCredit returns total amount of messages credited by local node
func (self *AccountingApi) MsgCredit() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
}
return mMsgCredit.Count(), nil
}

// MsgDebit returns total amount of messages debited by local node
func (self *AccountingApi) MsgDebit() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
}
return mMsgDebit.Count(), nil
}

// PeerDrops returns number of times when local node had to drop remote peers
func (self *AccountingApi) PeerDrops() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
}
return mPeerDrops.Count(), nil
}

// SelfDrops returns number of times when local node was overdrafted and dropped
func (self *AccountingApi) SelfDrops() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
Expand Down