promtop

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CPU_RATE_INTERVAL is the time window in seconds used to calculate CPU usage rates
	CPU_RATE_INTERVAL = 60

	// UPDATE_INTERVAL is the time between data updates in seconds
	UPDATE_INTERVAL = 1
)

Variables

This section is empty.

Functions

func CPURateIntervalString added in v0.0.2

func CPURateIntervalString() string

CPURateIntervalString returns the CPU rate interval formatted for Prometheus queries (e.g., "60s")

func Dashboard

func Dashboard(sources []Cache, sourceNames []string)

func ExampleDashboard

func ExampleDashboard(width, height int) string

ExampleDashboard demonstrates how to use Pane and layout helpers

func FourPaneGrid

func FourPaneGrid(width, height int) string

FourPaneGrid demonstrates using Wrap to create a 2x2 grid of metric panes

func Horizontal

func Horizontal(panes ...Pane) string

Horizontal renders panes side by side

func MaxCPURecords added in v0.0.2

func MaxCPURecords() int

MaxCPURecords returns the maximum number of CPU readings to store Calculated as CPU_RATE_INTERVAL / UPDATE_INTERVAL, rounded

func NewDashboard

func NewDashboard(sources []Cache, sourceNames []string) *dashboardModel

func SimpleTwoColumnLayout

func SimpleTwoColumnLayout(leftContent, rightContent string, width, height int) string

SimpleTwoColumnLayout creates a basic two-column dashboard

func ThreeColumnLayout

func ThreeColumnLayout(left, center, right string, width, height int) string

ThreeColumnLayout creates a three-column dashboard

func UpdateDuration added in v0.0.2

func UpdateDuration() time.Duration

UpdateDuration returns the update interval as a time.Duration

func Vertical

func Vertical(panes ...Pane) string

Vertical renders panes stacked vertically

func Wrap

func Wrap(panesPerRow int, panes ...Pane) string

Wrap renders panes in a grid with automatic wrapping panesPerRow specifies how many panes per row before wrapping Example: Wrap(2, pane1, pane2, pane3, pane4) creates a 2x2 grid

Types

type Cache

type Cache struct {
	Data
	// contains filtered or unexported fields
}

func (*Cache) GetNodes

func (c *Cache) GetNodes() []string

func (*Cache) MaxNodeNameLen

func (c *Cache) MaxNodeNameLen() int

func (*Cache) NumberOfNodes

func (c *Cache) NumberOfNodes() int

type Chart

type Chart struct {
	NodeRef    NodeRef
	ChartType  string               // "cpu", "memory", "disk", "network"
	CpuData    map[string][]float64 // CPU name -> time series
	MemoryData map[string]float64   // Memory metrics: total, available, used, used_percent, cached, buffers
}

Chart represents a chart displaying metrics for a specific node

type DashboardLayout

type DashboardLayout struct {
	// contains filtered or unexported fields
}

DashboardLayout handles positioning and rendering of multiple panes

func NewDashboardLayout

func NewDashboardLayout(width, height int) *DashboardLayout

NewDashboardLayout creates a new dashboard layout

func (*DashboardLayout) AddPane

func (d *DashboardLayout) AddPane(pane Pane)

AddPane adds a pane to the layout

func (*DashboardLayout) SetSize

func (d *DashboardLayout) SetSize(width, height int)

SetSize updates the layout dimensions

type Data

type Data interface {
	GetCpu(string) map[string]float64
	GetMemory(string) map[string]float64
	GetNodes() []string
	Check() error
	GetType() string // Returns "prometheus" or "node_exporter"
}

type DetectedSource

type DetectedSource struct {
	Data Data
	Name string
}

DetectedSource holds a data source and its display name

func TryConnectWithFallbacks

func TryConnectWithFallbacks(baseURL *url.URL) []DetectedSource

TryConnectWithFallbacks tries multiple URL variants to connect to data sources Returns all successful connections (can be both Prometheus and node_exporter)

type GridLayout

type GridLayout struct {
	// contains filtered or unexported fields
}

Grid renders panes in a 2D grid layout

func NewGrid

func NewGrid() *GridLayout

NewGrid creates a new grid layout

func (*GridLayout) AddRow

func (g *GridLayout) AddRow(panes ...Pane)

AddRow adds a row of panes to the grid

func (*GridLayout) Render

func (g *GridLayout) Render() string

Render renders the grid layout

type NodeExporterData

type NodeExporterData struct {
	// contains filtered or unexported fields
}

func NewNodeExporterData

func NewNodeExporterData(urls []*url.URL) (*NodeExporterData, error)

func (*NodeExporterData) Check

func (n *NodeExporterData) Check() error

func (*NodeExporterData) GetCpu

func (n *NodeExporterData) GetCpu(node string) map[string]float64

func (*NodeExporterData) GetMemory added in v0.0.2

func (n *NodeExporterData) GetMemory(node string) map[string]float64

func (*NodeExporterData) GetNodes

func (n *NodeExporterData) GetNodes() []string

func (*NodeExporterData) GetType

func (n *NodeExporterData) GetType() string

type NodeRef

type NodeRef struct {
	Type        string // prometheus, prometheus_node, node_exporter
	SourceIndex int    // Index into sources array
	SourceName  string // Human-readable source name (hostname from URL)
	NodeName    string // Node name from GetNodes() (empty if IsSourceHeader)
	DisplayName string // Formatted for UI
}

type Pane

type Pane struct {
	// contains filtered or unexported fields
}

Pane represents a bordered panel in the dashboard.

Example usage:

