Skip to content

Commit

Permalink
go/extra/stats: add block singature counting tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Dec 23, 2019
1 parent fbed77b commit cff3a8f
Show file tree
Hide file tree
Showing 8 changed files with 415 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .changelog/2500.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Entity block signatures count tool.

The tool uses node consensus and registry API endpoints and computes the per
entity block signature counts.
4 changes: 2 additions & 2 deletions go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ all: build

# Build.
# List of Go binaries to build.
go-binaries := oasis-node oasis-test-runner oasis-net-runner
go-binaries := oasis-node oasis-test-runner oasis-net-runner extra/stats
# List of test helpers to build.
test-helpers := urkel
# List of test vectors to generate.
Expand All @@ -22,7 +22,7 @@ generate:

$(go-binaries):
@$(ECHO) "$(MAGENTA)*** Building $@...$(OFF)"
@$(GO) build $(GOFLAGS) $(GO_EXTRA_FLAGS) -o ./$@/$@ ./$@
@$(GO) build $(GOFLAGS) $(GO_EXTRA_FLAGS) -o ./$@/$(notdir $@) ./$@

oasis-node:

Expand Down
4 changes: 4 additions & 0 deletions go/extra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Extra

This directory contains packages depending on (but not directly part of)
oasis-core.
1 change: 1 addition & 0 deletions go/extra/stats/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stats
19 changes: 19 additions & 0 deletions go/extra/stats/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Stats

Queries a node for network stats. Currently implemented per entity block
signature counts.

## Usage

```
stats/stats entity-signatures \
--address unix:<node_dir>/internal.sock \
--start-block 0 \
--end-block 100 \
--top-n 100
|Rank |Entity ID |Nodes |Signatures|
------------------------------------------------------------------------------------------
|1 |ef9ccfc825d5f0087e56937c697b46520f29f81e21d8a289218a4ebaef00509c| 6| 100|
|2 |4ea5328f943ef6f66daaed74cb0e99c3b1c45f76307b425003dbc7cb3638ed35| 1| 80|
...
53 changes: 53 additions & 0 deletions go/extra/stats/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Package cmd implements stats cmd tool.
package cmd

import (
"fmt"

"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"

"github.com/oasislabs/oasis-core/go/common/logging"
"github.com/oasislabs/oasis-core/go/common/version"
"github.com/oasislabs/oasis-core/go/oasis-node/cmd/common"
)

const cfgLogLevel = "log.level"

var (
rootCmd = &cobra.Command{
Use: "stats",
Short: "Oasis stats",
Version: version.SoftwareVersion,
}

rootFlags = flag.NewFlagSet("", flag.ContinueOnError)
)

// RootCommand returns the root (top level) cobra.Command.
func RootCommand() *cobra.Command {
return rootCmd
}

// Execute spawns the main entry point after handling the command line arguments.
func Execute() {
var logLevel logging.Level
if err := logLevel.Set(viper.GetString(cfgLogLevel)); err != nil {
common.EarlyLogAndExit(fmt.Errorf("root: failed to set log level: %w", err))
}

if err := rootCmd.Execute(); err != nil {
common.EarlyLogAndExit(err)
}
}

func init() {
logLevel := logging.LevelInfo
rootFlags.Var(&logLevel, cfgLogLevel, "log level")
_ = viper.BindPFlags(rootFlags)
rootCmd.PersistentFlags().AddFlagSet(rootFlags)

// Register all of the sub-commands.
RegisterStatsCmd(rootCmd)
}
Loading

0 comments on commit cff3a8f

Please sign in to comment.