ostent

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2016 License: MIT Imports: 35 Imported by: 6

Documentation

Overview

Package ostent is the library part of ostent cmd.

Index

Constants

View Source
const VERSION = "0.6.2"

VERSION of the latest known release. Unused in non-bin mode. Compared with in github.com/ostrost/ostent/main.go MUST BE semver compatible: no two digits ("X.Y") allowed.

Variables

View Source
var (
	RXlo      = regexp.MustCompile(`^lo\d*$`)
	RXvbr     = regexp.MustCompile(`^virbr\d+$`)
	RXvbrnic  = regexp.MustCompile(`^virbr\d+-nic$`)
	RXbridge  = regexp.MustCompile(`^bridge\d+$`)
	RXvboxnet = regexp.MustCompile(`^vboxnet\d+$`)
	RXfw      = regexp.MustCompile(`^fw\d+$`)
	RXgif     = regexp.MustCompile(`^gif\d+$`)
	RXstf     = regexp.MustCompile(`^stf\d+$`)
	RXwdl     = regexp.MustCompile(`^awdl\d+$`)
	RXairdrop = regexp.MustCompile(`^p2p\d+$`)
)

These are regexps to match network interfaces.

Functions

func AddAssetPathContextFunc

func AddAssetPathContextFunc(path string) func(http.Handler) http.Handler

func AddBackground

func AddBackground(j backgroundHandler)

func AssetInfoFunc

func AssetInfoFunc(infofunc func(string) (os.FileInfo, error)) func(string) (TimeInfo, error)

AssetInfoFunc wraps bindata's AssetInfo func. Returns typecasted infofunc.

func AssetReadFunc

func AssetReadFunc(readfunc func(string) ([]byte, error)) func(string) ([]byte, error)

AssetReadFunc wraps bindata's Asset func. Returns readfunc itself.

func CollectLoop

func CollectLoop()

CollectLoop is a ostent background job: collect the metrics.

func ContextParams added in v0.6.2

func ContextParams(r *http.Request) (httprouter.Params, error)

func Distrib added in v0.6.1

func Distrib() (string, error)

func Fetch added in v0.6.1

func Fetch(keys *params.FetchKeys) error

func FetchExtract added in v0.6.1

func FetchExtract(jdata *gabs.Container, keys []string) (*gabs.Container, interface{})

func FetchOne added in v0.6.1

func FetchOne(k params.FetchKey, keys []string) error

func FormatCPU

func FormatCPU(label string, mc *system.MetricCPU) system.CPUData

func FormatDF

func FormatDF(md *system.MetricDF) system.DFData

func FormatIF

func FormatIF(mi *system.MetricIF) system.IFData

func FormatIF1000

func FormatIF1000(diff *system.GaugeDiff, info1, info2 *string)

func FormatIF1024

func FormatIF1024(diff *system.GaugeDiff, info1, info2 *string)

func HandleFunc added in v0.6.2

func HandleFunc(hf http.HandlerFunc) httprouter.Handle

HandleFunc wraps hf into handle.

func HandleThen added in v0.6.2

func HandleThen(then func(http.Handler) http.Handler) func(http.HandlerFunc) httprouter.Handle

HandleThen wraps then(hf) into handle.

func HardwareIF

func HardwareIF(name string) bool

HardwareIF returns false for known virtual/software network interface name.

func LSBID added in v0.6.1

func LSBID(platform string) string

LSBID is to convert gopsutil platform identifier back to LSB ID form.

func LogHandler added in v0.6.2

func LogHandler(logRequests bool, h http.Handler) http.Handler

func NextSecond

func NextSecond() time.Time

NextSecond returns precisely next second in Time.

func NextSecondDelta

func NextSecondDelta() (time.Time, time.Duration)

NextSecondDelta returns precisely next second in Time and Duration.

func ParamsFunc added in v0.6.2

func ParamsFunc(then func(http.Handler) http.Handler) func(http.HandlerFunc) httprouter.Handle

ParamsFunc wraps then(hf) into handle with context setting by handleParamSetContext.

func ProcName added in v0.6.1

func ProcName(_ int, procName string) string

ProcName returns procName back.

func RunBackground

func RunBackground()

func ServerHandler added in v0.6.2

func ServerHandler(logRequests bool, h http.Handler) http.Handler

Types

type CPUSlice

type CPUSlice []*system.MetricCPU

CPUSlice is a list of MetricCPU.

func (CPUSlice) Len

func (cs CPUSlice) Len() int

Len, Swap and Less satisfy sorting interface.

func (CPUSlice) Less

func (cs CPUSlice) Less(i, j int) bool

func (CPUSlice) Swap

func (cs CPUSlice) Swap(i, j int)

type ContextID

type ContextID int
const (
	CAssetPath ContextID = iota
	CRouterParams
)

type DFSlice

type DFSlice []*system.MetricDF

DFSlice is a list of MetricDF.

type DFSort

