gosighttemplate

package
v0.0.0-...-520c4d9 Latest Latest
Warning

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

Go to latest
Published: May 13, 2025 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContainerMetrics = []model.MetricSelector{
	{Name: "container.podman.uptime_seconds", Namespace: "Container", SubNamespace: "Container.Podman", Instant: true},
	{Name: "container.podman.running", Namespace: "Container", SubNamespace: "Container.Podman", Instant: true},
	{Name: "container.podman.cpu_percent", Namespace: "Container", SubNamespace: "Container.Podman", Instant: true},
	{Name: "container.podman.mem_usage_bytes", Namespace: "Container", SubNamespace: "Container.Podman", Instant: true},
	{Name: "container.podman.mem_limit_bytes", Namespace: "Container", SubNamespace: "Container.Podman", Instant: true},
	{Name: "container.podman.net_rx_bytes", Namespace: "Container", SubNamespace: "Container.Podman", Instant: true},
	{Name: "container.podman.net_tx_bytes", Namespace: "Container", SubNamespace: "Container.Podman", Instant: true},
}
View Source
var HostMetrics = []model.MetricSelector{
	{Name: "system.cpu.count_physical", Namespace: "System", SubNamespace: "System.CPU", Instant: true},
	{Name: "system.cpu.usage_percent", Namespace: "System", SubNamespace: "System.CPU", Instant: true},
	{Name: "system.cpu.time_user", Namespace: "System", SubNamespace: "System.CPU", Instant: false},
	{Name: "system.cpu.time_system", Namespace: "System", SubNamespace: "System.CPU", Instant: false},
	{Name: "system.cpu.time_idle", Namespace: "System", SubNamespace: "System.CPU", Instant: false},
	{Name: "system.cpu.time_nice", Namespace: "System", SubNamespace: "System.CPU", Instant: false},
	{Name: "system.cpu.time_guest", Namespace: "System", SubNamespace: "System.CPU", Instant: false},
	{Name: "system.cpu.time_guest_nice", Namespace: "System", SubNamespace: "System.CPU", Instant: false},
	{Name: "system.cpu.time_iowait", Namespace: "System", SubNamespace: "System.CPU", Instant: false},
	{Name: "system.cpu.time_irq", Namespace: "System", SubNamespace: "System.CPU", Instant: false},
	{Name: "system.cpu.time_softirq", Namespace: "System", SubNamespace: "System.CPU", Instant: false},
	{Name: "system.cpu.time_steal", Namespace: "System", SubNamespace: "System.CPU", Instant: false},
	{Name: "system.cpu.clock_mhz", Namespace: "System", SubNamespace: "System.CPU", Instant: true},
	{Name: "system.cpu.count_logical", Namespace: "System", SubNamespace: "System.CPU", Instant: true},

	{Name: "system.memory.available", Namespace: "System", SubNamespace: "System.Memory", Instant: true},
	{Name: "system.memory.used", Namespace: "System", SubNamespace: "System.Memory", Instant: true},
	{Name: "system.memory.used_percent", Namespace: "System", SubNamespace: "System.Memory", Instant: false},
	{Name: "system.memory.total", Namespace: "System", SubNamespace: "System.Memory", Instant: true},

	{Name: "system.host.procs", Namespace: "System", SubNamespace: "System.Host", Instant: true},
	{Name: "system.host.users_loggedin", Namespace: "System", SubNamespace: "System.Host", Instant: true},
	{Name: "system.host.info", Namespace: "System", SubNamespace: "System.Host", Instant: true},
	{Name: "system.host.uptime", Namespace: "System", SubNamespace: "System.Host", Instant: true},

	{Name: "system.diskio.read_bytes", Namespace: "System", SubNamespace: "System.DiskIO", Instant: false},
	{Name: "system.diskio.read_time", Namespace: "System", SubNamespace: "System.DiskIO", Instant: false},
	{Name: "system.diskio.write_time", Namespace: "System", SubNamespace: "System.DiskIO", Instant: false},
	{Name: "system.diskio.merged_read_count", Namespace: "System", SubNamespace: "System.DiskIO", Instant: false},
	{Name: "system.diskio.merged_write_count", Namespace: "System", SubNamespace: "System.DiskIO", Instant: false},
	{Name: "system.diskio.weighted_io", Namespace: "System", SubNamespace: "System.DiskIO", Instant: false},
	{Name: "system.diskio.read_count", Namespace: "System", SubNamespace: "System.DiskIO", Instant: false},
	{Name: "system.diskio.write_count", Namespace: "System", SubNamespace: "System.DiskIO", Instant: false},
	{Name: "system.diskio.write_bytes", Namespace: "System", SubNamespace: "System.DiskIO", Instant: false},
	{Name: "system.diskio.io_time", Namespace: "System", SubNamespace: "System.DiskIO", Instant: false},

	{Name: "system.disk.used_percent", Namespace: "System", SubNamespace: "System.Disk", Instant: false},
	{Name: "system.disk.inodes_total", Namespace: "System", SubNamespace: "System.Disk", Instant: true},
	{Name: "system.disk.total", Namespace: "System", SubNamespace: "System.Disk", Instant: true},
	{Name: "system.disk.used", Namespace: "System", SubNamespace: "System.Disk", Instant: true},
	{Name: "system.disk.inodes_used", Namespace: "System", SubNamespace: "System.Disk", Instant: true},
	{Name: "system.disk.inodes_free", Namespace: "System", SubNamespace: "System.Disk", Instant: true},
	{Name: "system.disk.inodes_used_percent", Namespace: "System", SubNamespace: "System.Disk", Instant: false},
	{Name: "system.disk.free", Namespace: "System", SubNamespace: "System.Disk", Instant: true},

	{Name: "system.network.packets_recv", Namespace: "System", SubNamespace: "System.Network", Instant: false},
	{Name: "system.network.err_in", Namespace: "System", SubNamespace: "System.Network", Instant: false},
	{Name: "system.network.err_out", Namespace: "System", SubNamespace: "System.Network", Instant: false},
	{Name: "system.network.bytes_sent", Namespace: "System", SubNamespace: "System.Network", Instant: false},
	{Name: "system.network.bytes_recv", Namespace: "System", SubNamespace: "System.Network", Instant: false},
	{Name: "system.network.packets_sent", Namespace: "System", SubNamespace: "System.Network", Instant: false},
}

