Skip to content

Commit

Permalink
Format the code base with gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mtds committed Jul 21, 2020
1 parent a753728 commit e7cceb6
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 208 deletions.
14 changes: 7 additions & 7 deletions cpus.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func CPUsGetMetrics() *CPUsMetrics {
func ParseCPUsMetrics(input []byte) *CPUsMetrics {
var cm CPUsMetrics
if strings.Contains(string(input), "/") {
splitted := strings.Split(strings.TrimSpace(string(input)), "/")
cm.alloc, _ = strconv.ParseFloat(splitted[0], 64)
cm.idle, _ = strconv.ParseFloat(splitted[1], 64)
cm.other, _ = strconv.ParseFloat(splitted[2], 64)
cm.total, _ = strconv.ParseFloat(splitted[3], 64)
}
splitted := strings.Split(strings.TrimSpace(string(input)), "/")
cm.alloc, _ = strconv.ParseFloat(splitted[0], 64)
cm.idle, _ = strconv.ParseFloat(splitted[1], 64)
cm.other, _ = strconv.ParseFloat(splitted[2], 64)
cm.total, _ = strconv.ParseFloat(splitted[3], 64)
}
return &cm
}

Expand Down Expand Up @@ -96,7 +96,7 @@ func (cc *CPUsCollector) Describe(ch chan<- *prometheus.Desc) {
func (cc *CPUsCollector) Collect(ch chan<- prometheus.Metric) {
cm := CPUsGetMetrics()
ch <- prometheus.MustNewConstMetric(cc.alloc, prometheus.GaugeValue, cm.alloc)
ch <- prometheus.MustNewConstMetric(cc.idle, prometheus.GaugeValue, cm.idle)
ch <- prometheus.MustNewConstMetric(cc.idle, prometheus.GaugeValue, cm.idle)
ch <- prometheus.MustNewConstMetric(cc.other, prometheus.GaugeValue, cm.other)
ch <- prometheus.MustNewConstMetric(cc.total, prometheus.GaugeValue, cm.total)
}
20 changes: 11 additions & 9 deletions cpus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
package main

import (
"testing"
"os"
"io/ioutil"
"io/ioutil"
"os"
"testing"
)

func TestCPUsMetrics(t *testing.T) {
// Read the input data from a file
file, err := os.Open("test_data/sinfo_cpus.txt")
if err != nil { t.Fatalf("Can not open test data: %v", err) }
data, err := ioutil.ReadAll(file)
t.Logf("%+v", ParseCPUsMetrics(data))
// Read the input data from a file
file, err := os.Open("test_data/sinfo_cpus.txt")
if err != nil {
t.Fatalf("Can not open test data: %v", err)
}
data, err := ioutil.ReadAll(file)
t.Logf("%+v", ParseCPUsMetrics(data))
}

func TestCPUssGetMetrics(t *testing.T) {
t.Logf("%+v", CPUsGetMetrics())
t.Logf("%+v", CPUsGetMetrics())
}
36 changes: 18 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
package main

import (
"flag"
"net/http"
"github.com/prometheus/common/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"flag"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"net/http"
)

func init() {
// Metrics have to be registered to be exposed
prometheus.MustRegister(NewSchedulerCollector()) // from scheduler.go
prometheus.MustRegister(NewQueueCollector()) // from queue.go
prometheus.MustRegister(NewNodesCollector()) // from nodes.go
prometheus.MustRegister(NewCPUsCollector()) // from cpus.go
// Metrics have to be registered to be exposed
prometheus.MustRegister(NewSchedulerCollector()) // from scheduler.go
prometheus.MustRegister(NewQueueCollector()) // from queue.go
prometheus.MustRegister(NewNodesCollector()) // from nodes.go
prometheus.MustRegister(NewCPUsCollector()) // from cpus.go
}

var listenAddress = flag.String(
"listen-address",
":8080",
"The address to listen on for HTTP requests.")
"listen-address",
":8080",
"The address to listen on for HTTP requests.")

func main() {
flag.Parse()
// The Handler function provides a default handler to expose metrics
flag.Parse()
// The Handler function provides a default handler to expose metrics
// via an HTTP server. "/metrics" is the usual endpoint for that.
log.Infof("Starting Server: %s", *listenAddress)
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(*listenAddress, nil))
log.Infof("Starting Server: %s", *listenAddress)
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}
20 changes: 11 additions & 9 deletions nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
package main

import (
"testing"
"os"
"io/ioutil"
"io/ioutil"
"os"
"testing"
)

func TestNodesMetrics(t *testing.T) {
// Read the input data from a file
file, err := os.Open("test_data/sinfo.txt")
if err != nil { t.Fatalf("Can not open test data: %v", err) }
data, err := ioutil.ReadAll(file)
t.Logf("%+v", ParseNodesMetrics(data))
// Read the input data from a file
file, err := os.Open("test_data/sinfo.txt")
if err != nil {
t.Fatalf("Can not open test data: %v", err)
}
data, err := ioutil.ReadAll(file)
t.Logf("%+v", ParseNodesMetrics(data))
}

func TestNodesGetMetrics(t *testing.T) {
t.Logf("%+v", NodesGetMetrics())
t.Logf("%+v", NodesGetMetrics())
}
20 changes: 11 additions & 9 deletions queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
package main

import (
"testing"
"os"
"io/ioutil"
"io/ioutil"
"os"
"testing"
)

func TestParseQueueMetrics(t *testing.T) {
// Read the input data from a file
file, err := os.Open("test_data/squeue.txt")
if err != nil { t.Fatalf("Can not open test data: %v", err) }
data, err := ioutil.ReadAll(file)
t.Logf("%+v", ParseQueueMetrics(data))
// Read the input data from a file
file, err := os.Open("test_data/squeue.txt")
if err != nil {
t.Fatalf("Can not open test data: %v", err)
}
data, err := ioutil.ReadAll(file)
t.Logf("%+v", ParseQueueMetrics(data))
}

func TestQueueGetMetrics(t *testing.T) {
t.Logf("%+v", QueueGetMetrics())
t.Logf("%+v", QueueGetMetrics())
}
Loading

0 comments on commit e7cceb6

Please sign in to comment.