Skip to content
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 Container metric functionality #102

Merged
merged 35 commits into from
May 5, 2021
Merged

Add Container metric functionality #102

merged 35 commits into from
May 5, 2021

Conversation

Gituser143
Copy link
Member

@Gituser143 Gituser143 commented Apr 29, 2021

Description

Add functionality to get overview of containers running by docker and related metrics. Can be accessed using grofer container.

Fixes #91

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist:

  • I have read the contribution guidelines and followed it as far as possible.
  • I have performed a self-review of my own code (if applicable)
  • I have commented my code, particularly in hard-to-understand areas (if applicable)
  • I have run go fmt on my code (reference)
  • I have made corresponding changes to the documentation (if applicable)
  • My changes generate no new warnings
  • Any dependent and pending changes have been merged and published

@Gituser143 Gituser143 changed the title Container Add Container metric functionality May 1, 2021
@Gituser143
Copy link
Member Author

@MadhavJivrajani I think I'm done here, pls review and let me know if I've missed/should change anything!

Copy link
Member

@MadhavJivrajani MadhavJivrajani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot_20210503_171846

I get this panic with grofer container -c <cid of nginx>
And the panic is not clean, command continue to go on in the background and is a little messy to kill and recover

@Gituser143
Copy link
Member Author

@MadhavJivrajani this is strange, I'm not able to reproduce this issue. Can you tell me what you ran?

@Gituser143
Copy link
Member Author

@MadhavJivrajani Port mappings aren't derived from the ContainerInspect(), I get them directly from ContainerList() itself. The data returned, has ports within it as a field. The type can be found here

@MadhavJivrajani
Copy link
Member

Or instead of just IPv4, we could have another column in that table called HostIP, that would make things much clearer.

@Gituser143
Copy link
Member Author

Or instead of just IPv4, we could have another column in that table called HostIP, that would make things much clearer.

This sounds like a good idea, clears more things up!

@MadhavJivrajani
Copy link
Member

@MadhavJivrajani Port mappings aren't derived from the ContainerInspect(), I get them directly from ContainerList() itself. The data returned, has ports within it as a field. The type can be found here

Regardless, I would assume that the inspect command too gets its info from the API, just like ContainerList or ContainerStats

@Gituser143
Copy link
Member Author

Regardless, I would assume that the inspect command too gets its info from the API, just like ContainerList or ContainerStats

They are different endpoints, thus have different format entirely.

@MadhavJivrajani
Copy link
Member

MadhavJivrajani commented May 4, 2021

They are different endpoints, thus have different format entirely.

Right, but whenever you would want to list a particular resource (like ports in this case), it would give a unifrom result, albeit in different formats, is what I meant.

@MadhavJivrajani
Copy link
Member

lgtm other than the above comments.

@Gituser143
Copy link
Member Author

Gituser143 commented May 4, 2021

@MadhavJivrajani, Okay so for the CPU metrics calculation, making it a function might not be the best idea because, it requires quite a lot of parameters and simply sending each of those individual metrics doesn't seem worth it. The parameters we'd have to send are:

  • numCPUs
  • CPUStats.CPUUsage
  • PreCPUStats.CPUUsage
  • CPUStats.SystemUsage
  • PreCPUStats.SystemUsage

Each of which are a type defined externally (docker types). So I feel it would be better to leave this as is. What do you think?

@MadhavJivrajani
Copy link
Member

From what I can tell, all of them are available in the StatsJSON type. Sending a pointer to that struct to avoid copying sounds good enought to me

@Gituser143
Copy link
Member Author

From what I can tell, all of them are available in the StatsJSON type. Sending a pointer to that struct to avoid copying sounds good enought to me

But if we're doing this, writing tests might get a little messy as we'd have to either fetch a similar stat or populate a struct ourself. Which when I come to think of it, shouldn't be much of an issue. I'll get to it :P

src/display/container/init.go Outdated Show resolved Hide resolved
@Gituser143
Copy link
Member Author

@MadhavJivrajani changes have been made! Do let me know if I've missed/messed something up.

Copy link
Member

@MadhavJivrajani MadhavJivrajani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tenor

@MadhavJivrajani MadhavJivrajani merged commit 0b9e407 into master May 5, 2021
@Gituser143 Gituser143 deleted the container branch May 5, 2021 10:55
MadhavJivrajani added a commit that referenced this pull request May 12, 2021
* Update install instructions in README

* Add binary compile script

* Moved compile script to scripts directory

* Add license to compile.sh

* add bin/ to gitignore

* Optimize struct memory usage

* reorder struct fields

* Updated config.yml

* Updated config.yml

* remove field align check from CI

* add check existence of fieldalignment command

* Update README.md

* remove xml mention from README

* Tidied go.mod

* Add apt update to ci scripts

* Add Container metric functionality (#102)

* Add overall metrics collection

* Replace net and blk slices with structs

* Init UI for containers

* Replace tick with NewTicker

* Add help page for overallContainer

* Format container UI

* Modify container about

* Add container table fit and resize

* Removed redundant helper

* Resize list content according to table widths

* Auto Resize Disk chart

* Replace tick with NewTicker and fix container table alignment issues

* Add License

* Remove empty file

* Missing license fix

* Add auto resize for cpu info table

* Add basic UI for per container metrics

* Fix per cpu value error

* Add table scroll functionality for per container UI

* Remove invalid test file

* Fix dot imports, use of "self" and ineffective break

* Cleanup container metrics and document code

* Migrate overallcontainer list to table and add cursor colours

* Add error art functionality for containers

* Add checks for empty precpu metrics

* Replace one shot container stats fetch

* Handle docker not running error

* Add docker alias for `grofer container`

* Add host ip in port map list

* Add getCPUPercent functions and tests for funcs

* Add missing license

* Replace cpu percent calculation with new func in overall.go

* Add test for RoundValues with inBytes

* Add details for exported container metrics structs

* Minor comments added to explain TickUntilDone

* Fix incorrect timestamps (#105)

* Fix incorrect timestamps

* Update tests

* A bunch of refactors (#103)

* Add table to grofer proc

* Re Add proc kill functionality

* Add table for per proc child procs

* Add % symbol to cpuinfo

* Add cleaner network graph and remove nettext chart

* Tidy go mod

* Add missing license and ctx.Done() to UI

* Update README

* Add CPU table for overall when numCores > 8

* Add CPU table for --cpuinfo when numCores > 8

* Add extra tests to CI

* Removed unused NetTable widget

* Sort procs on Timestamp

* Update src/utils/lineGraph.go

Co-authored-by: Madhav Jivrajani <madhav.jiv@gmail.com>

* Readme and CI config update

* Add credit and cocument exported function

* Remove -race from CI tests

* Remove default sort

Co-authored-by: Madhav Jivrajani <madhav.jiv@gmail.com>

* Add Sort functionality to overall process and container tables (#109)

* Add sort functionality to all procs

* Restructure switch cases

* Add  sort for container table

* Update keybindings for sort

* Explain kill confirmation in keybindings

* Restructure sorts

* Minor comment changes to sort.go

* Add tests for sortData

* Add missing license to test file

* Add Container Actions! (#110)

* Add container pause action

* Add global cli, cliMutex and container restart action

* Remove cliMutex, add check for mem 0/0 error and container stop functionality

* Add `--all` flag for `grofer container`

* Add container kill and remove actions

* add error screen for container

* Add containerWait

* Add cursor selectin colour after error

* Update help keybindings

* Add leybindings, recover() to utils wrapper and close chans

* Add --all flag for refresh after container action

* use ct.Done as stop chan

* Add comment for ContainerWait()

* Add stats.Body.Close() and removed close of chan on receiver

Co-authored-by: Madhav Jivrajani <madhav.jiv@gmail.com>

* Add missing ctx.Done() for serve data functions

Co-authored-by: Madhav Jivrajani <madhav.jiv@gmail.com>
Co-authored-by: Sparsh Temani <sparshtemani31415@gmail.com>
Gituser143 added a commit that referenced this pull request Sep 10, 2021
* Update to version v1.3.0! (#111)

* Update install instructions in README

* Add binary compile script

* Moved compile script to scripts directory

* Add license to compile.sh

* add bin/ to gitignore

* Optimize struct memory usage

* reorder struct fields

* Updated config.yml

* Updated config.yml

* remove field align check from CI

* add check existence of fieldalignment command

* Update README.md

* remove xml mention from README

* Tidied go.mod

* Add apt update to ci scripts

* Add Container metric functionality (#102)

* Add overall metrics collection

* Replace net and blk slices with structs

* Init UI for containers

* Replace tick with NewTicker

* Add help page for overallContainer

* Format container UI

* Modify container about

* Add container table fit and resize

* Removed redundant helper

* Resize list content according to table widths

* Auto Resize Disk chart

* Replace tick with NewTicker and fix container table alignment issues

* Add License

* Remove empty file

* Missing license fix

* Add auto resize for cpu info table

* Add basic UI for per container metrics

* Fix per cpu value error

* Add table scroll functionality for per container UI

* Remove invalid test file

* Fix dot imports, use of "self" and ineffective break

* Cleanup container metrics and document code

* Migrate overallcontainer list to table and add cursor colours

* Add error art functionality for containers

* Add checks for empty precpu metrics

* Replace one shot container stats fetch

* Handle docker not running error

* Add docker alias for `grofer container`

* Add host ip in port map list

* Add getCPUPercent functions and tests for funcs

* Add missing license

* Replace cpu percent calculation with new func in overall.go

* Add test for RoundValues with inBytes

* Add details for exported container metrics structs

* Minor comments added to explain TickUntilDone

* Fix incorrect timestamps (#105)

* Fix incorrect timestamps

* Update tests

* A bunch of refactors (#103)

* Add table to grofer proc

* Re Add proc kill functionality

* Add table for per proc child procs

* Add % symbol to cpuinfo

* Add cleaner network graph and remove nettext chart

* Tidy go mod

* Add missing license and ctx.Done() to UI

* Update README

* Add CPU table for overall when numCores > 8

* Add CPU table for --cpuinfo when numCores > 8

* Add extra tests to CI

* Removed unused NetTable widget

* Sort procs on Timestamp

* Update src/utils/lineGraph.go

Co-authored-by: Madhav Jivrajani <madhav.jiv@gmail.com>

* Readme and CI config update

* Add credit and cocument exported function

* Remove -race from CI tests

* Remove default sort

Co-authored-by: Madhav Jivrajani <madhav.jiv@gmail.com>

* Add Sort functionality to overall process and container tables (#109)

* Add sort functionality to all procs

* Restructure switch cases

* Add  sort for container table

* Update keybindings for sort

* Explain kill confirmation in keybindings

* Restructure sorts

* Minor comment changes to sort.go

* Add tests for sortData

* Add missing license to test file

* Add Container Actions! (#110)

* Add container pause action

* Add global cli, cliMutex and container restart action

* Remove cliMutex, add check for mem 0/0 error and container stop functionality

* Add `--all` flag for `grofer container`

* Add container kill and remove actions

* add error screen for container

* Add containerWait

* Add cursor selectin colour after error

* Update help keybindings

* Add leybindings, recover() to utils wrapper and close chans

* Add --all flag for refresh after container action

* use ct.Done as stop chan

* Add comment for ContainerWait()

* Add stats.Body.Close() and removed close of chan on receiver

Co-authored-by: Madhav Jivrajani <madhav.jiv@gmail.com>

* Add missing ctx.Done() for serve data functions

Co-authored-by: Madhav Jivrajani <madhav.jiv@gmail.com>
Co-authored-by: Sparsh Temani <sparshtemani31415@gmail.com>

* Merge changes from main, upgrade to v1.4.0

Co-authored-by: Madhav Jivrajani <madhav.jiv@gmail.com>
Co-authored-by: Sparsh Temani <sparshtemani31415@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE REQ] add monitoring of system resources given docker container id
2 participants