Added support for data streams

This commit is contained in:
Dionysus 2024-11-30 15:08:01 -05:00
parent 29ea00fb73
commit 1caff77734
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE
2 changed files with 38 additions and 6 deletions

BIN
elastop

Binary file not shown.

View File

@ -222,6 +222,17 @@ var (
metricsPanel *tview.TextView metricsPanel *tview.TextView
) )
type DataStreamResponse struct {
DataStreams []DataStream `json:"data_streams"`
}
type DataStream struct {
Name string `json:"name"`
Timestamp string `json:"timestamp"`
Status string `json:"status"`
Template string `json:"template"`
}
func bytesToHuman(bytes int64) string { func bytesToHuman(bytes int64) string {
const unit = 1024 const unit = 1024
if bytes < unit { if bytes < unit {
@ -800,6 +811,13 @@ func main() {
nodeInfo.OS.Arch) nodeInfo.OS.Arch)
} }
// Get data streams info
var dataStreamResp DataStreamResponse
if err := makeRequest("/_data_stream", &dataStreamResp); err != nil {
indicesPanel.SetText(fmt.Sprintf("[red]Error getting data streams: %v", err))
return
}
// Update indices panel with dynamic width // Update indices panel with dynamic width
indicesPanel.Clear() indicesPanel.Clear()
fmt.Fprintf(indicesPanel, "[::b][#00ffff][[#ff5555]4[#00ffff]] Indices Information[::-]\n\n") fmt.Fprintf(indicesPanel, "[::b][#00ffff][[#ff5555]4[#00ffff]] Indices Information[::-]\n\n")
@ -864,7 +882,7 @@ func main() {
// Sort indices by document count (descending) // Sort indices by document count (descending)
sort.Slice(indices, func(i, j int) bool { sort.Slice(indices, func(i, j int) bool {
return indices[i].docs > indices[j].docs return indices[i].index < indices[j].index
}) })
// Update index entries with dynamic width // Update index entries with dynamic width
@ -874,15 +892,19 @@ func main() {
writeIcon = "[#5555ff]⚫" writeIcon = "[#5555ff]⚫"
} }
// Add data stream indicator
streamIndicator := " "
if isDataStream(idx.index, dataStreamResp) {
streamIndicator = "[#bd93f9]⚡[white]"
}
// Calculate document changes // Calculate document changes
activity := indexActivities[idx.index] activity := indexActivities[idx.index]
ingestedStr := "" ingestedStr := ""
if activity != nil && activity.InitialDocsCount < idx.docs { if activity != nil && activity.InitialDocsCount < idx.docs {
docChange := idx.docs - activity.InitialDocsCount docChange := idx.docs - activity.InitialDocsCount
// Pad the ingested string to 12 characters
ingestedStr = fmt.Sprintf("[green]%-12s", fmt.Sprintf("+%s", formatNumber(docChange))) ingestedStr = fmt.Sprintf("[green]%-12s", fmt.Sprintf("+%s", formatNumber(docChange)))
} else { } else {
// When there's no ingestion, still pad with 12 spaces
ingestedStr = fmt.Sprintf("%-12s", "") ingestedStr = fmt.Sprintf("%-12s", "")
} }
@ -901,8 +923,9 @@ func main() {
// Convert the size format before display // Convert the size format before display
sizeStr := convertSizeFormat(idx.storeSize) sizeStr := convertSizeFormat(idx.storeSize)
fmt.Fprintf(indicesPanel, "%s [%s]%-*s[white] [#444444]│[white] %15s [#444444]│[white] %12s [#444444]│[white] %8s [#444444]│[white] %8s [#444444]│[white] %s [#444444]│[white] %-8s\n", fmt.Fprintf(indicesPanel, "%s %s[%s]%-*s[white] [#444444]│[white] %15s [#444444]│[white] %12s [#444444]│[white] %8s [#444444]│[white] %8s [#444444]│[white] %s [#444444]│[white] %-8s\n",
writeIcon, writeIcon,
streamIndicator,
getHealthColor(idx.health), getHealthColor(idx.health),
maxIndexNameLen, maxIndexNameLen,
idx.index, idx.index,
@ -910,7 +933,7 @@ func main() {
sizeStr, sizeStr,
idx.priShards, idx.priShards,
idx.replicas, idx.replicas,
ingestedStr, // Now properly padded ingestedStr,
rateStr) rateStr)
} }
@ -1179,7 +1202,7 @@ func getNodesPanelHeader(maxNodeNameLen int) string {
} }
func getIndicesPanelHeader(maxIndexNameLen int) string { func getIndicesPanelHeader(maxIndexNameLen int) string {
return fmt.Sprintf(" [::b]%-*s [#444444]│[#00ffff] %15s [#444444]│[#00ffff] %12s [#444444]│[#00ffff] %8s [#444444]│[#00ffff] %8s [#444444]│[#00ffff] %-12s [#444444]│[#00ffff] %-8s[white]\n", return fmt.Sprintf(" [::b] %-*s [#444444]│[#00ffff] %15s [#444444]│[#00ffff] %12s [#444444]│[#00ffff] %8s [#444444]│[#00ffff] %8s [#444444]│[#00ffff] %-12s [#444444]│[#00ffff] %-8s[white]\n",
maxIndexNameLen, maxIndexNameLen,
"Index Name", "Index Name",
"Documents", "Documents",
@ -1189,3 +1212,12 @@ func getIndicesPanelHeader(maxIndexNameLen int) string {
"Ingested", "Ingested",
"Rate") "Rate")
} }
func isDataStream(name string, dataStreams DataStreamResponse) bool {
for _, ds := range dataStreams.DataStreams {
if ds.Name == name {
return true
}
}
return false
}