-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from compspec/add-memory-extractor
feat: add memory extractor
- Loading branch information
Showing
6 changed files
with
90 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package system | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
|
||
"github.com/compspec/compspec-go/pkg/extractor" | ||
) | ||
|
||
const ( | ||
memoryInfoFile = "/proc/meminfo" | ||
) | ||
|
||
// getMemoryInformation parses /proc/meminfo to get node memory metadata | ||
func getMemoryInformation() (extractor.ExtractorSection, error) { | ||
info := extractor.ExtractorSection{} | ||
|
||
raw, err := os.ReadFile(memoryInfoFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
lines := strings.Split(strings.TrimSpace(string(raw)), "\n") | ||
|
||
// We need custom parsing, the sections per processor are split by newlines | ||
for _, line := range lines { | ||
|
||
// I don't see any empty lines, etc. | ||
line = strings.Trim(line, " ") | ||
parts := strings.Split(line, ":") | ||
|
||
key := strings.TrimSpace(parts[0]) | ||
value := strings.TrimSpace(parts[1]) | ||
|
||
// Replace parens with underscore. Leave camel case for the rest... | ||
key = strings.ReplaceAll(key, "(", "_") | ||
key = strings.ToLower(strings.ReplaceAll(key, ")", "")) | ||
info[key] = value | ||
} | ||
return info, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters