-
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 0c10699
Showing
6 changed files
with
1,632 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,133 @@ | ||
/* | ||
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() | ||
} | ||
if s.IState != nil { | ||
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,57 @@ | ||
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/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/v2 v2.1.2 // indirect | ||
github.com/fsnotify/fsnotify v1.5.4 // indirect | ||
github.com/golang/protobuf v1.5.2 // 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/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/matttproud/golang_protobuf_extensions v1.0.1 // indirect | ||
github.com/mitchellh/go-wordwrap v1.0.1 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/nsf/termbox-go v1.1.1 // indirect | ||
github.com/o1egl/paseto v1.0.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/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/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 | ||
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect | ||
google.golang.org/grpc v1.46.2 // 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.