common

package
v0.0.0-...-04720bc Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DividerText  = "[...]"
	DiverTextLen = len(DividerText)
)

Variables

This section is empty.

Functions

func DisplayRatio

func DisplayRatio(current uint64, total uint64, opts ...DisplayOptions) string

func FormatBytes

func FormatBytes(bytes uint64) string

func Shorten

func Shorten(s string, truncateLen int) string

Types

type CgroupStatsCollection

type CgroupStatsCollection interface {
	// ToCsvOutput will transform the underlying collection into a format which can be written to a CSV file.
	ToCsvOutput() *CsvOutput
	// ToDisplayOutput will transform the underlying collection into a format which can be displayed to the screen.
	ToDisplayOutput() *DisplayOutput
	// ToVerboseOutput will transform the write the given collection to the provided writer. There is no guarantee about
	// the format of the data that is written to the given writer.
	ToVerboseOutput(writer io.Writer)
}

type CgroupStatsProvider

type CgroupStatsProvider interface {
	// ListCgroupsByPrefix will return a list of cgroup names that start with the given prefix.
	ListCgroupsByPrefix(cgroupPrefix string) []string
	// GetCgroupStatsByPrefix will return stats for cgroups that start with the given prefix.
	GetCgroupStatsByPrefix(prefix string) (CgroupStatsCollection, error)
	// GetCgroupStatsByName will return stats for the cgroup that matches the given name.
	GetCgroupStatsByName(name string) (CgroupStatsCollection, error)
}

type Collection

type Collection[T any] struct {
	Stats              []T
	CsvHeadersProvider func() []string
	CsvRowTransformer  func(T) []string

	DisplayHeadersProvider func() []interface{}
	DisplayRowTransformer  func(T) []interface{}

	VerboseOutputTransformer func(io.Writer, []T)
}

func (Collection[T]) ToCsvOutput

func (c Collection[T]) ToCsvOutput() *CsvOutput

func (Collection[T]) ToDisplayOutput

func (c Collection[T]) ToDisplayOutput() *DisplayOutput

func (Collection[T]) ToVerboseOutput

func (c Collection[T]) ToVerboseOutput(w io.Writer)

type CommonCgroupStatsProvider

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

func NewCommonCgroupStatsProvider

func NewCommonCgroupStatsProvider(rootDir string) *CommonCgroupStatsProvider

func (*CommonCgroupStatsProvider) ListCgroupsByPrefix

func (c *CommonCgroupStatsProvider) ListCgroupsByPrefix(cgroupPrefix string) []string

type CsvOutput

type CsvOutput struct {
	Headers []string
	Rows    [][]string
}

type DisplayOptions

type DisplayOptions func(d *displayOptions)

func WithBytes

func WithBytes() DisplayOptions

func WithTotal

func WithTotal() DisplayOptions

type DisplayOutput

type DisplayOutput struct {
	Headers []interface{}
	Rows    [][]interface{}
}

Jump to

Keyboard shortcuts

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