-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP - add function get container stats * add view stats container * fix test --------- Co-authored-by: ernesto <[email protected]>
- Loading branch information
1 parent
3f8aa4d
commit f16aaa0
Showing
6 changed files
with
158 additions
and
8 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
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
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,55 @@ | ||
package models | ||
|
||
import ( | ||
"dockerniceui/docker" | ||
"dockerniceui/utils" | ||
"fmt" | ||
|
||
"github.com/charmbracelet/bubbles/viewport" | ||
"github.com/charmbracelet/glamour" | ||
"github.com/charmbracelet/lipgloss" | ||
) | ||
|
||
func NewContainerStats(stats docker.MyContainerStats, createTable utils.CreateTableFunc) (viewport.Model, error) { | ||
content := getContentStats(stats) | ||
const width = 120 | ||
|
||
vp := viewport.New(width, 30) | ||
vp.Style = lipgloss.NewStyle(). | ||
BorderStyle(lipgloss.RoundedBorder()). | ||
BorderForeground(lipgloss.Color("62")). | ||
PaddingRight(2) | ||
|
||
renderer, err := glamour.NewTermRenderer( | ||
glamour.WithAutoStyle(), | ||
glamour.WithWordWrap(width), | ||
) | ||
if err != nil { | ||
return viewport.Model{}, err | ||
} | ||
|
||
str, err := renderer.Render(content) | ||
if err != nil { | ||
return viewport.Model{}, err | ||
} | ||
|
||
vp.SetContent(str) | ||
|
||
return vp, nil | ||
} | ||
|
||
func getContentStats(stats docker.MyContainerStats) string { | ||
response := "" | ||
|
||
response += utils.CreateTable("# Stats", []string{"CPU", "MEM USAGE/LIMIT", "MEM", "PIDS"}, | ||
[][]string{ | ||
{ | ||
fmt.Sprintf("%.2f%%", stats.CPUPer), | ||
fmt.Sprintf("%s / %s", stats.MemUsage, stats.MemLimit), | ||
fmt.Sprintf("%.2f%%", stats.MemPer), | ||
fmt.Sprintf("%d", stats.PID), | ||
}, | ||
}) | ||
|
||
return response | ||
} |
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
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
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