Skip to content

Commit

Permalink
Merge pull request #16 from jtsunne/15-add-repository-page
Browse files Browse the repository at this point in the history
add Repo Page with Snapshot Table
  • Loading branch information
jtsunne authored Oct 28, 2022
2 parents 02be455 + f37b995 commit 39ec0d2
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Structs/EsCluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,22 @@ type EsClusterNodeTags struct {
Attr string `json:"attr"`
Value string `json:"value"`
}

type EsClusterRepository struct {
Id string `json:"id"`
Type string `json:"type"`
}

type EsSnapshot struct {
Id string `json:"id"`
Status string `json:"status"`
StartEpoch string `json:"start_epoch"`
StartTime string `json:"start_time"`
EndEpoch string `json:"end_epoch"`
EndTime string `json:"end_time"`
Duration string `json:"duration"`
Indices string `json:"indices"`
SuccessfulShards string `json:"successful_shards"`
FailedShards string `json:"failed_shards"`
TotalShards string `json:"total_shards"`
}
116 changes: 116 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ var (
idxAliases []Structs.EsIndexAlias
clusterNodes []Structs.EsClusterNode
clusterNodesTags []Structs.EsClusterNodeTags
clusterRepos []Structs.EsClusterRepository
clusterSnapshots map[string][]Structs.EsSnapshot
app = tview.NewApplication()
pages = tview.NewPages()
helpPage = tview.NewTextView()
tvNodes = tview.NewTable()
tvIndices = tview.NewTable()
repoTable = tview.NewTable()
snapshotTable = tview.NewTable()
header = tview.NewTextView()
footer = tview.NewTextView()
filter = tview.NewInputField()
Expand Down Expand Up @@ -98,6 +102,24 @@ func init() {
return event
})

repoTable.SetBorder(true).
SetTitleAlign(tview.AlignCenter).
SetTitle("Repositories")
snapshotTable.SetBorder(true).
SetTitleAlign(tview.AlignCenter).
SetTitle("Snapshots")
tvNodes.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
switch event.Key() {

}
switch event.Rune() {
case 'r':
pages.SwitchToPage("repos")
return nil
}
return event
})

filter.SetBorder(true).
SetTitleAlign(tview.AlignCenter).
SetTitle(" Filter ")
Expand All @@ -113,6 +135,12 @@ func init() {
AddItem(header, 3, 1, false).
AddItem(tvInfo, 0, 1, true),
true, true)
pages.AddPage("repos",
tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(header, 3, 1, false).
AddItem(repoTable, 0, 1, true).
AddItem(snapshotTable, 0, 1, false),
true, true)
pages.AddPage("help",
tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(header, 3, 1, false).
Expand Down Expand Up @@ -159,9 +187,17 @@ func RefreshData() {
return indices[i].Index < indices[j].Index
})
Utils.GetJson(fmt.Sprintf("%s/_cat/aliases?format=json", EsUrl), &idxAliases)
Utils.GetJson(fmt.Sprintf("%s/_cat/repositories?format=json", EsUrl), &clusterRepos)
clusterSnapshots = make(map[string][]Structs.EsSnapshot)
for _, itm := range clusterRepos {
var s []Structs.EsSnapshot
Utils.GetJson(fmt.Sprintf("%s/_cat/snapshots/%s?format=json", EsUrl, itm.Id), &s)
clusterSnapshots[itm.Id] = s
}

FillNodes(nodes, tvNodes)
FillIndices(indices, tvIndices)
FillRepos(clusterRepos, repoTable)
dt := time.Now()
footer.SetText("Data refreshed @ " + dt.Format(time.ANSIC))
}
Expand Down Expand Up @@ -346,6 +382,86 @@ func FillIndices(idxs []Structs.EsIndices, t *tview.Table) {
})
}

func FillRepos(r []Structs.EsClusterRepository, t *tview.Table) {
t.Clear()
t.SetBorder(true)
t.SetCell(0, 0, tview.NewTableCell("Id").
SetTextColor(tcell.ColorYellow).
SetAlign(tview.AlignCenter))
t.SetCell(0, 1, tview.NewTableCell("Type").
SetTextColor(tcell.ColorYellow).
SetAlign(tview.AlignCenter))
for i, itm := range r {
t.SetCellSimple(i+1, 0, itm.Id)
t.SetCellSimple(i+1, 1, itm.Type)
}
t.SetFixed(2, 1)
t.Select(2, 1)
t.SetSelectable(true, false)
t.SetSelectedFunc(func(row, column int) {
repo := t.GetCell(row, 0).Text
FillSnapshot(repo, snapshotTable)
app.SetFocus(snapshotTable)
})
t.SetDoneFunc(func(key tcell.Key) {
pages.SwitchToPage("nodes")
})
}

func FillSnapshot(repoName string, t *tview.Table) {
t.Clear()
t.SetBorder(true)
t.SetTitle("Snapshots [" + repoName + "]")
t.SetCell(0, 0, tview.NewTableCell("Id").
SetTextColor(tcell.ColorYellow).
SetAlign(tview.AlignCenter))
t.SetCell(0, 1, tview.NewTableCell("Status").
SetTextColor(tcell.ColorYellow).
SetAlign(tview.AlignCenter))
t.SetCell(0, 2, tview.NewTableCell("Start Time").
SetTextColor(tcell.ColorYellow).
SetAlign(tview.AlignCenter))
t.SetCell(0, 3, tview.NewTableCell("End Time").
SetTextColor(tcell.ColorYellow).
SetAlign(tview.AlignCenter))
t.SetCell(0, 4, tview.NewTableCell("Duration").
SetTextColor(tcell.ColorYellow).
SetAlign(tview.AlignCenter))
t.SetCell(0, 5, tview.NewTableCell("Indices").
SetTextColor(tcell.ColorYellow).
SetAlign(tview.AlignCenter))
t.SetCell(0, 6, tview.NewTableCell("Successful Shards").
SetTextColor(tcell.ColorYellow).
SetAlign(tview.AlignCenter))
t.SetCell(0, 7, tview.NewTableCell("Failed Shards").
SetTextColor(tcell.ColorYellow).
SetAlign(tview.AlignCenter))
t.SetCell(0, 8, tview.NewTableCell("Total Shards").
SetTextColor(tcell.ColorYellow).
SetAlign(tview.AlignCenter))
for i, itm := range clusterSnapshots[repoName] {
t.SetCellSimple(i+1, 0, itm.Id)
t.SetCellSimple(i+1, 1, itm.Status)
t.SetCellSimple(i+1, 2, itm.StartTime)
t.SetCellSimple(i+1, 3, itm.EndTime)
t.SetCellSimple(i+1, 4, itm.Duration)
t.SetCellSimple(i+1, 5, itm.Indices)
t.SetCellSimple(i+1, 6, itm.SuccessfulShards)
t.SetCellSimple(i+1, 7, itm.FailedShards)
t.SetCellSimple(i+1, 8, itm.TotalShards)
}
t.SetFixed(2, 1)
t.Select(2, 1)
t.SetSelectable(true, false)
t.SetSelectedFunc(func(row, column int) {

})
t.SetDoneFunc(func(key tcell.Key) {
t.Clear()
app.SetFocus(repoTable)
})
}

func selectedIndexFunc(row int, _ int, tbl *tview.Table) {
var selectedIndexName string
selectedIndexName = tbl.GetCell(row, 0).Text
Expand Down

0 comments on commit 39ec0d2

Please sign in to comment.