-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance metrics with influxdb tags and rpc api (#59)
- Loading branch information
Showing
3 changed files
with
44 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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,33 @@ | ||
package metrics | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/ethereum/go-ethereum/metrics" | ||
) | ||
|
||
const DefaultAPIName = "metrics" | ||
|
||
// API provides metrics related RPC implementations. | ||
type API struct { | ||
reg metrics.Registry | ||
} | ||
|
||
func NewAPI(reg metrics.Registry) *API { return &API{reg} } | ||
|
||
func NewDefaultAPI() *API { return &API{DefaultRegistry} } | ||
|
||
// GetMetrics returns all metrics of specified prefix. Empty prefix indicates all metrics. | ||
func (api *API) GetMetrics(prefix ...string) (map[string]map[string]any, error) { | ||
result := make(map[string]map[string]any) | ||
|
||
all := api.reg.GetAll() | ||
|
||
for k, v := range all { | ||
if len(prefix) == 0 || strings.HasPrefix(k, prefix[0]) { | ||
result[k] = v | ||
} | ||
} | ||
|
||
return result, nil | ||
} |
This file contains 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