From 287d6bbfcf9e509cfc63d10ec692334ea065bffc Mon Sep 17 00:00:00 2001 From: Sebastian Czoch Date: Sun, 24 Jan 2016 18:39:50 +0100 Subject: [PATCH] satisfy golint --- collector/collector.go | 2 ++ collector/lxc_cpu.go | 1 + collector/lxc_mem.go | 1 + cpu/cpu.go | 3 +++ kernel/version.go | 2 ++ lxc/cpu.go | 2 ++ lxc/lxc.go | 3 +++ lxc/memory.go | 2 ++ service/service.go | 12 +++++++----- 9 files changed, 23 insertions(+), 5 deletions(-) diff --git a/collector/collector.go b/collector/collector.go index cf3b2e0..317fe73 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -4,8 +4,10 @@ import ( "github.com/prometheus/client_golang/prometheus" ) +// Namespace is a prefix for all metrics const Namespace = "lxc" +// Collector is interface for collectors type Collector interface { Update(ch chan<- prometheus.Metric) error Init() error diff --git a/collector/lxc_cpu.go b/collector/lxc_cpu.go index b642ae0..1962c89 100644 --- a/collector/lxc_cpu.go +++ b/collector/lxc_cpu.go @@ -22,6 +22,7 @@ var ( physicalStat cpu.ProcStat ) +// NewCPUStatCollector is a function which return new lxc cpu collector func NewCPUStatCollector() Collector { return &lxcCPUCollector{ cpu: prometheus.NewDesc( diff --git a/collector/lxc_mem.go b/collector/lxc_mem.go index 3d29275..d93f2e0 100644 --- a/collector/lxc_mem.go +++ b/collector/lxc_mem.go @@ -11,6 +11,7 @@ type lxcMemCollector struct { lxcStat *lxc.LXC } +// NewMemStatCollector is a method which return new lxc memory collector func NewMemStatCollector() Collector { return &lxcMemCollector{ memory: prometheus.NewDesc( diff --git a/cpu/cpu.go b/cpu/cpu.go index a73dd84..5ea16d4 100644 --- a/cpu/cpu.go +++ b/cpu/cpu.go @@ -11,6 +11,7 @@ var ( procStatPath = "/proc/stat" ) +// ProcStat is a struct which represent cpu usage in Golang type ProcStat struct { User float64 System float64 @@ -30,6 +31,7 @@ type ProcStat struct { prevZero float64 } +// GetProcStat is a function which returns new ProcStat structure func GetProcStat() (ProcStat, error) { content, err := fetchProcStat() if err != nil { @@ -39,6 +41,7 @@ func GetProcStat() (ProcStat, error) { return parseProcStat(content), nil } +// Refresh is a method which returns new ProcStat structure (based on newest data) func (p *ProcStat) Refresh() (ProcStat, error) { content, err := fetchProcStat() if err != nil { diff --git a/kernel/version.go b/kernel/version.go index e92f08d..ceba262 100644 --- a/kernel/version.go +++ b/kernel/version.go @@ -11,6 +11,7 @@ var ( kernelVersionFile = "/proc/version" ) +// GetVersion is a function which returns version of kernel from /proc/version func GetVersion() (string, error) { content, err := getVersionFile() if err != nil { @@ -20,6 +21,7 @@ func GetVersion() (string, error) { return getKernelVersionFromContent(content), nil } +// GetMajorVersion is a function which returns version of kernel from /proc/version (only major(first) number) func GetMajorVersion() (int, error) { content, err := getVersionFile() if err != nil { diff --git a/lxc/cpu.go b/lxc/cpu.go index a32be4d..389c1ba 100644 --- a/lxc/cpu.go +++ b/lxc/cpu.go @@ -7,6 +7,7 @@ import ( "strings" ) +// ProcStat is a method which represent cpu stats from cgroups type ProcStat struct { User float64 System float64 @@ -19,6 +20,7 @@ var ( } ) +// GetProcStat is a method which returns ProcStat struct for selected container func (l *LXC) GetProcStat(containerName string) (ProcStat, error) { if !l.containerExists(containerName) { return ProcStat{}, errorContainerNotFound diff --git a/lxc/lxc.go b/lxc/lxc.go index 5fa4b8c..0ec3f01 100644 --- a/lxc/lxc.go +++ b/lxc/lxc.go @@ -24,11 +24,13 @@ var ( errorContainerNotFound = errors.New("container not found") ) +// LXC is a struct which provide some methods to deal witch LXC containers type LXC struct { kernelVersion int containersPath string } +// New is a function which return new LXC struct func New(kernelVersion int) (*LXC, error) { err := checkCGroups() if err != nil { @@ -46,6 +48,7 @@ func New(kernelVersion int) (*LXC, error) { }, nil } +// GetContainers is a method which returns slice of containers names running on host func (l *LXC) GetContainers() []string { var containers = []string{} files, _ := ioutil.ReadDir(l.containersPath) diff --git a/lxc/memory.go b/lxc/memory.go index 8edc9b9..23cf048 100644 --- a/lxc/memory.go +++ b/lxc/memory.go @@ -6,6 +6,7 @@ import ( "strings" ) +// MemStat is a struct which contains usage of memory read from cgroups type MemStat struct { Usage float64 } @@ -16,6 +17,7 @@ var ( } ) +// GetMemStat is a method which returns MemStat struct for selected container func (l *LXC) GetMemStat(containerName string) (MemStat, error) { if !l.containerExists(containerName) { return MemStat{}, errorContainerNotFound diff --git a/service/service.go b/service/service.go index 3039862..78ad0d8 100644 --- a/service/service.go +++ b/service/service.go @@ -25,6 +25,12 @@ var ( ) ) +// LXCCollector implements the prometheus.Collector interface. +type LXCCollector struct { + collectors map[string]collector.Collector +} + +// StartServer is a method which starts HTTP server func StartServer(addr *string) { http.Handle("/metrics", prometheus.Handler()) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -42,6 +48,7 @@ func StartServer(addr *string) { } } +// StartColectors is a function which load all available containers func StartColectors() { loadCollectors() for name, c := range collectors { @@ -55,11 +62,6 @@ func StartColectors() { prometheus.MustRegister(LXCCollector{collectors: collectors}) } -// LXCCollector implements the prometheus.Collector interface. -type LXCCollector struct { - collectors map[string]collector.Collector -} - // Describe implements the prometheus.Collector interface. func (n LXCCollector) Describe(ch chan<- *prometheus.Desc) { scrapeDurations.Describe(ch)