mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-12-25 23:19:06 +01:00
Update LustreCollector to use lctl. Sysfs version is commented out
This commit is contained in:
parent
92d4a9c2b9
commit
db02c89683
@ -3,18 +3,21 @@ package collectors
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"fmt"
|
||||||
"log"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
||||||
)
|
)
|
||||||
|
|
||||||
const LUSTREFILE = `/proc/fs/lustre/llite/lnec-XXXXXX/stats`
|
const LUSTRE_SYSFS = `/sys/fs/lustre`
|
||||||
|
const LCTL_CMD = `lctl`
|
||||||
|
const LCTL_OPTION = `get_param`
|
||||||
|
|
||||||
type LustreCollectorConfig struct {
|
type LustreCollectorConfig struct {
|
||||||
Procfiles []string `json:"procfiles"`
|
LCtlCommand string `json:"lctl_command"`
|
||||||
ExcludeMetrics []string `json:"exclude_metrics"`
|
ExcludeMetrics []string `json:"exclude_metrics"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,6 +27,58 @@ type LustreCollector struct {
|
|||||||
matches map[string]map[string]int
|
matches map[string]map[string]int
|
||||||
devices []string
|
devices []string
|
||||||
config LustreCollectorConfig
|
config LustreCollectorConfig
|
||||||
|
lctl string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *LustreCollector) getDevices() []string {
|
||||||
|
devices := make([]string, 0)
|
||||||
|
|
||||||
|
// //Version reading devices from sysfs
|
||||||
|
// globPattern := filepath.Join(LUSTRE_SYSFS, "llite/*/stats")
|
||||||
|
// files, err := filepath.Glob(globPattern)
|
||||||
|
// if err != nil {
|
||||||
|
// return devices
|
||||||
|
// }
|
||||||
|
// for _, f := range files {
|
||||||
|
// pathlist := strings.Split(f, "/")
|
||||||
|
// devices = append(devices, pathlist[4])
|
||||||
|
// }
|
||||||
|
|
||||||
|
command := exec.Command(m.lctl, LCTL_OPTION, "llite.*.stats")
|
||||||
|
command.Wait()
|
||||||
|
stdout, err := command.Output()
|
||||||
|
if err != nil {
|
||||||
|
return devices
|
||||||
|
}
|
||||||
|
for _, line := range strings.Split(string(stdout), "\n") {
|
||||||
|
if strings.HasPrefix(line, "llite") {
|
||||||
|
linefields := strings.Split(line, ".")
|
||||||
|
if len(linefields) > 2 {
|
||||||
|
devices = append(devices, linefields[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return devices
|
||||||
|
}
|
||||||
|
|
||||||
|
// //Version reading the stats data of a device from sysfs
|
||||||
|
// func (m *LustreCollector) getDeviceDataSysfs(device string) []string {
|
||||||
|
// llitedir := filepath.Join(LUSTRE_SYSFS, "llite")
|
||||||
|
// devdir := filepath.Join(llitedir, device)
|
||||||
|
// statsfile := filepath.Join(devdir, "stats")
|
||||||
|
// buffer, err := ioutil.ReadFile(statsfile)
|
||||||
|
// if err != nil {
|
||||||
|
// return make([]string, 0)
|
||||||
|
// }
|
||||||
|
// return strings.Split(string(buffer), "\n")
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (m *LustreCollector) getDeviceDataCommand(device string) []string {
|
||||||
|
statsfile := fmt.Sprintf("llite.%s.stats", device)
|
||||||
|
command := exec.Command(m.lctl, LCTL_OPTION, statsfile)
|
||||||
|
command.Wait()
|
||||||
|
stdout, _ := command.Output()
|
||||||
|
return strings.Split(string(stdout), "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *LustreCollector) Init(config json.RawMessage) error {
|
func (m *LustreCollector) Init(config json.RawMessage) error {
|
||||||
@ -46,19 +101,18 @@ func (m *LustreCollector) Init(config json.RawMessage) error {
|
|||||||
"getattr": {"getattr": 1},
|
"getattr": {"getattr": 1},
|
||||||
"statfs": {"statfs": 1},
|
"statfs": {"statfs": 1},
|
||||||
"inode_permission": {"inode_permission": 1}}
|
"inode_permission": {"inode_permission": 1}}
|
||||||
m.devices = make([]string, 0)
|
p, err := exec.LookPath(m.config.LCtlCommand)
|
||||||
for _, p := range m.config.Procfiles {
|
if err != nil {
|
||||||
_, err := ioutil.ReadFile(p)
|
p, err = exec.LookPath(LCTL_CMD)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
m.devices = append(m.devices, p)
|
return err
|
||||||
} else {
|
|
||||||
log.Print(err.Error())
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m.lctl = p
|
||||||
|
|
||||||
|
m.devices = m.getDevices()
|
||||||
if len(m.devices) == 0 {
|
if len(m.devices) == 0 {
|
||||||
return errors.New("No metrics to collect")
|
return errors.New("no metrics to collect")
|
||||||
}
|
}
|
||||||
m.init = true
|
m.init = true
|
||||||
return nil
|
return nil
|
||||||
@ -68,15 +122,10 @@ func (m *LustreCollector) Read(interval time.Duration, output chan lp.CCMetric)
|
|||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, p := range m.devices {
|
for _, device := range m.devices {
|
||||||
buffer, err := ioutil.ReadFile(p)
|
stats := m.getDeviceDataCommand(device)
|
||||||
|
|
||||||
if err != nil {
|
for _, line := range stats {
|
||||||
log.Print(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, line := range strings.Split(string(buffer), "\n") {
|
|
||||||
lf := strings.Fields(line)
|
lf := strings.Fields(line)
|
||||||
if len(lf) > 1 {
|
if len(lf) > 1 {
|
||||||
for match, fields := range m.matches {
|
for match, fields := range m.matches {
|
||||||
|
Loading…
Reference in New Issue
Block a user