widgets

package
v0.0.0-...-cca9b4c Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2015 License: GPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const ConnectionsWidgetType = "connections"
View Source
const LoadWidgetType = "load"
View Source
const MeminfoWidgetType = "meminfo"
View Source
const NetworkWidgetType = "network"
View Source
const UptimeWidgetType = "uptime"

Variables

View Source
var AllWidgets = map[string]WidgetInitiator{
	LoadWidgetType:        func() Widget { return &LoadWidget{} },
	UptimeWidgetType:      func() Widget { return &UptimeWidget{} },
	MeminfoWidgetType:     func() Widget { return &MeminfoWidget{} },
	ConnectionsWidgetType: func() Widget { return &ConnectionsWidget{} },
	NetworkWidgetType:     func() Widget { return &NetworkWidget{} },
}
View Source
var LoadAverageRegexp = regexp.MustCompile("^([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)")
View Source
var LoadCoresRegexp = regexp.MustCompile("^processor")
View Source
var MeminfoRegexp = regexp.MustCompile("^([^:]*):\\s+(\\d+)")
View Source
var NetworkDeviceSplitRegexp = regexp.MustCompile("\\s+")
View Source
var TCPInfoRegexp = regexp.MustCompile("^\\s*(\\d+): ([0-9a-fA-F]+):([0-9a-fA-F]+) ([0-9a-fA-F]+):([0-9a-fA-F]+) ([0-9a-fA-F]+)")

Functions

func CombineToSeconds

func CombineToSeconds(days, hours, minutes, seconds int) int

func GatherCores

func GatherCores() (int, error)

func GatherLoadAverage

func GatherLoadAverage() (one, five, fifteen string, err error)

func GatherLocalIPAddresses

func GatherLocalIPAddresses() ([]net.IP, error)

func GatherTCPConnections

func GatherTCPConnections() (tcp4, tcp6 int, err error)

func GatherUptime

func GatherUptime() (days, hours, minutes, seconds int, err error)

func SplitSeconds

func SplitSeconds(in int) (days, hours, minutes, seconds int)

Types

type BulkElement

type BulkElement struct {
	Type       string          `json:"type"`
	Identifier string          `json:"identifier"`
	Widget     json.RawMessage `json:"widget"`
}

type ConnectionsWidget

type ConnectionsWidget struct {
	TCP4 int `json:"tcp4"`
	TCP6 int `json:"tcp6"`
}

func (*ConnectionsWidget) Configuration

func (widget *ConnectionsWidget) Configuration() interface{}

func (*ConnectionsWidget) Configure

func (widget *ConnectionsWidget) Configure(json.RawMessage) error

func (*ConnectionsWidget) HasData

func (widget *ConnectionsWidget) HasData() bool

func (*ConnectionsWidget) Identifier

func (widget *ConnectionsWidget) Identifier() string

func (*ConnectionsWidget) Name

func (widget *ConnectionsWidget) Name() string

func (*ConnectionsWidget) Start

func (widget *ConnectionsWidget) Start() error

func (*ConnectionsWidget) Type

func (widget *ConnectionsWidget) Type() string

func (*ConnectionsWidget) Update

func (widget *ConnectionsWidget) Update() error

type LoadWidget

type LoadWidget struct {
	One     string `json:"one"`
	Five    string `json:"five"`
	Fifteen string `json:"fifteen"`
	Cores   int    `json:"cores"`
}

func (*LoadWidget) Configuration

func (widget *LoadWidget) Configuration() interface{}

func (*LoadWidget) Configure

func (widget *LoadWidget) Configure(json.RawMessage) error

func (*LoadWidget) HasData

func (widget *LoadWidget) HasData() bool

func (*LoadWidget) Identifier

func (widget *LoadWidget) Identifier() string

func (*LoadWidget) Name

func (widget *LoadWidget) Name() string

func (*LoadWidget) Start

func (widget *LoadWidget) Start() error

func (*LoadWidget) Type

func (widget *LoadWidget) Type() string

func (*LoadWidget) Update

func (widget *LoadWidget) Update() error

type Meminfo

type Meminfo struct {
	MainTotalKB   uint64
	MainFreeKB    uint64
	MainBuffersKB uint64
	MainCachedKB  uint64

	MainUsedKB uint64
}

func GatherMeminfo

func GatherMeminfo() (*Meminfo, error)

type MeminfoWidget

type MeminfoWidget struct {
	Total int `json:"total"`
	Used  int `json:"used"`
}

func (*MeminfoWidget) Configuration

func (widget *MeminfoWidget) Configuration() interface{}

func (*MeminfoWidget) Configure

func (widget *MeminfoWidget) Configure(json.RawMessage) error

func (*MeminfoWidget) HasData

func (widget *MeminfoWidget) HasData() bool

func (*MeminfoWidget) Identifier