Functions

func Div

func Div(a, b float64) float64

Div performs safe division, returning 0 if the divisor is zero.

func FlattenInstant

func FlattenInstant(rows []model.MetricRow) map[string]float64

FlattenInstant flattens the MetricRows returned by store and makes it usable for template

func FlattenRange

func FlattenRange(rows []model.MetricRow) map[string][]model.MetricPoint

func FormatUptime

func FormatUptime(seconds float64) string

func GetMetricNames

func GetMetricNames(metrics []model.MetricSelector, instantOnly bool) []string

func HasPermission

func HasPermission(userPermissions []string, permission string) bool

HasPermission checks if a user has a specific permission.

func HasPrefix

func HasPrefix(s, prefix string) bool

func HumanizeBytes

func HumanizeBytes(b float64) string

HumanizeBytes converts a byte size in bytes to a human-readable string.

func Marshal

func Marshal(v interface{}) template.JS

Marshal converts a Go value to a JSON string and returns it as a template.JS type.

func SafeHTML

func SafeHTML(s string) template.HTML

SafeHTML returns a template.HTML type to safely render HTML content.

func Seq

func Seq(from, to int) []int

Seq generates a slice of integers from `from` to `to`, inclusive.

func Since

func Since(ts string) string

Since calculates the time duration since a given timestamp in seconds.

Types

type Breadcrumb struct {
	Label string
	URL   string
}

Breadcrumb represents a single breadcrumb in the navigation trail.

type GoSightTemplate

type GoSightTemplate struct {
	Cfg *config.Config

	Tmpl *template.Template

	MetricStore metricstore.MetricStore
	MetricIndex *metricindex.MetricIndex
	UserStore   userstore.UserStore
	// contains filtered or unexported fields
}

func NewGoSightTemplate

func NewGoSightTemplate(
	ctx context.Context,
	cfg *config.Config,
	metricStore metricstore.MetricStore,
	metricIndex *metricindex.MetricIndex,
	userStore userstore.UserStore) (*GoSightTemplate, error)

func (*GoSightTemplate) BuildPageData

func (t *GoSightTemplate) BuildPageData(user *usermodel.User, breadcrumbs, labels map[string]string, path, title string,
	meta *model.Meta, permissions []string) *TemplateData

BuildPageData constructs the TemplateData for rendering a page.

func (*GoSightTemplate) RenderTemplate

func (t *GoSightTemplate) RenderTemplate(w http.ResponseWriter, layout, page string, data any) error

RenderTemplate renders a template with the given layout and page, passing in the provided data.

type TemplateData

type TemplateData struct {
	Title       string
	User        *usermodel.User
	UserData    usermodel.SafeUser
	Permissions []string
	Metrics     map[string]float64 // TODO: Revaluate need.
	Timeseries  map[string][]model.MetricPoint
	Tags        map[string]string
	Labels      map[string]string
	Meta        *model.Meta
	Breadcrumbs []Breadcrumb
	CurrentPath string
}

TemplateData holds the data passed to templates for rendering.

Jump to

Keyboard shortcuts

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