From e9a74a4c9c2c260cc07adb01a197613922cca0f8 Mon Sep 17 00:00:00 2001 From: Thomas Roehl Date: Thu, 25 Mar 2021 16:52:28 +0100 Subject: [PATCH] Add LustreCollector --- collectors/lustreMetric.go | 62 ++++++++++++++++++++++++++++++++++++++ config.json | 3 +- metric-collector.go | 1 + 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 collectors/lustreMetric.go diff --git a/collectors/lustreMetric.go b/collectors/lustreMetric.go new file mode 100644 index 0000000..7c2f044 --- /dev/null +++ b/collectors/lustreMetric.go @@ -0,0 +1,62 @@ +package collectors + +import ( +// "errors" + "io/ioutil" + "log" + "strconv" + "strings" + "time" +) + +const LUSTREFILE = `/proc/fs/lustre/llite/lnec-XXXXXX/stats` + +type LustreCollector struct { + MetricCollector +} + + +func (m *LustreCollector) Init() { + m.name = "LustreCollector" + m.setup() +} + +func (m *LustreCollector) Read(interval time.Duration){ + buffer, err := ioutil.ReadFile(string(LUSTREFILE)) + + if err != nil { + log.Print(err) + return + } + + for _, line := range strings.Split(string(buffer), "\n") { + lf := strings.Fields(line) + if len(lf) > 1 { + switch lf[0] { + case "read_bytes": + m.node["read_bytes"], err = strconv.ParseInt(lf[6], 0, 64) + m.node["read_requests"], err = strconv.ParseInt(lf[1], 0, 64) + case "write_bytes": + m.node["write_bytes"], err = strconv.ParseInt(lf[6], 0, 64) + m.node["write_requests"], err = strconv.ParseInt(lf[1], 0, 64) + case "open": + m.node["open"], err = strconv.ParseInt(lf[1], 0, 64) + case "close": + m.node["close"], err = strconv.ParseInt(lf[1], 0, 64) + case "setattr": + m.node["setattr"], err = strconv.ParseInt(lf[1], 0, 64) + case "getattr": + m.node["getattr"], err = strconv.ParseInt(lf[1], 0, 64) + case "statfs": + m.node["statfs"], err = strconv.ParseInt(lf[1], 0, 64) + case "inode_permission": + m.node["inode_permission"], err = strconv.ParseInt(lf[1], 0, 64) + } + + } + } +} + +func (m *LustreCollector) Close() { + return +} diff --git a/config.json b/config.json index 2ef517a..bd1fafe 100644 --- a/config.json +++ b/config.json @@ -12,7 +12,8 @@ "likwid", "loadavg", "netstat", - "ibstat" + "ibstat", + "lustrestat" ] } diff --git a/metric-collector.go b/metric-collector.go index 4c5ab1a..88ba3f0 100644 --- a/metric-collector.go +++ b/metric-collector.go @@ -18,6 +18,7 @@ var Collectors = map[string]collectors.MetricGetter{ "memstat": &collectors.MemstatCollector{}, "netstat": &collectors.NetstatCollector{}, "ibstat": &collectors.InfinibandCollector{}, + "lustrestat": &collectors.LustreCollector{}, } type GlobalConfig struct { Sink struct {