core

package
v0.0.0-...-949dbd7 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2016 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// File to store containerList
	ContainerListFilePath = "./containers.json"
)
View Source
const (
	StatsMeasurements = "cstats"
)

Variables

View Source
var (
	// HTTP client used to get probe infos
	HTTPClient     = &http.Client{}
	Probes         []*Probe
	ProbeLastStats map[string][]dguard.Container
)
View Source
var (

	// containerList's Mutex
	ContainerListMutex sync.Mutex
)
View Source
var (
	// DB
	DB *influxdb.Client
)

Client variables

Functions

func AddCORS

func AddCORS(w http.ResponseWriter)

Add CORS to headers

func Alert

func Alert(event dguard.Event)

Send an event alert with corresponding transport(s)

func CriticalExit

func CriticalExit(s string)

Exit the program when critical error

func DeleteContainer

func DeleteContainer(c *dguard.Container) error

Delete a container in containerList

func GetContainerByCID

func GetContainerByCID(cid string) (dguard.Container, error)

Get a container by cid in containerList

func GetContainersByProbe

func GetContainersByProbe(probeName string) ([]dguard.Container, error)

Get containers by probe name in containerList

func GetProbesInfos

func GetProbesInfos() []dguard.ProbeInfos

Get list of probes infos

func GetSimpleContainersByProbe

func GetSimpleContainersByProbe(probeName string) ([]dguard.SimpleContainer, error)

Get []dguard.SimpleContainer by probe name in containerList

func HTTPHandlerContainerCID

func HTTPHandlerContainerCID(w http.ResponseWriter, r *http.Request)

Return container infos

func HTTPHandlerContainers

func HTTPHandlerContainers(w http.ResponseWriter, r *http.Request)

Return containers infos

func HTTPHandlerContainersProbeName

func HTTPHandlerContainersProbeName(w http.ResponseWriter, r *http.Request)

Return probe's containers infos

func HTTPHandlerProbes

func HTTPHandlerProbes(w http.ResponseWriter, r *http.Request)

Return simplified probes array

func HTTPHandlerProbesName

func HTTPHandlerProbesName(w http.ResponseWriter, r *http.Request)

Return one probe

func HTTPHandlerStats

func HTTPHandlerStats(w http.ResponseWriter, r *http.Request)

Return containers stats

func HTTPHandlerStatsCID

func HTTPHandlerStatsCID(w http.ResponseWriter, r *http.Request)

Return containers stats by container ID

func HTTPHandlerStatsProbeName

func HTTPHandlerStatsProbeName(w http.ResponseWriter, r *http.Request)

Return containers stats by probe name

func HTTPSecureAPI

func HTTPSecureAPI(r *http.Request, rm *mux.RouteMatch) bool

Secure API access

func HTTPServer

func HTTPServer()

Run HTTP Server

func HTTPURILogger

func HTTPURILogger(r *http.Request, rm *mux.RouteMatch) bool

Log HTTP requests' URI

func Init

func Init()

Initialize Core

func InitConfig

func InitConfig(path string)

Load program config from file

func InitContainersController

func InitContainersController()

Initialize containers controller

func InitDB

func InitDB()

Initialize InfluxDB connection

func InitLogger

func InitLogger(l1, l2, l3 bool) *logo.Logger

Initialize logger

func InsertContainer

func InsertContainer(c *dguard.Container) error

Insert a Container in containerList

func InsertStats

func InsertStats(stats []Stat, probeName string) error

Insert some stats

func LoadListFromFile

func LoadListFromFile() error

Load containerList from a file

func MonitorProbe

func MonitorProbe(p Probe)

Loop for monitoring a probe

func NotFoundHandler

func NotFoundHandler(w http.ResponseWriter, r *http.Request)

func SaveListToFile

func SaveListToFile() error

Load containerList to a file

Types

type Config

type Config struct {
	DockerGuard struct {
		API struct {
			ListenInterface string `yaml:"listen-interface"`
			ListenPort      string `yaml:"listen-port"`
			APILogin        string `yaml:"api-login"`
			APIPassword     string `yaml:"api-password"`
		}
		InfluxDB struct {
			IP   string `yaml:"ip"`
			Port int    `yaml:"port"`
			DB   string `yaml:"db"`
		} `yaml:"influxdb"`
		Event struct {
			Watch      []string    `yaml:"watch"`
			Transports []Transport `yaml:"transports"`
		} `yaml:"event"`
	} `yaml:"docker-guard"`
	Probes []Probe `yaml:"probes"`
}

Program config struct

var (
	// Program config
	DGConfig Config
)

type Options

type Options struct {
	Since  string
	Before string
	Limit  int
}

HTTP GET options

func GetOptions

func GetOptions(r *http.Request) Options

Parse Options

type Probe

type Probe struct {
	Name        string  `yaml:"name"`
	URI         string  `yaml:"uri"`
	APIPassword string  `yaml:"api-password"`
	ReloadTime  float64 `yaml:"reload-time"`
	Infos       *dguard.ProbeInfos
}

Probe

type Stat

type Stat struct {
	ContainerID   string
	Time          time.Time
	SizeRootFs    float64
	SizeRw        float64
	SizeMemory    float64
	NetBandwithRX float64
	NetBandwithTX float64
	CPUUsage      float64
	Running       bool
}

Container's stats

func GetLastStat

func GetLastStat(c *dguard.Container) (Stat, error)

Get container's last stat

func GetStatsByContainerCID

func GetStatsByContainerCID(containerCID string, o Options) ([]Stat, error)

Get stats by container id

func GetStatsByContainerProbeID

func GetStatsByContainerProbeID(probeName string, o Options) ([]Stat, error)

Get stats by probe name

func (*Stat) Insert

func (s *Stat) Insert(probeName string) error

Insert a stat

type StatPopulated

type StatPopulated struct {
	Container     dguard.Container
	Time          time.Time
	SizeRootFs    float64
	SizeRw        float64
	SizeMemory    float64
	NetBandwithRX float64
	NetBandwithTX float64
	CPUUsage      float64
	Running       bool
}

Stat populated

func GetStatsPByContainerProbeID

func GetStatsPByContainerProbeID(probeName string, o Options) ([]StatPopulated, error)

Get stats populated by probe name

type Transport

type Transport struct {
	Name string `yaml:"name"`
	Path string `yaml:"path"`
}

Transport struct

path is the path to the transport program

Jump to

Keyboard shortcuts

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