Skip to content

Commit f307375

Browse files
authored
Merge pull request prometheus#1690 from shapor/patch-1
Move regexp to global in meminfo_linux.go
2 parents 7e7845a + a1a3633 commit f307375

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

collector/meminfo_linux.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import (
2525
"strings"
2626
)
2727

28+
var (
29+
reParens = regexp.MustCompile(`\((.*)\)`)
30+
)
31+
2832
func (c *meminfoCollector) getMemInfo() (map[string]float64, error) {
2933
file, err := os.Open(procFilePath("meminfo"))
3034
if err != nil {
@@ -39,7 +43,6 @@ func parseMemInfo(r io.Reader) (map[string]float64, error) {
3943
var (
4044
memInfo = map[string]float64{}
4145
scanner = bufio.NewScanner(r)
42-
re = regexp.MustCompile(`\((.*)\)`)
4346
)
4447

4548
for scanner.Scan() {
@@ -55,7 +58,7 @@ func parseMemInfo(r io.Reader) (map[string]float64, error) {
5558
}
5659
key := parts[0][:len(parts[0])-1] // remove trailing : from key
5760
// Active(anon) -> Active_anon
58-
key = re.ReplaceAllString(key, "_${1}")
61+
key = reParens.ReplaceAllString(key, "_${1}")
5962
switch len(parts) {
6063
case 2: // no unit
6164
case 3: // has unit, we presume kB

0 commit comments

Comments
 (0)