-
Notifications
You must be signed in to change notification settings - Fork 19
/
tps.go
35 lines (29 loc) · 863 Bytes
/
tps.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2016 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package factom
import (
"encoding/json"
)
// GetTPS returns the instant rate (over the previous 3 seconds) and total rate
// (over the lifetime of the node) of Transactions Per Second rate know to
// factomd.
func GetTPS() (instant, total float64, err error) {
req := NewJSON2Request("tps-rate", APICounter(), nil)
resp, err := factomdRequest(req)
if err != nil {
return
}
if resp.Error != nil {
return
}
// create temporary type to decode the json tps rate response
rates := new(struct {
InstantRate float64 `json:"instanttxrate"`
TotalRate float64 `json:"totaltxrate"`
})
if err = json.Unmarshal(resp.JSONResult(), rates); err != nil {
return
}
return rates.InstantRate, rates.TotalRate, nil
}