mirror of
https://github.com/go-i2p/go-i2pcontrol.git
synced 2025-06-08 18:41:44 -04:00
add ratestats
This commit is contained in:
3
auth.go
3
auth.go
@ -62,6 +62,9 @@ func Call(method string, params interface{}) (map[string]interface{}, error) {
|
||||
//var retv string
|
||||
var retpre map[string]interface{}
|
||||
err = response.GetObject(&retpre)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return retpre, nil
|
||||
}
|
||||
|
||||
|
5
go.mod
5
go.mod
@ -2,4 +2,7 @@ module github.com/eyedeekay/go-i2pcontrol
|
||||
|
||||
go 1.16
|
||||
|
||||
require github.com/ybbus/jsonrpc/v2 v2.1.6
|
||||
require (
|
||||
github.com/766b/go-outliner v0.0.0-20180511142203-fc6edecdadd7 // indirect
|
||||
github.com/ybbus/jsonrpc/v2 v2.1.6
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@ -1,3 +1,5 @@
|
||||
github.com/766b/go-outliner v0.0.0-20180511142203-fc6edecdadd7 h1:cJXisB2yAM61AzMutv7X+KM8F3xVLxGH99S8VmaSlps=
|
||||
github.com/766b/go-outliner v0.0.0-20180511142203-fc6edecdadd7/go.mod h1:1SzhThoS5lcKfE4IFOLQJ04WCmFpaAiPe8H9yqXyYSU=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
|
2
info.go
2
info.go
@ -70,7 +70,7 @@ func NetStatus() (string, error) {
|
||||
case 14:
|
||||
return "ERROR_UDP_DISABLED_AND_TCP_UNSET", nil
|
||||
}
|
||||
return "Unexpected result", fmt.Errorf("Unexpected result %d", result)
|
||||
return "unexpected result", fmt.Errorf("unexpected result %d", result)
|
||||
}
|
||||
|
||||
// Reseeding checks if the I2P Router is reseeding
|
||||
|
99
stats.go
99
stats.go
@ -1 +1,100 @@
|
||||
package i2pcontrol
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
// RateStat executes a GetRate call
|
||||
func RateStat(Stat string, Period int) (int, error) {
|
||||
retpre, err := Call("GetRate", map[string]interface{}{
|
||||
"Stat": Stat,
|
||||
"Period": Period,
|
||||
"Token": token,
|
||||
})
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
result := int(retpre["Result"].(float64))
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func SendBps() (int, error) {
|
||||
return RateStat("bw.sendBps", 300000)
|
||||
}
|
||||
|
||||
func ReceiveBps() (int, error) {
|
||||
return RateStat("bw.receiveBps", 300000)
|
||||
}
|
||||
|
||||
func ExploratoryBuildExpire() (int, error) {
|
||||
return RateStat("tunnel.buildExploratoryExpire", 600000)
|
||||
}
|
||||
|
||||
func ExploratoryBuildReject() (int, error) {
|
||||
return RateStat("tunnel.buildExploratoryReject", 600000)
|
||||
}
|
||||
|
||||
func ExploratoryBuildSuccess() (int, error) {
|
||||
return RateStat("tunnel.buildExploratorySuccess", 600000)
|
||||
}
|
||||
|
||||
func ExploratoryBuildRejectPercentage() (int, error) {
|
||||
explReject, err := ExploratoryBuildReject()
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("unable to calculate exploratory build rejection percent: %s", err)
|
||||
}
|
||||
explSuccess, err := ExploratoryBuildSuccess()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
explExpire, err := ExploratoryBuildExpire()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
explTotal := explReject + explSuccess + explExpire
|
||||
if explTotal == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
return int(float64(explReject) / float64(explTotal) * 100), nil
|
||||
}
|
||||
|
||||
func ExploratoryBuildSuccessPercentage() (int, error) {
|
||||
explSuccess, err := ExploratoryBuildSuccess()
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("unable to calculate exploratory build success percent: %s", err)
|
||||
}
|
||||
explReject, err := ExploratoryBuildReject()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
explExpire, err := ExploratoryBuildExpire()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
explTotal := explReject + explSuccess + explExpire
|
||||
if explTotal == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
return int(float64(explSuccess) / float64(explTotal) * 100), nil
|
||||
}
|
||||
|
||||
func ExploratoryBuildExpirePercentage() (int, error) {
|
||||
explExpire, err := ExploratoryBuildExpire()
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("unable to calculate exploratory build expire percent: %s", err)
|
||||
}
|
||||
explSuccess, err := ExploratoryBuildSuccess()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
explReject, err := ExploratoryBuildReject()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
explTotal := explReject + explSuccess + explExpire
|
||||
if explTotal == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
return int(float64(explExpire) / float64(explTotal) * 100), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user