diff options
author | Ben Kochie <superq@gmail.com> | 2020-05-25 13:57:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-25 13:57:24 +0200 |
commit | f3073755a383a570705079601b42e1ed7723fde6 (patch) | |
tree | 82d7ed624af425ea51a058443b635fbe69f15c7a | |
parent | 7e7845a29f7cb5623683d8d67a71fe64639557a3 (diff) | |
parent | a1a3633d89520c6e941908fb6e93a94dca6eeb2a (diff) | |
download | prometheus_node_collector-f3073755a383a570705079601b42e1ed7723fde6.tar.bz2 prometheus_node_collector-f3073755a383a570705079601b42e1ed7723fde6.tar.xz prometheus_node_collector-f3073755a383a570705079601b42e1ed7723fde6.zip |
Merge pull request #1690 from shapor/patch-1
Move regexp to global in meminfo_linux.go
-rw-r--r-- | collector/meminfo_linux.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/collector/meminfo_linux.go b/collector/meminfo_linux.go index c5de432..3b9e2e9 100644 --- a/collector/meminfo_linux.go +++ b/collector/meminfo_linux.go | |||
@@ -25,6 +25,10 @@ import ( | |||
25 | "strings" | 25 | "strings" |
26 | ) | 26 | ) |
27 | 27 | ||
28 | var ( | ||
29 | reParens = regexp.MustCompile(`\((.*)\)`) | ||
30 | ) | ||
31 | |||
28 | func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { | 32 | func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { |
29 | file, err := os.Open(procFilePath("meminfo")) | 33 | file, err := os.Open(procFilePath("meminfo")) |
30 | if err != nil { | 34 | if err != nil { |
@@ -39,7 +43,6 @@ func parseMemInfo(r io.Reader) (map[string]float64, error) { | |||
39 | var ( | 43 | var ( |
40 | memInfo = map[string]float64{} | 44 | memInfo = map[string]float64{} |
41 | scanner = bufio.NewScanner(r) | 45 | scanner = bufio.NewScanner(r) |
42 | re = regexp.MustCompile(`\((.*)\)`) | ||
43 | ) | 46 | ) |
44 | 47 | ||
45 | for scanner.Scan() { | 48 | for scanner.Scan() { |
@@ -55,7 +58,7 @@ func parseMemInfo(r io.Reader) (map[string]float64, error) { | |||
55 | } | 58 | } |
56 | key := parts[0][:len(parts[0])-1] // remove trailing : from key | 59 | key := parts[0][:len(parts[0])-1] // remove trailing : from key |
57 | // Active(anon) -> Active_anon | 60 | // Active(anon) -> Active_anon |
58 | key = re.ReplaceAllString(key, "_${1}") | 61 | key = reParens.ReplaceAllString(key, "_${1}") |
59 | switch len(parts) { | 62 | switch len(parts) { |
60 | case 2: // no unit | 63 | case 2: // no unit |
61 | case 3: // has unit, we presume kB | 64 | case 3: // has unit, we presume kB |