Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #23 from mjtrangoni/megacheck
Browse files Browse the repository at this point in the history
Megacheck
  • Loading branch information
SqiSch authored May 30, 2017
2 parents 19988d7 + edf2d26 commit 28f2def
Show file tree
Hide file tree
Showing 29 changed files with 1,423 additions and 272 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Editor files #
################
*~

ipmitool-*/
build/
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
language: go
go:
- 1.7
- 1.8.x

before_install:
- go get honnef.co/go/tools/cmd/megacheck

script:
- make build
- make test
- make

before_deploy:
- gem install fpm package_cloud
Expand Down
34 changes: 24 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,46 @@ PROJECT_NAME = ipmi_exporter
VERSION = $(shell git describe --tags || echo 0.0.0-dev)
GO = go
GOX = gox
MEGACHECK ?= $(GOPATH)/bin/megacheck
GOX_ARGS = -output="$(BUILD_DIR)/{{.Dir}}_{{.OS}}_{{.Arch}}" -osarch="linux/amd64 linux/386 linux/arm linux/arm64 darwin/amd64 freebsd/amd64 freebsd/386 windows/386 windows/amd64"
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)

all: format vet megacheck build test

.PHONY: build
build:
@echo ">> building binaries"
GOBIN=$(BUILD_DIR) $(GO) install -v -ldflags '-X main.Version=$(VERSION)'

.PHONY: clean
clean:
rm -R $(BUILD_DIR)/* || true

.PHONY: test
test:
$(GO) test ./...
@echo ">> running tests"
@$(GO) test $(pkgs)

format:
@echo ">> formatting code"
@$(GO) fmt $(pkgs)

vet:
@echo ">> vetting code"
@$(GO) vet $(pkgs)

megacheck:
@echo ">> megacheck code"
@$(GO) get -u honnef.co/go/tools/cmd/megacheck
@$(MEGACHECK) $(pkgs)

.PHONY: release-build
release-build:
@$(GO) get -u github.com/mitchellh/gox
@$(GOX) $(GOX_ARGS) github.com/lovoo/$(PROJECT_NAME)

.PHONY: deb
deb:
make build-deb ARCH=amd64 GOARCH=amd64
make build-deb ARCH=i386 GOARCH=386
make build-deb ARCH=arm64 GOARCH=arm64
make build-deb ARCH=armhf GOARCH=arm

.PHONY: build-deb
build-deb:
fpm -s dir -t deb \
--name $(PROJECT_NAME) \
Expand All @@ -40,7 +53,7 @@ build-deb:
--deb-priority optional \
--category monitoring \
--force \
--deb-compression bzip2 \
--deb-compression bzip2 \
--license "BSD-3-Clause" \
--vendor "LOVOO GmbH" \
--deb-no-default-config-files \
Expand All @@ -52,7 +65,8 @@ build-deb:
$(BUILD_DIR)/$(PROJECT_NAME)_linux_$(GOARCH)=/usr/bin/ipmi_exporter \
packaging/ipmi-exporter.service=/lib/systemd/system/ipmi-exporter.service

.PHONY: release-package
release-package:
package_cloud push lovooOS/prometheus-exporters/debian/jessie build/*.deb
package_cloud push lovooOS/prometheus-exporters/debian/stretch build/*.deb
package_cloud push lovooOS/prometheus-exporters/debian/stretch build/*.deb

.PHONY: all build build-deb clean deb format megacheck release-build release-package test vet
46 changes: 23 additions & 23 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os/exec"
"regexp"
"strconv"
"strings"
"strings"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
Expand All @@ -18,7 +18,6 @@ type metric struct {
metricsname string
value float64
unit string
addr string
}

// Exporter implements the prometheus.Collector interface. It exposes the metrics
Expand Down Expand Up @@ -119,33 +118,32 @@ func splitOutput(impiOutput []byte) ([][]string, error) {
result, err := r.ReadAll()
if err != nil {
log.Errorf("could not parse ipmi output: %v", err)
return result, err
return result, err
}

keys := make(map[string]int)
var res [][]string
for _, v := range result {
key := v[0]
if _, ok := keys[key]; ok {
keys[key] += 1
v[0] = strings.TrimSpace(v[0]) + strconv.Itoa(keys[key])
} else {
keys[key] = 1
}
res = append(res, v)
}
return res, err
keys := make(map[string]int)
var res [][]string
for _, v := range result {
key := v[0]
if _, ok := keys[key]; ok {
keys[key] += 1
v[0] = strings.TrimSpace(v[0]) + strconv.Itoa(keys[key])
} else {
keys[key] = 1
}
res = append(res, v)
}
return res, err
}


// Describe describes all the registered stats metrics from the ipmi node.
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
ch <- temperatures
ch <- fanspeed
ch <- voltages
ch <- intrusion
ch <- powersupply
ch <- current
ch <- current
}

// Collect collects all the registered stats metrics from the ipmi node.
Expand All @@ -163,6 +161,8 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
log.Errorln(err)
}

psRegex := regexp.MustCompile("PS(.*) Status")

for _, res := range convertedOutput {
push := func(m *prometheus.Desc) {
ch <- prometheus.MustNewConstMetric(m, prometheus.GaugeValue, res.value, res.metricsname)
Expand All @@ -174,13 +174,13 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
push(voltages)
case "rpm":
push(fanspeed)
case "watts":
push(powersupply)
case "amps":
push(current)
case "watts":
push(powersupply)
case "amps":
push(current)
}

if matches, err := regexp.MatchString("PS.* Status", res.metricsname); matches && err == nil {
if matches := psRegex.MatchString(res.metricsname); matches {
push(powersupply)
} else if strings.HasSuffix(res.metricsname, "Chassis Intru") {
ch <- prometheus.MustNewConstMetric(intrusion, prometheus.GaugeValue, res.value)
Expand Down
14 changes: 7 additions & 7 deletions collector/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ var (
[]string{"sensor"},
nil,
)
current = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "current"),
"Contains the current from IPMI",
[]string{"sensor"},
nil,
)

current = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "current"),
"Contains the current from IPMI",
[]string{"sensor"},
nil,
)

intrusion = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "intrusion_status"),
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/lovoo/ipmi_exporter/collector"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
)

Expand All @@ -20,7 +21,7 @@ func main() {
flag.Parse()
prometheus.MustRegister(collector.NewExporter(*ipmiBinary))

handler := prometheus.Handler()
handler := promhttp.Handler()
if *metricsPath == "" || *metricsPath == "/" {
http.Handle(*metricsPath, handler)
} else {
Expand Down
12 changes: 2 additions & 10 deletions vendor/github.com/prometheus/client_golang/prometheus/counter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions vendor/github.com/prometheus/client_golang/prometheus/desc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 28f2def

Please sign in to comment.