-
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.
feat(replive): Add tool to check live replication stats
- Loading branch information
Farhan Khan
committed
Oct 3, 2022
1 parent
c2a602e
commit 1642903
Showing
6 changed files
with
1,664 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
master: | ||
- host: 0.0.0.0 | ||
port: 3322 | ||
name: master | ||
db: db | ||
|
||
followers: | ||
- host: 0.0.0.0 | ||
port: 3324 | ||
name: follower | ||
db: db |
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,131 @@ | ||
/* | ||
Copyright 2022 CodeNotary, Inc. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
ui "github.com/gizak/termui/v3" | ||
"github.com/gizak/termui/v3/widgets" | ||
) | ||
|
||
const ( | ||
terminalWidth = 120 | ||
heapAllocBarCount = 6 | ||
) | ||
|
||
// controller terminal-based controller | ||
type controller struct { | ||
Grid *ui.Grid | ||
Table *widgets.Table | ||
} | ||
|
||
func (p *controller) Resize() { | ||
p.resize() | ||
ui.Render(p.Grid) | ||
} | ||
|
||
func (p *controller) resize() { | ||
_, h := ui.TerminalDimensions() | ||
p.Grid.SetRect(0, 0, terminalWidth, h) | ||
} | ||
|
||
func (p *controller) initTable() { | ||
p.Table.Rows = [][]string{ | ||
{"Node", "Precommitted TX ID", "Committed TX ID", "Status"}, | ||
} | ||
p.Table.TextStyle = ui.NewStyle(ui.ColorWhite) | ||
p.Table.TextAlignment = ui.AlignLeft | ||
p.Table.RowSeparator = true | ||
p.Table.ColumnWidths = []int{30, 30, 30, 30} | ||
p.Table.PaddingLeft = 2 | ||
p.Table.BorderStyle = ui.NewStyle(ui.ColorGreen) | ||
p.Table.SetRect(0, 30, 70, 50) | ||
p.Table.RowStyles[0] = ui.NewStyle(ui.ColorRed, ui.ColorBlack, ui.ModifierBold) | ||
p.Table.SetRect(2, 2, 60, 10) | ||
} | ||
|
||
func (p *controller) Render(states []*State) { | ||
p.initTable() | ||
|
||
for _, s := range states { | ||
var status string | ||
if s.Err == nil { | ||
status = "Running" | ||
} else { | ||
status = s.Err.Error() | ||
} | ||
p.Table.Rows = append(p.Table.Rows, []string{ | ||
s.Name, | ||
fmt.Sprint(s.IState.PrecommittedTxId), | ||
fmt.Sprint(s.IState.TxId), | ||
status, | ||
}) | ||
} | ||
|
||
ui.Render(p.Grid) | ||
} | ||
|
||
func (p *controller) initUI() { | ||
p.resize() | ||
p.Grid.Set( | ||
ui.NewRow(.4, p.Table), | ||
) | ||
|
||
} | ||
|
||
func newController() *controller { | ||
ctl := &controller{ | ||
Grid: ui.NewGrid(), | ||
Table: widgets.NewTable(), | ||
} | ||
|
||
ctl.initUI() | ||
|
||
return ctl | ||
} | ||
|
||
func Run(loader StateLoader, interval time.Duration) { | ||
if err := ui.Init(); err != nil { | ||
log.Fatalf("failed to initialize termui: %v", err) | ||
} | ||
defer ui.Close() | ||
|
||
controller := newController() | ||
|
||
ev := ui.PollEvents() | ||
tick := time.Tick(interval) | ||
|
||
for { | ||
select { | ||
case e := <-ev: | ||
switch e.Type { | ||
case ui.KeyboardEvent: | ||
// quit on any keyboard event | ||
return | ||
case ui.ResizeEvent: | ||
controller.Resize() | ||
} | ||
case <-tick: | ||
stats := loader.Load() | ||
// update dashboard every second | ||
controller.Render(stats) | ||
} | ||
} | ||
} |
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,83 @@ | ||
module github.com/codenotary/immudb-tools/replive | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/codenotary/immudb v1.3.3-0.20220930121936-c7e2ab692f97 | ||
github.com/gizak/termui/v3 v3.1.0 | ||
gopkg.in/yaml.v2 v2.4.0 | ||
) | ||
|
||
require ( | ||
github.com/Masterminds/goutils v1.1.1 // indirect | ||
github.com/Masterminds/semver v1.5.0 // indirect | ||
github.com/Masterminds/sprig v2.22.0+incompatible // indirect | ||
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect | ||
github.com/aead/chacha20poly1305 v0.0.0-20201124145622-1a5aba2a8b29 // indirect | ||
github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635 // indirect | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash v1.1.0 // indirect | ||
github.com/cespare/xxhash/v2 v2.1.2 // indirect | ||
github.com/dgraph-io/ristretto v0.0.2 // indirect | ||
github.com/envoyproxy/protoc-gen-validate v0.3.0-java // indirect | ||
github.com/fsnotify/fsnotify v1.5.4 // indirect | ||
github.com/ghodss/yaml v1.0.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect | ||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/huandu/xstrings v1.3.2 // indirect | ||
github.com/imdario/mergo v0.3.13 // indirect | ||
github.com/inconshreveable/mousetrap v1.0.0 // indirect | ||
github.com/magiconair/properties v1.8.6 // indirect | ||
github.com/mattn/go-runewidth v0.0.13 // indirect | ||
github.com/mattn/goveralls v0.0.11 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect | ||
github.com/mitchellh/copystructure v1.2.0 // indirect | ||
github.com/mitchellh/go-wordwrap v1.0.1 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/mitchellh/reflectwalk v1.0.2 // indirect | ||
github.com/mwitkow/go-proto-validators v0.0.0-20180403085117-0950a7990007 // indirect | ||
github.com/nsf/termbox-go v1.1.1 // indirect | ||
github.com/o1egl/paseto v1.0.0 // indirect | ||
github.com/ory/go-acc v0.2.8 // indirect | ||
github.com/ory/viper v1.7.5 // indirect | ||
github.com/pborman/uuid v1.2.0 // indirect | ||
github.com/pelletier/go-toml v1.9.5 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.1 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/prometheus/client_golang v1.12.2 // indirect | ||
github.com/prometheus/client_model v0.2.0 // indirect | ||
github.com/prometheus/common v0.32.1 // indirect | ||
github.com/prometheus/procfs v0.7.3 // indirect | ||
github.com/pseudomuto/protoc-gen-doc v1.4.1 // indirect | ||
github.com/pseudomuto/protokit v0.2.1 // indirect | ||
github.com/rakyll/statik v0.1.7 // indirect | ||
github.com/rivo/uniseg v0.2.0 // indirect | ||
github.com/rogpeppe/go-internal v1.8.0 // indirect | ||
github.com/rs/xid v1.3.0 // indirect | ||
github.com/spf13/afero v1.8.2 // indirect | ||
github.com/spf13/cast v1.5.0 // indirect | ||
github.com/spf13/cobra v1.2.1 // indirect | ||
github.com/spf13/jwalterweatherman v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/spf13/viper v1.12.0 // indirect | ||
github.com/subosito/gotenv v1.3.0 // indirect | ||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect | ||
golang.org/x/mod v0.4.2 // indirect | ||
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect | ||
golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d // indirect | ||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect | ||
golang.org/x/text v0.3.7 // indirect | ||
golang.org/x/tools v0.1.5 // indirect | ||
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect | ||
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect | ||
google.golang.org/grpc v1.46.2 // indirect | ||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 // indirect | ||
google.golang.org/protobuf v1.28.0 // indirect | ||
gopkg.in/ini.v1 v1.66.6 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.