func (widget *MeminfoWidget) Identifier() string

func (*MeminfoWidget) Name

func (widget *MeminfoWidget) Name() string

func (*MeminfoWidget) Start

func (widget *MeminfoWidget) Start() error

func (*MeminfoWidget) Type

func (widget *MeminfoWidget) Type() string

func (*MeminfoWidget) Update

func (widget *MeminfoWidget) Update() error

type NetworkDevice

type NetworkDevice struct {
	Interface        string
	ReceivedBytes    uint64
	TransmittedBytes uint64
}

func GatherNetDevInfo

func GatherNetDevInfo() ([]NetworkDevice, error)

func NewNetworkDevice

func NewNetworkDevice(line string) *NetworkDevice

type NetworkWidget

type NetworkWidget struct {
	Interface   string  `json:"interface"`
	Interval    float64 `json:"interval"`
	Received    int     `json:"received"`
	Transmitted int     `json:"transmitted"`
	// contains filtered or unexported fields
}

func (*NetworkWidget) Configuration

func (widget *NetworkWidget) Configuration() interface{}

func (*NetworkWidget) Configure

func (widget *NetworkWidget) Configure(c json.RawMessage) error

func (*NetworkWidget) HasData

func (widget *NetworkWidget) HasData() bool

func (*NetworkWidget) Identifier

func (widget *NetworkWidget) Identifier() string

func (*NetworkWidget) Name

func (widget *NetworkWidget) Name() string

func (*NetworkWidget) Start

func (widget *NetworkWidget) Start() error

func (*NetworkWidget) Type

func (widget *NetworkWidget) Type() string

func (*NetworkWidget) Update

func (widget *NetworkWidget) Update() error

type TCPInfo

type TCPInfo struct {
	Entry      uint     // sl
	LocalIP    net.IP   // local_address
	LocalPort  uint16   // local_address
	RemoteIP   net.IP   // remote_address
	RemotePort uint16   // remote_address
	State      TCPState // st
}

func GatherTCP4Infos

func GatherTCP4Infos() ([]TCPInfo, error)

func GatherTCP6Infos

func GatherTCP6Infos() ([]TCPInfo, error)

func GatherTCPInfos

func GatherTCPInfos(filename string) ([]TCPInfo, error)

func NewTCPInfo

func NewTCPInfo(line string) (*TCPInfo, error)

type TCPState

type TCPState int
const (
	TCPEstablished TCPState = 1
	TCPSynSent     TCPState = 2
	TCPSynRecv     TCPState = 3
	TCPFinWait1    TCPState = 4
	TCPFinWait2    TCPState = 5
	TCPTimeWait    TCPState = 6
	TCPClose       TCPState = 7
	TCPCloseWait   TCPState = 8
	TCPLastAck     TCPState = 9
	TCPListen      TCPState = 10
	TCPClosing     TCPState = 11
)

type UptimeWidget

type UptimeWidget struct {
	LastUpdated time.Time
	Days        int
	Hours       int
	Minutes     int
	Seconds     int
}

func (*UptimeWidget) Configuration

func (widget *UptimeWidget) Configuration() interface{}

func (*UptimeWidget) Configure

func (widget *UptimeWidget) Configure(json.RawMessage) error

func (*UptimeWidget) HasData

func (widget *UptimeWidget) HasData() bool

func (*UptimeWidget) Identifier

func (widget *UptimeWidget) Identifier() string

func (*UptimeWidget) MarshalJSON

func (widget *UptimeWidget) MarshalJSON() ([]byte, error)

func (*UptimeWidget) Name

func (widget *UptimeWidget) Name() string

func (*UptimeWidget) Start

func (widget *UptimeWidget) Start() error

func (*UptimeWidget) Type

func (widget *UptimeWidget) Type() string

func (*UptimeWidget) UnmarshalJSON

func (widget *UptimeWidget) UnmarshalJSON(data []byte) error

func (*UptimeWidget) Update

func (widget *UptimeWidget) Update() error

type Widget

type Widget interface {
	// Name should return a human-readable name for this widget describing what
	// it does.
	Name() string

	// Type should return the type of the widget.
	// unique among other widgets.
	Type() string

	// Identifier should return an unique identifier for the widget. It should
	// be based on its type and configuration.
	Identifier() string

	// HasData should return whether the widget has data to display. This should
	// default to false and become true when the widget gets information from
	// the client for the first time.
	HasData() bool

	// Update should update widget with the most recent information
	Update() error

	// Configure should configure a widget using data from the configuration
	// file.
	Configure(data json.RawMessage) error

	// Configuration should return the widget configuration
	Configuration() interface{}

	// Start should start any background processes needed to e.g. gather data,
	// if necessary.
	Start() error
}

Widget defines the interface for a general widget.

type WidgetInitiator

type WidgetInitiator func() Widget

Jump to

Keyboard shortcuts

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