-
Notifications
You must be signed in to change notification settings - Fork 5
feat: change to us exec+ps for metrics #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
352189e
docs: update version in README
alexec efd3ae6
feat: change to us exec+ps for metrics
alexec 29f56e1
ok
alexec b7e12b0
feat: simplify metrics
alexec 8973e70
ok
alexec 88f0083
fix complitation issue
alexec b510437
copilot feedback
alexec c49ead2
ok
alexec 06bad0a
tidy up
alexec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,35 @@ | ||
| package metrics | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/kitproj/kit/internal/types" | ||
| ) | ||
|
|
||
| // GetProcFSCommand returns the cat command to read /proc/pid/statm | ||
| func GetProcFSCommand(pid int) []string { | ||
| return []string{"cat", fmt.Sprintf("/proc/%d/statm", pid)} | ||
| } | ||
|
|
||
| // ParseProcFSOutput parses /proc/pid/statm output for memory usage only | ||
| func ParseProcFSOutput(output string) (*types.Metrics, error) { | ||
| fields := strings.Fields(strings.TrimSpace(output)) | ||
| if len(fields) < 2 { | ||
| return nil, fmt.Errorf("unexpected /proc/pid/statm output: insufficient fields") | ||
| } | ||
|
|
||
| // Field 1 (0-indexed): RSS (resident pages) | ||
| rssPages, err := strconv.ParseInt(fields[1], 10, 64) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to parse RSS from /proc/pid/statm: %w", err) | ||
| } | ||
|
|
||
| // Convert pages to bytes using actual system page size | ||
| systemPageSize := int64(os.Getpagesize()) | ||
| memoryBytes := uint64(rssPages * systemPageSize) | ||
|
|
||
| return &types.Metrics{Mem: memoryBytes}, nil | ||
| } |
This file contains hidden or 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,40 @@ | ||
| package metrics | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/kitproj/kit/internal/types" | ||
| ) | ||
|
|
||
| func GetPSCommand(pid int) []string { | ||
| return []string{"ps", "-o", "rss", "-p", strconv.Itoa(pid)} | ||
| } | ||
|
|
||
| func ParsePSOutput(output string) (*types.Metrics, error) { | ||
| lines := strings.Split(strings.TrimSpace(output), "\n") | ||
| if len(lines) < 2 { | ||
| return nil, fmt.Errorf("unexpected ps output: %s", output) | ||
| } | ||
|
|
||
| var totalMemory uint64 | ||
|
|
||
| for i := 1; i < len(lines); i++ { | ||
| fields := strings.Fields(lines[i]) | ||
| if len(fields) < 1 { | ||
| continue | ||
| } | ||
|
|
||
| rssMemoryKB, err := strconv.ParseInt(fields[0], 10, 64) | ||
| if err != nil { | ||
| continue | ||
| } | ||
|
|
||
| totalMemory += uint64(rssMemoryKB * 1024) | ||
| } | ||
|
|
||
| return &types.Metrics{ | ||
| Mem: totalMemory, | ||
| }, nil | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.