mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
p2p/protocols: accounting metrics rpc added (#847)
This commit is contained in:
parent
3ac633ba84
commit
d545bb74ba
3 changed files with 120 additions and 0 deletions
|
|
@ -18,6 +18,7 @@
|
|||
package web3ext
|
||||
|
||||
var Modules = map[string]string{
|
||||
"account": Account_JS,
|
||||
"admin": Admin_JS,
|
||||
"chequebook": Chequebook_JS,
|
||||
"clique": Clique_JS,
|
||||
|
|
@ -692,3 +693,43 @@ web3._extend({
|
|||
]
|
||||
});
|
||||
`
|
||||
|
||||
const Account_JS = `
|
||||
web3._extend({
|
||||
property: 'account',
|
||||
methods: [
|
||||
new web3._extend.Property({
|
||||
name: 'balanceCredit',
|
||||
getter: 'account_balanceCredit'
|
||||
}),
|
||||
new web3._extend.Property({
|
||||
name: 'balanceDebit',
|
||||
getter: 'account_balanceDebit'
|
||||
}),
|
||||
new web3._extend.Property({
|
||||
name: 'bytesCredit',
|
||||
getter: 'account_bytesCredit'
|
||||
}),
|
||||
new web3._extend.Property({
|
||||
name: 'bytesDebit',
|
||||
getter: 'account_bytesDebit'
|
||||
}),
|
||||
new web3._extend.Property({
|
||||
name: 'msgCredit',
|
||||
getter: 'account_msgCredit'
|
||||
}),
|
||||
new web3._extend.Property({
|
||||
name: 'msgDebit',
|
||||
getter: 'account_msgDebit'
|
||||
}),
|
||||
new web3._extend.Property({
|
||||
name: 'peerDrops',
|
||||
getter: 'account_peerDrops'
|
||||
}),
|
||||
new web3._extend.Property({
|
||||
name: 'selfDrops',
|
||||
getter: 'account_selfDrops'
|
||||
}),
|
||||
]
|
||||
});
|
||||
`
|
||||
|
|
|
|||
73
p2p/protocols/accounting_api.go
Normal file
73
p2p/protocols/accounting_api.go
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
package protocols
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
const AccountingVersion = "1.0"
|
||||
|
||||
var errNoAccountingMetrics = errors.New("no accounting metrics")
|
||||
|
||||
type AccountingApi struct {
|
||||
metrics *AccountingMetrics
|
||||
}
|
||||
|
||||
func NewAccountingApi(m *AccountingMetrics) *AccountingApi {
|
||||
return &AccountingApi{m}
|
||||
}
|
||||
|
||||
func (self *AccountingApi) BalanceCredit() (int64, error) {
|
||||
if self.metrics == nil {
|
||||
return 0, errNoAccountingMetrics
|
||||
}
|
||||
return mBalanceCredit.Count(), nil
|
||||
}
|
||||
|
||||
func (self *AccountingApi) BalanceDebit() (int64, error) {
|
||||
if self.metrics == nil {
|
||||
return 0, errNoAccountingMetrics
|
||||
}
|
||||
return mBalanceDebit.Count(), nil
|
||||
}
|
||||
|
||||
func (self *AccountingApi) BytesCredit() (int64, error) {
|
||||
if self.metrics == nil {
|
||||
return 0, errNoAccountingMetrics
|
||||
}
|
||||
return mBytesCredit.Count(), nil
|
||||
}
|
||||
|
||||
func (self *AccountingApi) BytesDebit() (int64, error) {
|
||||
if self.metrics == nil {
|
||||
return 0, errNoAccountingMetrics
|
||||
}
|
||||
return mBytesDebit.Count(), nil
|
||||
}
|
||||
|
||||
func (self *AccountingApi) MsgCredit() (int64, error) {
|
||||
if self.metrics == nil {
|
||||
return 0, errNoAccountingMetrics
|
||||
}
|
||||
return mMsgCredit.Count(), nil
|
||||
}
|
||||
|
||||
func (self *AccountingApi) MsgDebit() (int64, error) {
|
||||
if self.metrics == nil {
|
||||
return 0, errNoAccountingMetrics
|
||||
}
|
||||
return mMsgDebit.Count(), nil
|
||||
}
|
||||
|
||||
func (self *AccountingApi) PeerDrops() (int64, error) {
|
||||
if self.metrics == nil {
|
||||
return 0, errNoAccountingMetrics
|
||||
}
|
||||
return mPeerDrops.Count(), nil
|
||||
}
|
||||
|
||||
func (self *AccountingApi) SelfDrops() (int64, error) {
|
||||
if self.metrics == nil {
|
||||
return 0, errNoAccountingMetrics
|
||||
}
|
||||
return mSelfDrops.Count(), nil
|
||||
}
|
||||
|
|
@ -518,6 +518,12 @@ func (self *Swarm) APIs() []rpc.API {
|
|||
Service: self.sfs,
|
||||
Public: false,
|
||||
},
|
||||
{
|
||||
Namespace: "account",
|
||||
Version: protocols.AccountingVersion,
|
||||
Service: protocols.NewAccountingApi(self.accountingMetrics),
|
||||
Public: false,
|
||||
},
|
||||
}
|
||||
|
||||
apis = append(apis, self.bzz.APIs()...)
|
||||
|
|
|
|||
Loading…
Reference in a new issue