type DFSort struct {
	Dfk     *params.Num
	DFSlice DFSlice
}

DFSort is to facilitate DFSlice sorting.

func (DFSort) Len

func (ds DFSort) Len() int

Len, Swap and Less satisfy sorting interface.

func (DFSort) Less

func (ds DFSort) Less(i, j int) (r bool)

func (DFSort) Swap

func (ds DFSort) Swap(i, j int)

type ExportingList added in v0.6.1

type ExportingList []struct{ Name, Endpoint string }

ExportingList is a list to be sorted by .Name: - Entries come from CLI flags which may be specified in any order - That order not preserved since parsing anyway

var (
	// Connections is of unexported conns type to hold active ws connections.
	Connections = conns{/* contains filtered or unexported fields */}
	// Exporting has "exporting to" list (after init)
	Exporting ExportingList
)

func (ExportingList) Len added in v0.6.1

func (el ExportingList) Len() int

func (ExportingList) Less added in v0.6.1

func (el ExportingList) Less(i, j int) bool

func (ExportingList) Swap added in v0.6.1

func (el ExportingList) Swap(i, j int)

type ExportingListing added in v0.6.1

type ExportingListing struct {
	RWMutex sync.RWMutex
	ExportingList
}

ExportingListing keeps "exporting to" list.

func (*ExportingListing) AddExporter added in v0.6.1

func (el *ExportingListing) AddExporter(name string, stringer fmt.Stringer)

type IFSlice

type IFSlice []*system.MetricIF

IFSlice is a list of MetricIF.

func (IFSlice) Len

func (is IFSlice) Len() int

Len, Swap and Less satisfy sorting interface.

func (IFSlice) Less

func (is IFSlice) Less(i, j int) bool

func (IFSlice) Swap

func (is IFSlice) Swap(i, j int)

type IndexData

type IndexData map[string]interface{}

IndexData is a data map for templates and marshalling. Keys (even abbrevs eg CPU) intentionally start with lowercase.

func Updates

func Updates(req *http.Request, para *params.Params) (IndexData, bool, error)

type IndexRegistry

type IndexRegistry struct {
	Registry           metrics.Registry
	PrivateCPUAll      *system.MetricCPU /// metrics.Registry
	PrivateCPURegistry metrics.Registry  // set of MetricCPUs is handled as a metric in this registry
	PrivateIFRegistry  metrics.Registry  // set of system.MetricIFs is handled as a metric in this registry
	PrivateDFRegistry  metrics.Registry  // set of system.MetricDFs is handled as a metric in this registry
	PrivateMutex       sync.Mutex

	RAM  *system.MetricRAM
	Swap system.MetricSwap
	Load *system.MetricLoad

	Mutex sync.Mutex
}
var (
	OstentUpgrade = new(UpgradeInfo)
	Reg1s         *IndexRegistry
)

func (*IndexRegistry) GetCPU

func (ir *IndexRegistry) GetCPU(para *params.Params) []system.CPUData

func (*IndexRegistry) GetDF

func (ir *IndexRegistry) GetDF(para *params.Params) []system.DFData

func (*IndexRegistry) GetIF

func (ir *IndexRegistry) GetIF(para *params.Params) []system.IFData

func (*IndexRegistry) GetOrRegisterPrivateCPU

func (ir *IndexRegistry) GetOrRegisterPrivateCPU(coreno int) *system.MetricCPU

GetOrRegisterPrivateCPU produces a registered in PrivateCPURegistry MetricCPU.

func (*IndexRegistry) GetOrRegisterPrivateDF

func (ir *IndexRegistry) GetOrRegisterPrivateDF(part disk.PartitionStat) *system.MetricDF

func (*IndexRegistry) GetOrRegisterPrivateIF

func (ir *IndexRegistry) GetOrRegisterPrivateIF(name string) *system.MetricIF

GetOrRegisterPrivateIF produces a registered in PrivateIFRegistry system.MetricIF.

func (*IndexRegistry) ListPrivateCPU

func (ir *IndexRegistry) ListPrivateCPU() (cs CPUSlice)

ListPrivateCPU returns list of system.MetricCPU's by traversing the PrivateCPURegistry.

func (*IndexRegistry) ListPrivateDF

func (ir *IndexRegistry) ListPrivateDF() (dfs DFSlice)

ListPrivateDF returns list of system.MetricDF's by traversing the PrivateDFRegistry.

func (*IndexRegistry) ListPrivateIF

func (ir *IndexRegistry) ListPrivateIF() (is IFSlice)

ListPrivateIF returns list of MetricIF's by traversing the PrivateIFRegistry.

func (*IndexRegistry) UpdateCPU

func (ir *IndexRegistry) UpdateCPU(agg cpu.TimesStat, list []cpu.TimesStat)

func (*IndexRegistry) UpdateDF

func (ir *IndexRegistry) UpdateDF(part disk.PartitionStat, usage *disk.UsageStat)

