mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-04-18 18:55:55 +02:00
Fixing format with gofmt
This commit is contained in:
parent
e9a74a4c9c
commit
f32ff9d006
@ -5,8 +5,8 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ func (m *InfinibandCollector) Init() {
|
|||||||
m.setup()
|
m.setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *InfinibandCollector) Read(interval time.Duration){
|
func (m *InfinibandCollector) Read(interval time.Duration) {
|
||||||
buffer, err := ioutil.ReadFile(string(LIDFILE))
|
buffer, err := ioutil.ReadFile(string(LIDFILE))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo CFLAGS: -I.
|
#cgo CFLAGS: -I.
|
||||||
#cgo LDFLAGS: -L. -llikwid -llikwid-hwloc -lm
|
#cgo LDFLAGS: -L. -llikwid -llikwid-hwloc -lm
|
||||||
@ -11,7 +12,7 @@ import "unsafe"
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var topo C.CpuTopology_t
|
var topo C.CpuTopology_t
|
||||||
C.topology_init();
|
C.topology_init()
|
||||||
topo = C.get_cpuTopology()
|
topo = C.get_cpuTopology()
|
||||||
cpulist := make([]C.int, topo.numHWThreads)
|
cpulist := make([]C.int, topo.numHWThreads)
|
||||||
for a := 0; a < int(topo.numHWThreads); a++ {
|
for a := 0; a < int(topo.numHWThreads); a++ {
|
||||||
@ -27,5 +28,5 @@ func main() {
|
|||||||
fmt.Println(v)
|
fmt.Println(v)
|
||||||
C.free(unsafe.Pointer(gstring))
|
C.free(unsafe.Pointer(gstring))
|
||||||
C.perfmon_finalize()
|
C.perfmon_finalize()
|
||||||
C.topology_finalize();
|
C.topology_finalize()
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package collectors
|
package collectors
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo CFLAGS: -I./likwid
|
#cgo CFLAGS: -I./likwid
|
||||||
#cgo LDFLAGS: -L./likwid -llikwid -llikwid-hwloc -lm
|
#cgo LDFLAGS: -L./likwid -llikwid -llikwid-hwloc -lm
|
||||||
@ -9,19 +10,17 @@ import "C"
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
// "io/ioutil"
|
// "io/ioutil"
|
||||||
// "log"
|
// "log"
|
||||||
// "strconv"
|
// "strconv"
|
||||||
"strings"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
"log"
|
|
||||||
|
|
||||||
//protocol "github.com/influxdata/line-protocol"
|
//protocol "github.com/influxdata/line-protocol"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type LikwidCollector struct {
|
type LikwidCollector struct {
|
||||||
MetricCollector
|
MetricCollector
|
||||||
cpulist []C.int
|
cpulist []C.int
|
||||||
@ -45,12 +44,11 @@ var likwid_metrics = map[string][]LikwidMetric{
|
|||||||
LikwidMetric{name: "pwr1", search: "Power [W]", socket_scope: true},
|
LikwidMetric{name: "pwr1", search: "Power [W]", socket_scope: true},
|
||||||
LikwidMetric{name: "pwr2", search: "Power DRAM [W]", socket_scope: true},
|
LikwidMetric{name: "pwr2", search: "Power DRAM [W]", socket_scope: true},
|
||||||
LikwidMetric{name: "flops_dp", search: "DP [MFLOP/s]", socket_scope: false}},
|
LikwidMetric{name: "flops_dp", search: "DP [MFLOP/s]", socket_scope: false}},
|
||||||
"FLOPS_SP" : {LikwidMetric{name: "clock", search: "Clock [MHz]", socket_scope: false},
|
"FLOPS_SP": {LikwidMetric{name: "clock", search: "Clock [MHz]", socket_scope: false},
|
||||||
LikwidMetric{name: "cpi", search: "CPI", socket_scope: false},
|
LikwidMetric{name: "cpi", search: "CPI", socket_scope: false},
|
||||||
LikwidMetric{name: "flops_sp", search: "SP [MFLOP/s]", socket_scope: false}},
|
LikwidMetric{name: "flops_sp", search: "SP [MFLOP/s]", socket_scope: false}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func getMetricId(group C.int, search string) (int, error) {
|
func getMetricId(group C.int, search string) (int, error) {
|
||||||
for i := 0; i < int(C.perfmon_getNumberOfMetrics(group)); i++ {
|
for i := 0; i < int(C.perfmon_getNumberOfMetrics(group)); i++ {
|
||||||
mname := C.perfmon_getMetricName(group, C.int(i))
|
mname := C.perfmon_getMetricName(group, C.int(i))
|
||||||
@ -77,7 +75,6 @@ func getSocketCpus() map[C.int]int {
|
|||||||
return outmap
|
return outmap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (m *LikwidCollector) Init() {
|
func (m *LikwidCollector) Init() {
|
||||||
m.name = "LikwidCollector"
|
m.name = "LikwidCollector"
|
||||||
m.setup()
|
m.setup()
|
||||||
@ -120,7 +117,7 @@ func (m *LikwidCollector) Init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *LikwidCollector) Read(interval time.Duration){
|
func (m *LikwidCollector) Read(interval time.Duration) {
|
||||||
if m.init {
|
if m.init {
|
||||||
for gname, gid := range m.groups {
|
for gname, gid := range m.groups {
|
||||||
C.perfmon_setupCounters(gid)
|
C.perfmon_setupCounters(gid)
|
||||||
@ -133,24 +130,24 @@ func (m *LikwidCollector) Read(interval time.Duration){
|
|||||||
for sid, tid := range m.sock2tid {
|
for sid, tid := range m.sock2tid {
|
||||||
res := C.perfmon_getLastMetric(gid, C.int(lmetric.group_idx), C.int(tid))
|
res := C.perfmon_getLastMetric(gid, C.int(lmetric.group_idx), C.int(tid))
|
||||||
m.sockets[int(sid)][lmetric.name] = float64(res)
|
m.sockets[int(sid)][lmetric.name] = float64(res)
|
||||||
// log.Print("Metric '", lmetric.name,"' on Socket ",int(sid)," returns ", m.sockets[int(sid)][lmetric.name])
|
// log.Print("Metric '", lmetric.name,"' on Socket ",int(sid)," returns ", m.sockets[int(sid)][lmetric.name])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for tid, cpu := range m.cpulist {
|
for tid, cpu := range m.cpulist {
|
||||||
res := C.perfmon_getLastMetric(gid, C.int(lmetric.group_idx), C.int(tid))
|
res := C.perfmon_getLastMetric(gid, C.int(lmetric.group_idx), C.int(tid))
|
||||||
m.cpus[int(cpu)][lmetric.name] = float64(res)
|
m.cpus[int(cpu)][lmetric.name] = float64(res)
|
||||||
// log.Print("Metric '", lmetric.name,"' on CPU ",int(cpu)," returns ", m.cpus[int(cpu)][lmetric.name])
|
// log.Print("Metric '", lmetric.name,"' on CPU ",int(cpu)," returns ", m.cpus[int(cpu)][lmetric.name])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for cpu, _ := range m.cpus {
|
for cpu := range m.cpus {
|
||||||
if flops_dp, found := m.cpus[cpu]["flops_dp"]; found {
|
if flops_dp, found := m.cpus[cpu]["flops_dp"]; found {
|
||||||
if flops_sp, found := m.cpus[cpu]["flops_sp"]; found {
|
if flops_sp, found := m.cpus[cpu]["flops_sp"]; found {
|
||||||
m.cpus[cpu]["flops_any"] = flops_dp.(float64) + flops_sp.(float64)
|
m.cpus[cpu]["flops_any"] = flops_dp.(float64) + flops_sp.(float64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for sid, _ := range m.sockets {
|
for sid := range m.sockets {
|
||||||
if pwr1, found := m.sockets[int(sid)]["pwr1"]; found {
|
if pwr1, found := m.sockets[int(sid)]["pwr1"]; found {
|
||||||
if pwr2, found := m.sockets[int(sid)]["pwr2"]; found {
|
if pwr2, found := m.sockets[int(sid)]["pwr2"]; found {
|
||||||
sum := pwr1.(float64) + pwr2.(float64)
|
sum := pwr1.(float64) + pwr2.(float64)
|
||||||
|
@ -3,8 +3,8 @@ package collectors
|
|||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const LOADAVGFILE = `/proc/loadavg`
|
const LOADAVGFILE = `/proc/loadavg`
|
||||||
@ -13,13 +13,12 @@ type LoadavgCollector struct {
|
|||||||
MetricCollector
|
MetricCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (m *LoadavgCollector) Init() {
|
func (m *LoadavgCollector) Init() {
|
||||||
m.name = "LoadavgCollector"
|
m.name = "LoadavgCollector"
|
||||||
m.setup()
|
m.setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *LoadavgCollector) Read(interval time.Duration){
|
func (m *LoadavgCollector) Read(interval time.Duration) {
|
||||||
buffer, err := ioutil.ReadFile(string(LOADAVGFILE))
|
buffer, err := ioutil.ReadFile(string(LOADAVGFILE))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package collectors
|
package collectors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "errors"
|
// "errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -15,13 +15,12 @@ type LustreCollector struct {
|
|||||||
MetricCollector
|
MetricCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (m *LustreCollector) Init() {
|
func (m *LustreCollector) Init() {
|
||||||
m.name = "LustreCollector"
|
m.name = "LustreCollector"
|
||||||
m.setup()
|
m.setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *LustreCollector) Read(interval time.Duration){
|
func (m *LustreCollector) Read(interval time.Duration) {
|
||||||
buffer, err := ioutil.ReadFile(string(LUSTREFILE))
|
buffer, err := ioutil.ReadFile(string(LUSTREFILE))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
//protocol "github.com/influxdata/line-protocol"
|
//protocol "github.com/influxdata/line-protocol"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -17,13 +16,12 @@ type MemstatCollector struct {
|
|||||||
MetricCollector
|
MetricCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (m *MemstatCollector) Init() {
|
func (m *MemstatCollector) Init() {
|
||||||
m.name = "MemstatCollector"
|
m.name = "MemstatCollector"
|
||||||
m.setup()
|
m.setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MemstatCollector) Read(interval time.Duration){
|
func (m *MemstatCollector) Read(interval time.Duration) {
|
||||||
buffer, err := ioutil.ReadFile(string(MEMSTATFILE))
|
buffer, err := ioutil.ReadFile(string(MEMSTATFILE))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package collectors
|
package collectors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MetricGetter interface {
|
type MetricGetter interface {
|
||||||
@ -25,8 +25,6 @@ type MetricCollector struct {
|
|||||||
cpus map[int]map[string]interface{}
|
cpus map[int]map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (c *MetricCollector) Name() string {
|
func (c *MetricCollector) Name() string {
|
||||||
return c.name
|
return c.name
|
||||||
}
|
}
|
||||||
@ -58,7 +56,6 @@ func (c *MetricCollector) setup() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func intArrayContains(array []int, str int) (int, bool) {
|
func intArrayContains(array []int, str int) (int, bool) {
|
||||||
for i, a := range array {
|
for i, a := range array {
|
||||||
if a == str {
|
if a == str {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package collectors
|
package collectors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"log"
|
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const NETSTATFILE = `/proc/net/dev`
|
const NETSTATFILE = `/proc/net/dev`
|
||||||
@ -15,13 +15,12 @@ type NetstatCollector struct {
|
|||||||
MetricCollector
|
MetricCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (m *NetstatCollector) Init() {
|
func (m *NetstatCollector) Init() {
|
||||||
m.name = "NetstatCollector"
|
m.name = "NetstatCollector"
|
||||||
m.setup()
|
m.setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *NetstatCollector) Read(interval time.Duration){
|
func (m *NetstatCollector) Read(interval time.Duration) {
|
||||||
data, err := ioutil.ReadFile(string(NETSTATFILE))
|
data, err := ioutil.ReadFile(string(NETSTATFILE))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err.Error())
|
log.Print(err.Error())
|
||||||
|
@ -3,13 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/ClusterCockpit/cc-metric-collector/collectors"
|
||||||
|
protocol "github.com/influxdata/line-protocol"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"github.com/ClusterCockpit/cc-metric-collector/collectors"
|
|
||||||
protocol "github.com/influxdata/line-protocol"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var Collectors = map[string]collectors.MetricGetter{
|
var Collectors = map[string]collectors.MetricGetter{
|
||||||
@ -20,6 +20,7 @@ var Collectors = map[string]collectors.MetricGetter{
|
|||||||
"ibstat": &collectors.InfinibandCollector{},
|
"ibstat": &collectors.InfinibandCollector{},
|
||||||
"lustrestat": &collectors.LustreCollector{},
|
"lustrestat": &collectors.LustreCollector{},
|
||||||
}
|
}
|
||||||
|
|
||||||
type GlobalConfig struct {
|
type GlobalConfig struct {
|
||||||
Sink struct {
|
Sink struct {
|
||||||
User string `json:"user"`
|
User string `json:"user"`
|
||||||
@ -32,8 +33,6 @@ type GlobalConfig struct {
|
|||||||
Collectors []string `json:"collectors"`
|
Collectors []string `json:"collectors"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func LoadConfiguration(file string, config *GlobalConfig) error {
|
func LoadConfiguration(file string, config *GlobalConfig) error {
|
||||||
configFile, err := os.Open(file)
|
configFile, err := os.Open(file)
|
||||||
defer configFile.Close()
|
defer configFile.Close()
|
||||||
@ -45,8 +44,6 @@ func LoadConfiguration(file string, config *GlobalConfig) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func shutdown(wg *sync.WaitGroup, config *GlobalConfig) {
|
func shutdown(wg *sync.WaitGroup, config *GlobalConfig) {
|
||||||
sigs := make(chan os.Signal, 1)
|
sigs := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigs, os.Interrupt)
|
signal.Notify(sigs, os.Interrupt)
|
||||||
@ -73,10 +70,10 @@ func main() {
|
|||||||
log.Print(err)
|
log.Print(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var tags = map[string]string {"host": host}
|
var tags = map[string]string{"host": host}
|
||||||
|
|
||||||
LoadConfiguration("config.json", &config)
|
LoadConfiguration("config.json", &config)
|
||||||
if config.Interval <= 0 || time.Duration(config.Interval) * time.Second <= 0 {
|
if config.Interval <= 0 || time.Duration(config.Interval)*time.Second <= 0 {
|
||||||
log.Print("Configuration value 'interval' must be greater than zero")
|
log.Print("Configuration value 'interval' must be greater than zero")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -93,7 +90,7 @@ func main() {
|
|||||||
col.Init()
|
col.Init()
|
||||||
log.Print("Start ", col.Name())
|
log.Print("Start ", col.Name())
|
||||||
}
|
}
|
||||||
log.Print(config.Interval, time.Duration(config.Interval) * time.Second)
|
log.Print(config.Interval, time.Duration(config.Interval)*time.Second)
|
||||||
ticker := time.NewTicker(time.Duration(config.Interval) * time.Second)
|
ticker := time.NewTicker(time.Duration(config.Interval) * time.Second)
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
node_fields := make(map[string]interface{})
|
node_fields := make(map[string]interface{})
|
||||||
@ -113,8 +110,7 @@ func main() {
|
|||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
return
|
return
|
||||||
case t:= <-ticker.C:
|
case t := <-ticker.C:
|
||||||
|
|
||||||
|
|
||||||
scount := 0
|
scount := 0
|
||||||
ccount := 0
|
ccount := 0
|
||||||
@ -149,7 +145,7 @@ func main() {
|
|||||||
if scount > 0 {
|
if scount > 0 {
|
||||||
for sid, socket := range sockets_fields {
|
for sid, socket := range sockets_fields {
|
||||||
var CurrentSocket protocol.MutableMetric
|
var CurrentSocket protocol.MutableMetric
|
||||||
var stags = map[string]string {"socket": fmt.Sprintf("%d", sid), "host": host}
|
var stags = map[string]string{"socket": fmt.Sprintf("%d", sid), "host": host}
|
||||||
CurrentSocket, err = protocol.New("socket", stags, socket, t)
|
CurrentSocket, err = protocol.New("socket", stags, socket, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
@ -163,7 +159,7 @@ func main() {
|
|||||||
if ccount > 0 {
|
if ccount > 0 {
|
||||||
for cid, cpu := range cpu_fields {
|
for cid, cpu := range cpu_fields {
|
||||||
var CurrentCpu protocol.MutableMetric
|
var CurrentCpu protocol.MutableMetric
|
||||||
var ctags = map[string]string {"host": host, "cpu": fmt.Sprintf("%d", cid)}
|
var ctags = map[string]string{"host": host, "cpu": fmt.Sprintf("%d", cid)}
|
||||||
CurrentCpu, err = protocol.New("cpu", ctags, cpu, t)
|
CurrentCpu, err = protocol.New("cpu", ctags, cpu, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
@ -178,6 +174,5 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user