mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-28 23:19:46 -08:00
Merge pull request #1690 from shapor/patch-1
Move regexp to global in meminfo_linux.go
This commit is contained in:
commit
f3073755a3
|
@ -25,6 +25,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
reParens = regexp.MustCompile(`\((.*)\)`)
|
||||||
|
)
|
||||||
|
|
||||||
func (c *meminfoCollector) getMemInfo() (map[string]float64, error) {
|
func (c *meminfoCollector) getMemInfo() (map[string]float64, error) {
|
||||||
file, err := os.Open(procFilePath("meminfo"))
|
file, err := os.Open(procFilePath("meminfo"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -39,7 +43,6 @@ func parseMemInfo(r io.Reader) (map[string]float64, error) {
|
||||||
var (
|
var (
|
||||||
memInfo = map[string]float64{}
|
memInfo = map[string]float64{}
|
||||||
scanner = bufio.NewScanner(r)
|
scanner = bufio.NewScanner(r)
|
||||||
re = regexp.MustCompile(`\((.*)\)`)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
|
@ -55,7 +58,7 @@ func parseMemInfo(r io.Reader) (map[string]float64, error) {
|
||||||
}
|
}
|
||||||
key := parts[0][:len(parts[0])-1] // remove trailing : from key
|
key := parts[0][:len(parts[0])-1] // remove trailing : from key
|
||||||
// Active(anon) -> Active_anon
|
// Active(anon) -> Active_anon
|
||||||
key = re.ReplaceAllString(key, "_${1}")
|
key = reParens.ReplaceAllString(key, "_${1}")
|
||||||
switch len(parts) {
|
switch len(parts) {
|
||||||
case 2: // no unit
|
case 2: // no unit
|
||||||
case 3: // has unit, we presume kB
|
case 3: // has unit, we presume kB
|
||||||
|
|
Loading…
Reference in a new issue