func (*IndexRegistry) UpdateIF

func (ir *IndexRegistry) UpdateIF(ifaddr system.IfAddress)

func (*IndexRegistry) UpdateLA

func (ir *IndexRegistry) UpdateLA(stat load.AvgStat)

func (*IndexRegistry) UpdateMEM added in v0.6.2

func (ir *IndexRegistry) UpdateMEM(ram *mem.VirtualMemoryStat, swap *mem.SwapMemoryStat)

UpdateMEM reads stat and updates ir.RAM and ir.Swap

type NetIO added in v0.6.1

type NetIO struct {
	psnet.IOCountersStat
	IP string
}

func (NetIO) BytesIn added in v0.6.1

func (io NetIO) BytesIn() uint

func (NetIO) BytesOut added in v0.6.1

func (io NetIO) BytesOut() uint

func (NetIO) DropsIn added in v0.6.1

func (io NetIO) DropsIn() uint

func (NetIO) DropsOut added in v0.6.1

func (io NetIO) DropsOut() uint

func (NetIO) ErrorsIn added in v0.6.1

func (io NetIO) ErrorsIn() uint

func (NetIO) ErrorsOut added in v0.6.1

func (io NetIO) ErrorsOut() uint

func (NetIO) GetIP added in v0.6.1

func (io NetIO) GetIP() string

func (NetIO) GetName added in v0.6.1

func (io NetIO) GetName() string

func (NetIO) PacketsIn added in v0.6.1

func (io NetIO) PacketsIn() uint

func (NetIO) PacketsOut added in v0.6.1

func (io NetIO) PacketsOut() uint

type PS

type PS struct {
	List []system.PSData `json:",omitempty"`
	N    *int            `json:",omitempty"`
}

type PSSlice

type PSSlice []*system.PSInfo

PSSlice is a list of PSInfo.

func (PSSlice) Ordered

func (pss PSSlice) Ordered(para *params.Params) *PS

type PSSort

type PSSort struct {
	Psk     *params.Num
	PSSlice PSSlice
	UIDs    map[uint]string
}

PSSort is to facilitate PSSlice sorting.

func (PSSort) Len

func (ps PSSort) Len() int

Len, Swap and Less satisfy sorting interface.

func (PSSort) Less

func (ps PSSort) Less(i, j int) (r bool)

func (PSSort) Swap

func (ps PSSort) Swap(i, j int)

type SSE

type SSE struct {
	Writer      http.ResponseWriter // points to the writer
	Params      *params.Params
	SentHeaders bool
	Errord      bool
}

func (*SSE) ServeHTTP

func (sse *SSE) ServeHTTP(_ http.ResponseWriter, r *http.Request)

ServeHTTP is a regular serve func except the first argument, passed as a copy, is unused. sse.Writer is there for writes.

func (*SSE) SetHeader

func (sse *SSE) SetHeader(name, value string) bool

type ServeAssets

type ServeAssets struct {
	ReadFunc       func(string) ([]byte, error)
	InfoFunc       func(string) (os.FileInfo, error)
	AltModTimeFunc func() time.Time // may be nil
}

func (ServeAssets) Serve

func (sa ServeAssets) Serve(w http.ResponseWriter, r *http.Request)

Serve does http.ServeContent with asset content and info.

type ServeIndex

type ServeIndex struct {
	ServeWS
	TaggedBin     bool
	IndexTemplate *templateutil.LazyTemplate
}

func NewServeIndex

func NewServeIndex(sw ServeWS, taggedbin bool, template *templateutil.LazyTemplate) ServeIndex

func (ServeIndex) Index

func (si ServeIndex) Index(w http.ResponseWriter, r *http.Request)

Index renders index page.

type ServeSSE

type ServeSSE struct {
	flags.DelayBounds
	// contains filtered or unexported fields
}

func NewServeSSE

func NewServeSSE(logRequests bool, dbounds flags.DelayBounds) ServeSSE

func (ServeSSE) IndexSSE

func (ss ServeSSE) IndexSSE(w http.ResponseWriter, r *http.Request)

IndexSSE serves SSE updates.

type ServeWS

type ServeWS struct {
	ServeSSE
}

func NewServeWS

func NewServeWS(se ServeSSE) ServeWS

func (ServeWS) IndexWS

func (sw ServeWS) IndexWS(w http.ResponseWriter, req *http.Request)

IndexWS serves ws updates.

type TimeInfo

type TimeInfo interface {
	ModTime() time.Time
}

TimeInfo is for AssetInfoFunc: a reduced os.FileInfo.

type UpgradeInfo added in v0.6.1

type UpgradeInfo struct {
	RWMutex       sync.RWMutex
	LatestVersion string
}

func (*UpgradeInfo) Get added in v0.6.1

func (ui *UpgradeInfo) Get() string

func (*UpgradeInfo) Set added in v0.6.1

func (ui *UpgradeInfo) Set(lv string)

Jump to

Keyboard shortcuts

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