amir20 / dozzle

Realtime log viewer for docker containers.
https://dozzle.dev/
MIT License
5.7k stars 287 forks source link

Add configured memory value of container #3128

Closed RicardoViteriR closed 1 month ago

RicardoViteriR commented 1 month ago

Describe the feature you would like to see

It would be great to see the numeric limit in MB of memory. Similar to what one can see when running docker stats. Currently, one has to log into the console to check the configured value.

Describe how you would like to see this feature implemented

image

image

Describe any alternatives you've considered

I currently log into the host and check the configured values.

amir20 commented 1 month ago

I am not much of a UI person, but do you think this would be repetitive since it doesn't change much. My overall principle has been to only show data that changes a lot. Anything that assist in debugging. Would this help?

If you do know a little of Vue then PRs are welcomed too.

RicardoViteriR commented 1 month ago

Hi there! Given the current dashboard layout, I believe displaying the memory value wouldn't be redundant. Unlike CPU, which allows easy inference of resource usage based on the maximum % CPU (calculated as # of CPUs * 100%), memory configurations can vary per Docker container. Thus, knowing the percentage based on these limits would provide useful information.

Let me know if it makes sense, and I can try to take a shot a adding a PR.

amir20 commented 1 month ago

Hi there! Given the current dashboard layout, I believe displaying the memory value wouldn't be redundant. Unlike CPU, which allows easy inference of resource usage based on the maximum % CPU (calculated as # of CPUs * 100%), memory configurations can vary per Docker container. Thus, knowing the percentage based on these limits would provide useful information.

I agree. The more I thought of your ask, my principle changed that Dozzle should be similar to Docker CLI but better. This would allow people to not even open their terminal.

The only problem is, I can't actually find this in the JSON returned. I am sure it's there and I am just missing it. You will need to figure out where it is returned, and add it to all the layers of data.

If you can find it, I could try helping you. My days have been pretty busy and for Dozzle I am working on a few performance issues so I won't be able to work on this.

RicardoViteriR commented 1 month ago

I retrieved the HostConfig.Memory propery of the container using curl --unix-socket /var/run/docker.sock "http://localhost/v1.44/containers/1a591a84c9ed/json?size=true".

Here is the json output: https://gist.github.com/RicardoViteriR/d6f6b9a9bca4b3d1059461f7ad615335

Interestingly, this information isn't retrievable when calling the /containers/json endpoint. Even after setting size=true, I didn't receive a response despite waiting a few seconds.

amir20 commented 1 month ago

Hmm I don't think size is the right place. According to docs for docker inspect

  -s, --size            Display total file sizes if the type is container

It took me a while, but I believe you want the Limit which can be found at https://github.com/moby/moby/blob/662f78c0b1bb5114172427cfcb40491d73159be2/api/types/container/stats.go#L69.

The code that fetches that data is at https://github.com/amir20/dozzle/blob/989a650f12bc7e7152d5d89329c07f314435a424/internal/docker/client.go#L273.

So this might be a little more complicated because you will need to update Go and Vue. Hopefully, you are up for the challenge. Most people don't bother with making changes to Dozzle so I understand if it's too much.

Let me know if you need more help.

amir20 commented 1 month ago

I haven't heard back. I won't find this feature useful. Closing but open open to PRs. You will have to do the work of understanding how Docker API works though.