Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

Commit

Permalink
satisfy golint
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianCzoch committed Jan 24, 2016
1 parent 51382d7 commit 287d6bb
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions collector/lxc_cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions collector/lxc_mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions kernel/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions lxc/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
)

// ProcStat is a method which represent cpu stats from cgroups
type ProcStat struct {
User float64
System float64
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lxc/lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lxc/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
)

// MemStat is a struct which contains usage of memory read from cgroups
type MemStat struct {
Usage float64
}
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 287d6bb

Please # to comment.