This repository was archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
p2p/protocols: accounting metrics rpc added (#847) #1048
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d545bb7
p2p/protocols: accounting metrics rpc added (#847)
b8454e6
p2p/protocols: accounting api documentation added (#847)
22f62b4
p2p/protocols: accounting api doc updated (#847)
2a6c2b2
p2p/protocols: accounting api doc update (#847)
d1d0b88
p2p/protocols: accounting api doc update (#847)
25964a1
p2p/protocols: fix file is not gofmted
e5cc4ba
fix lint error
5875394
updated comments after review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package protocols | ||
|
|
||
| import ( | ||
| "errors" | ||
| ) | ||
|
|
||
| // Textual version number of accounting API | ||
| const AccountingVersion = "1.0" | ||
|
|
||
| var errNoAccountingMetrics = errors.New("accounting metrics not enabled") | ||
|
|
||
| // AccountingApi provides an API to access account related information | ||
| type AccountingApi struct { | ||
|
JerzyLa marked this conversation as resolved.
|
||
| metrics *AccountingMetrics | ||
| } | ||
|
|
||
| // NewAccountingApi creates a new AccountingApi | ||
|
zelig marked this conversation as resolved.
|
||
| // m will be used to check if accounting metrics are enabled | ||
| 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 | ||
| } | ||
| return mSelfDrops.Count(), nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.