-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add metrics/alloc_bytes for showing memory allocated #5715
Add metrics/alloc_bytes for showing memory allocated #5715
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good. My only concern would be that the same thing could be achieved by reading the existing metrics and doing the addition and pretty printing using some favourite scripting language. But it surely adds some convenience over that.
I haven't read the detailed descriptions of the metrics added together here, but if anything, the runtime metrics should be more accurate over top etc, shouldn't they be? |
You're absolutely right: this is only for convenience. And I'm all about convenience :) As for the accuracy, that might very well be. Reported metrics by Go multiplied by ~ 1.125 seems to give almost exactly what What do you think regarding the default formatting? |
I think Re Default formatting, I'd keep it as it is right now. But I'm not having a strong opinion here. If we change the default, the name should perhaps include Another thing, do we need to do something to ensure that the route won't clash with existing ones, or future ones, of the prom handler? |
I suppose we could have one I have checked to make sure |
👍 |
@srenatus I'm sorry, was the thumb up about
or that |
The second. LGTM. |
var m runtime.MemStats | ||
runtime.ReadMemStats(&m) | ||
|
||
total := m.HeapInuse + m.StackInuse + m.MCacheInuse + m.MSpanInuse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you help me understand why we these metrics and not something like HeapAlloc
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alloc
/HeapAlloc
will show a lower number, moving the metrics reported here further away from what other tools report.
I agree something like |
Alright, I'll update to use |
I think there's another metric that could be useful for triangulating the memstats we're adding here, and what htop etc show: |
I don't think it corresponds to any: it's using /proc to find data about the process' memory usage as seen from the kernel. But I just realised it's linux-only, so that might not be helpful here. |
6ae76fe
to
48d8e59
Compare
✅ Deploy Preview for openpolicyagent ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
48d8e59
to
1322e9a
Compare
Signed-off-by: Anders Eknert <anders@styra.com>
1322e9a
to
143a326
Compare
Add a simple endpoint (
/metrics/alloc
) to quickly show memory utilization of OPA. This can be done via e.g. Prometheus already, but having a human friendlier interface for this is nice.$ curl 'localhost:8181/metrics/alloc?pretty=true' 3.3GB
Without the
pretty
query string, the raw number of bytes is shown. I'm considering whether the pretty format should be the default, and something likeformat=raw
, orpretty=false
should be the option to show bytes, as that's likely less useful to a human operator. Ideas on that would be appreciated.NOTE: There's a slight discrepancy between what Go reports and what top and other programs do (Go reports less memory used), but I think this is good enough for providing a ballpark metric.