pane := NewPane("CPU Metrics", 40, 10).
    SetContent("Core 0: 45%\nCore 1: 23%").
    SetFocused(true)
fmt.Println(pane.Render())

Panes can be composed using layout helpers:

leftPane := NewPane("Left", 30, 20).SetContent("content")
rightPane := NewPane("Right", 50, 20).SetContent("content")
dashboard := Horizontal(leftPane, rightPane)

Pane implements tea.Model so it can be used as a standalone Bubble Tea component

func MetricPane

func MetricPane(title string, metrics map[string]string, width, height int) Pane

MetricPane creates a formatted metric display pane

func NewPane

func NewPane(title string, width, height int) Pane

NewPane creates a new pane with default styling

func (Pane) Init

func (p Pane) Init() tea.Cmd

Init implements tea.Model

func (Pane) Render

func (p Pane) Render() string

Render is a convenience method that calls View()

func (Pane) SetBorderStyle

func (p Pane) SetBorderStyle(style lipgloss.Style) Pane

SetBorderStyle sets the border style

func (Pane) SetContent

func (p Pane) SetContent(content string) Pane

SetContent sets the pane content

func (Pane) SetFocused

func (p Pane) SetFocused(focused bool) Pane

SetFocused sets the focus state

func (Pane) SetSize

func (p Pane) SetSize(width, height int) Pane

SetSize sets the pane dimensions

func (Pane) SetTitle

func (p Pane) SetTitle(title string) Pane

SetTitle sets the pane title

func (Pane) SetTitleStyle

func (p Pane) SetTitleStyle(style lipgloss.Style) Pane

SetTitleStyle sets the title style

func (Pane) Update

func (p Pane) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model

func (Pane) View

func (p Pane) View() string

View implements tea.Model

type PrometheusData

type PrometheusData struct {
	// contains filtered or unexported fields
}

func NewPrometheusData

func NewPrometheusData(prometheusURL *url.URL) (*PrometheusData, error)

func (*PrometheusData) Check

func (p *PrometheusData) Check() error

func (*PrometheusData) GetCpu

func (p *PrometheusData) GetCpu(node string) map[string]float64

func (*PrometheusData) GetMemory added in v0.0.2

func (p *PrometheusData) GetMemory(node string) map[string]float64

func (*PrometheusData) GetNodes

func (p *PrometheusData) GetNodes() []string

func (*PrometheusData) GetType

func (p *PrometheusData) GetType() string

type TabSet

type TabSet struct {
	// contains filtered or unexported fields
}

TabSet manages multiple charts with tab navigation

func NewTabSet

func NewTabSet() *TabSet

NewTabSet creates a new TabSet

func (*TabSet) AddChart

func (ts *TabSet) AddChart(chart Chart) *TabSet

AddChart adds a chart to the tab set

func (*TabSet) GetChartPointer added in v0.0.2

func (ts *TabSet) GetChartPointer(index int) *Chart

GetChartPointer returns a pointer to a chart at the given index

func (*TabSet) GetCharts

func (ts *TabSet) GetCharts() []Chart

GetCharts returns all charts in the tab set

func (*TabSet) GetSelectedTab

func (ts *TabSet) GetSelectedTab() int

GetSelectedTab returns the currently selected tab index

func (*TabSet) NextTab

func (ts *TabSet) NextTab() *TabSet

NextTab moves to the next tab (wraps around)

func (*TabSet) PrevTab

func (ts *TabSet) PrevTab() *TabSet

PrevTab moves to the previous tab (wraps around)

func (*TabSet) RemoveCurrentTab

func (ts *TabSet) RemoveCurrentTab() bool

RemoveCurrentTab removes the currently selected tab Returns true if tab was removed, false if it was the last tab

func (*TabSet) Render

func (ts *TabSet) Render() string

Render renders the tab set with tabs and active chart content

func (*TabSet) SelectTab

func (ts *TabSet) SelectTab(index int) *TabSet

SelectTab changes the active tab

func (*TabSet) SetSize

func (ts *TabSet) SetSize(width, height int) *TabSet

SetSize sets the dimensions for rendering

func (*TabSet) String

func (ts *TabSet) String() string

String is a convenience method that calls Render

type WrapTable

type WrapTable struct {
	// contains filtered or unexported fields
}

WrapTable wraps lipgloss table to support height-based wrapping When data exceeds maxHeight, it creates multiple tables side-by-side

func NewWrapTable

func NewWrapTable() *WrapTable

NewWrapTable creates a new wrap table

func (*WrapTable) Border

func (wt *WrapTable) Border(border lipgloss.Border) *WrapTable

Border sets the table border style

func (*WrapTable) BorderStyle

func (wt *WrapTable) BorderStyle(style lipgloss.Style) *WrapTable

BorderStyle sets the border styling

func (*WrapTable) Headers

func (wt *WrapTable) Headers(headers ...string) *WrapTable

Headers sets the table headers

func (*WrapTable) MaxHeight

func (wt *WrapTable) MaxHeight(height int) *WrapTable

MaxHeight sets the maximum height constraint

func (*WrapTable) MaxWidth

func (wt *WrapTable) MaxWidth(width int) *WrapTable

MaxWidth sets the maximum width constraint

func (*WrapTable) Render

func (wt *WrapTable) Render() string

Render renders the table with wrapping if needed

func (*WrapTable) Rows

func (wt *WrapTable) Rows(rows ...[]string) *WrapTable

Rows sets the table rows

func (*WrapTable) String

func (wt *WrapTable) String() string

String is a convenience method that calls Render

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL