ostent

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2016 License: MIT Imports: 33 Imported by: 6

Documentation

Overview

Package ostent is the library part of ostent cmd.

Index

Constants

View Source
const PanicStatusCode = http.StatusInternalServerError
View Source
const VERSION = "0.6.1"

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.

View Source
var (
	Reg1s  *IndexRegistry
	RegMSS = &MSS{KV: map[string]string{}}

	OstentUpgrade = new(UpgradeInfo)
)
View Source
var (
	PanicStatusText = statusLine(PanicStatusCode)
	PanicTemplate   = template.Must(template.New("recovery.html").Parse(`
<html>
<head><title>{{.Title}}</title></head>
<body bgcolor="white">
<center><h1>{{.Description}}</h1></center>
<hr><pre>{{.Stack}}</pre>
</body>
</html>
`))
)
View Source
var (
	// Connections is of unexported conns type to hold active ws connections.
	Connections = conns{/* contains filtered or unexported fields */}
)
View Source
var DISTRIB string

DISTRIB is distribution string and it's version. Set once at init.

View Source
var ZeroTime, _ = time.Parse("15:04:05", "00:00:00")

ZeroTime is zero time for formatting duration from it.

Functions

func AddAssetPathContextFunc

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

func AddBackground

func AddBackground(j backgroundHandler)

func ApplyRoutes

func ApplyRoutes(r *httprouter.Router, routes map[*Route]Handle, conv func(http.Handler) httprouter.Handle)

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 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 GetHN

func GetHN() (string, error)

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 NewErrorLog

func NewErrorLog() (*log.Logger, func() error)

NewErrorLog creates a logger and returns a func to defer.

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 ProcName added in v0.6.1

func ProcName(_ int, procName string) string

ProcName returns procName back.

func RunBackground

func RunBackground()

func WriteField

func WriteField(buf *bytes.Buffer, val interface{}, posts ...string)

WriteField is a helper to write val and optional posts[0] or a whitespace. The name relate to use with logrus.Entry.Data fields, no other Field relation.

Types

type Access

type Access struct {
	TaggedBin bool
	Log       *logrus.Logger
	Hosts     struct {
		Mutex sync.Mutex
		Hosts map[string]struct{}
	}
}

func NewAccess

func NewAccess(taggedbin bool) *Access

func NewServery

func NewServery(taggedbin bool) (*httprouter.Router, alice.Chain, *Access)

func (*Access) Constructor

func (a *Access) Constructor(handler http.Handler) http.Handler

func (*Access) DoLog

func (a *Access) DoLog(start time.Time, req *http.Request, rsp *Responding)

DoLog logs the arguments specifics.

func (*Access) Seen

func (a *Access) Seen(host string) bool

Seen returns whether host has been recorded. The record is created if it did not exist.

type AccessFormat

type AccessFormat struct{}

AccessFormat is a dummy struct with Format method.

func (*AccessFormat) Format

func (af *AccessFormat) Format(entry *logrus.Entry) ([]byte, error)

Format conforms to logrus.Formatter interface.

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 Collector

type Collector interface {
	GetHN() (string, error)
	HN(S2SRegistry, *sync.WaitGroup)
	UP(S2SRegistry, *sync.WaitGroup)
	LA(Registry, *sync.WaitGroup)
	RAM(Registry, *sync.WaitGroup)
	Swap(Registry, *sync.WaitGroup)
	IF(Registry, *sync.WaitGroup)
	PS(chan<- PSSlice)
	DF(Registry, *sync.WaitGroup)
	CPU(Registry, *sync.WaitGroup)
}

Collector is collection interface.

type ContextID

type ContextID int
const (
	CPanicError ContextID = iota
	CAssetPath
)

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) 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 (

	// 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 Handle

type Handle struct {
	Chain alice.Chain
	HFunc http.HandlerFunc
}

func NewHandle

func NewHandle(chain alice.Chain, hfunc http.HandlerFunc) Handle

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)

func (IndexData) SetString

func (data IndexData) SetString(k, v string)

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
}

func (*IndexRegistry) CPU

func (ir *IndexRegistry) CPU(para *params.Params, data IndexData) bool

func (*IndexRegistry) DF

func (ir *IndexRegistry) DF(para *params.Params, data IndexData) bool

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(fs sigar.FileSystem) *system.MetricDF

func (*IndexRegistry) GetOrRegisterPrivateIF

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

GetOrRegisterPrivateIF produces a registered in PrivateIFRegistry system.MetricIF.

func (*IndexRegistry) IF

func (ir *IndexRegistry) IF(para *params.Params, data IndexData) bool

func (*IndexRegistry) LA

func (ir *IndexRegistry) LA(para *params.Params, data IndexData) bool

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) MEM

func (ir *IndexRegistry) MEM(para *params.Params, data IndexData) bool

func (*IndexRegistry) UpdateCPU

func (ir *IndexRegistry) UpdateCPU(all sigar.Cpu, list []sigar.Cpu)

func (*IndexRegistry) UpdateDF

func (ir *IndexRegistry) UpdateDF(fs sigar.FileSystem, usage sigar.FileSystemUsage)

func (*IndexRegistry) UpdateIF

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

func (*IndexRegistry) UpdateLA

func (ir *IndexRegistry) UpdateLA(la sigar.LoadAverage)

func (*IndexRegistry) UpdateRAM

func (ir *IndexRegistry) UpdateRAM(got sigar.Mem, extra1, extra2 uint64)

func (*IndexRegistry) UpdateSwap

func (ir *IndexRegistry) UpdateSwap(got sigar.Swap)

UpdateSwap reads got and updates the ir.Swap. TODO Bad description.

type MSS

type MSS struct {
	MU sync.Mutex
	KV map[string]string
}

MSS implements S2SRegistry in a map[string]string.

func (*MSS) GetString

func (mss *MSS) GetString(k string) string

func (*MSS) HN

func (mss *MSS) HN(para *params.Params, data IndexData) bool

func (*MSS) SetString

func (mss *MSS) SetString(k, v string)

func (*MSS) UP

func (mss *MSS) UP(para *params.Params, data IndexData) bool

type Machine

type Machine struct{}

Machine implements Collector by collecting the maching metrics.

func (Machine) CPU

func (m Machine) CPU(reg Registry, wg *sync.WaitGroup)

func (Machine) DF

func (m Machine) DF(reg Registry, wg *sync.WaitGroup)

func (Machine) GetHN

func (m Machine) GetHN() (string, error)

func (Machine) HN

func (m Machine) HN(sreg S2SRegistry, wg *sync.WaitGroup)

func (Machine) IF

func (m Machine) IF(reg Registry, wg *sync.WaitGroup)

IF registers the interfaces with the reg.

func (Machine) LA

func (m Machine) LA(reg Registry, wg *sync.WaitGroup)

func (Machine) PS

func (m Machine) PS(CH chan<- PSSlice)

func (Machine) RAM

func (m Machine) RAM(reg Registry, wg *sync.WaitGroup)

func (Machine) Swap

func (m Machine) Swap(reg Registry, wg *sync.WaitGroup)

func (Machine) UP

func (m Machine) UP(sreg S2SRegistry, wg *sync.WaitGroup)

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) IU

func (pss PSSlice) IU(para *params.Params, data IndexData) bool

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) bool

func (PSSort) Swap

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

type Registry

type Registry interface {
	UpdateIF(system.IfAddress)
	UpdateCPU(sigar.Cpu, []sigar.Cpu)
	UpdateLA(sigar.LoadAverage)
	UpdateSwap(sigar.Swap)
	UpdateRAM(sigar.Mem, uint64, uint64)
	UpdateDF(sigar.FileSystem, sigar.FileSystemUsage)
}

Registry has updates with sigar values.

type Responding

type Responding struct {
	http.ResponseWriter
	http.Flusher // ?
	Status       int
	Size         int
}

func (*Responding) Flush

func (r *Responding) Flush()

func (*Responding) Hijack

func (r *Responding) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (Responding) StatusGood

func (r Responding) StatusGood() bool

func (*Responding) Write

func (r *Responding) Write(text []byte) (int, error)

func (*Responding) WriteHeader

func (r *Responding) WriteHeader(status int)

type Route

type Route struct {
	*RouteInfo
	RouterFuncs *[]func(string, httprouter.Handle)
}

func NewRoute

func NewRoute(path string, rfs ...func(string, httprouter.Handle)) *Route

type RouteInfo

type RouteInfo struct {
	Path   string
	Asset  bool
	Post   bool // filled after ApplyRoutes
	Params bool // filled after ApplyRoutes
}

type S2SRegistry

type S2SRegistry interface {
	SetString(string, string)
	GetString(string) string
}

S2SRegistry is for string kv storage.

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 {
	Log                 *log.Logger
	AssetFunc           func(string) ([]byte, error)
	AssetInfoFunc       func(string) (os.FileInfo, error)
	AssetAltModTimeFunc 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 ServePanic

type ServePanic struct{ TaggedBin bool }

func NewServePanic

func NewServePanic(taggedbin bool) *ServePanic

func (*ServePanic) PanicHandler

func (sp *ServePanic) PanicHandler(w http.ResponseWriter, r *http.Request)

type ServeSSE

type ServeSSE struct {
	Access *Access
	flags.DelayBounds
}

func NewServeSSE

func NewServeSSE(access *Access, 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
	ErrLog *log.Logger
}

func NewServeWS

func NewServeWS(ss ServeSSE, errlog *log.Logger) 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