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

Adding docker-compose project display #191

Open
art049 opened this issue Mar 2, 2020 · 14 comments
Open

Adding docker-compose project display #191

art049 opened this issue Mar 2, 2020 · 14 comments

Comments

@art049
Copy link

art049 commented Mar 2, 2020

I think adding something to display that some containers have been created from the same docker-compose project could be interesting.
Maybe something as htop tree view.
image

If you think it's worth it, what could be worth implementing in order to have a first interesting integration?

@art049
Copy link
Author

art049 commented Jun 21, 2020

Hello @bcicen, do you think it'd be interesting to add this feature ?
I'm really interested to implement this 😉!

@luckydonald
Copy link

I think that would be a useful feature.

@stokito
Copy link
Contributor

stokito commented Aug 10, 2020

If container started from docker-compose then it will have a group of labels with "com.docker.compose." prefix. You can make docker inspect :

 "Labels": {
            "com.docker.compose.config-hash": "0a2749064f846be47808f2330dfc21ef2cd4fd8b39926c9f48f5a2bf4cccf5ad",
            "com.docker.compose.container-number": "1",
            "com.docker.compose.oneoff": "False",
            "com.docker.compose.project": "dockerise",
            "com.docker.compose.project.config_files": "/home/dockerise/docker-compose.dev.yml",
            "com.docker.compose.project.working_dir": "/home/dockerise",
            "com.docker.compose.service": "wildfly",
            "com.docker.compose.version": "1.25.0"
 }

We can group containers if they have the same com.docker.compose.project.
Just to visualize IntelliJ have such grouping:

intellij-compose

@pirate
Copy link

pirate commented Oct 24, 2020

I'd pay a $50 bounty for someone to implement this (through GitTip/paypal/sponsors/whatever your platform of choice). It would vastly improve my ctop experience and I rely on ctop for about a minute ~50 times a year.

I don't know how complex the ctop internals are so it may not be enough to entice anyone, but hey, it's more than nothing and open-source is real work that doesn't have a good compensation system right now, so donations/bounties are how I try to help 🤷.

I'm imagining a UX like this for viewing docker-compose containers grouped by project in ctop (with aggregate totals for each project):

$ cd /opt/mailu
$ docker-compose up -d
$ cd /opt/matomo
$ docker-compose up -d
...
$ ctop --compose
  ctop - 18:26:16 UTC   2 projects   15 containers                                                                                                                                                                                                                         

    NAME                    CID                               CPU      MEM             NET RX/TX       IO R/W          PIDS

 + ◉  mailu                  /opt/mailu                       2%       717M            3.5G / 2.2G     314M / 6.5G     71
   ✚ ◉  mailu_admin_1          567c6e40c9f4                     0%       216M / 3.84G    622M / 847M     24M / 0B        6       
   ✚ ◉  mailu_antispam_1       99c2490bd075                     0%        71M / 3.84G    155M / 141M     28M / 54M       4
   ✚ ◉  mailu_database_1       b6531b18a9da                     1%        29M / 3.84G    523M / 382M     183M / 1.59G    15
     ◉  mailu_fetchmail_1      fe26570a0690                     0%        14M / 3.84G    910K / 877K     6M / 0B         1
   ✚ ◉  mailu_front_1          8b30aab48008                     1%        16M / 3.84G    584M / 681M     24M / 36K       4
   ✚ ◉  mailu_imap_1           82b02542519f                     0%        26M / 3.84G    2M / 4M         15M / 1M        7
     ◉  mailu_redis_1          d83e1fb2d8a4                     0%        6M / 3.84G     220M / 70M      7M / 5.47G      5
   ✚ ◉  mailu_resolver_1       8de8dc0f89fc                     0%        18M / 3.84G    362M / 167M     18M / 88K       1
   ✚ ◉  mailu_smtp_1           f926e3697ae1                     0%        44M / 3.84G    116M / 145M     9M / 74M        18
   ✚ ◉  mailu_webdav_1         04a6fc7242ad                     0%       216M / 3.84G    49K / 480B      9M / 0B         1
   ✚ ◉  mailu_webmail_1        a1e27e2af6ad                     0%        61M / 3.84G    7M / 27M        32M / 12K       9
 
 + ◉  matomo                 /opt/matomo                      1%       234M            1.9G / 1.5G     239M / 2.9G     25
     ◉  matomo_argo_1          d109f307c457                     1%        14M / 512M     566M / 262M     524K / 0B       11
   ✚ ◉  matomo_mariadb_1       4b1d45531c84                     0%       181M / 1.95G    186M / 338M     144M / 2.49G    8
     ◉  matomo_phpfpm_1        b5953347d1db                     0%        37M / 1.95G    360M / 684M     90M / 460M      4
   ✚ ◉  matomo_nginx_1         fb472389be8b                     0%         2M / 512M     566M / 262M     2M / 0B         2

@stokito
Copy link
Contributor

stokito commented Oct 24, 2020

@pirate if the project author is not interested then I'll try to implement this on Monday. Right now I have a spare week and I anyway wanted to try programming in Go

stokito added a commit to stokito/ctop that referenced this issue Oct 25, 2020
Added "compose project", "compose service", "compose config", "compose workdir" fields.
They are shown in container info view.
Since the fields may be empty so added a condition to show them only if they have a value
@stokito
Copy link
Contributor

stokito commented Oct 26, 2020

Added "compose project", "compose service", "compose config", "compose workdir" fields.
They are shown in container info view.
Since the fields may be empty so added a condition to show them only if they have a value.

Now I would like to discuss how to properly design UI.
Instead of rows we may show tree where branch is compose project and leafs are services:

◉  mailu               /opt/mailu
  ◉  mailu_admin_1     567c6e40c9f4       0%       216M / 3.84G    622M / 847M     24M / 0B        6       
  ◉  mailu_webmail_1   a1e27e2af6ad       0%        61M / 3.84G    7M / 27M        32M / 12K       9
◉  matomo              /opt/matomo
  ◉  matomo_argo_1     d109f307c457       1%        14M / 512M     566M / 262M     524K / 0B       11

Pros:
In tree style we may also show total aggregated memory and CPU usage for each compose project.
We may add actions like up/down the whole compose project.
Cons:
In the same time this brings a UX problem: how to sort by MEM/CPU?
If a user wants to sort by CPU then he or she is looking for most heavy processes.
But, to keep grouping we can only sort containers inside of one compose project.
The compose projects in the same time must be always sorted by name.

Or we may just add a prefix to name with compose project / service / name:

◉  mailu/admin/mailu_admin_1      567c6e40c9f4  0%       216M / 3.84G    622M / 847M     24M / 0B        6       
◉  mailu/webmail/mailu_webmail_1  a1e27e2af6ad  0%        61M / 3.84G    7M / 27M        32M / 12K       9
◉  matomo/argo/matomo_argo_1      d109f307c457  1%        14M / 512M     566M / 262M     524K / 0B       11

Pros:
More compact view but we'll have some tautology because container name usually already have compose project name and service e.g. mailu_webmail_1.
But user may set any container_name in docker-compose.yaml so we still need to prepend at least compose project.
The sort logic remains the same i.e. we consider each container as a separate unit.
Cons:
Not clear for a user how not up/down the whole compose project.
Less information shown like working dir and total CPU/MEM per compose project.

My proposition is to use a third simplest possible solution: keep almost everything as is ;)
Total usage CPU/MEM of compose project probably almost never needed. Most often it will be only one compose project executed on a computer.
In 99% of cases container name anyway contains compose project name.
Show containers as they are shown now but on name sorting always put them together i.e. first sort by compose project and only then by container name inside of the project.
This will protect from rare cases when container_name is set, or some other container has a similar name.
For each container add a menu item "docker compose: Down" and for each container info view add details about compose project.
So you can down the whole compose project from menu of any container that belongs to the same compose project.

This is easy to implement and covers most basic needs.

@pirate
Copy link

pirate commented Oct 26, 2020

Total usage CPU/MEM of compose project probably almost never needed

The tree view with aggregate totals for each project is important in my mind 😅, because I use 3-8 compose projects on each server, with about 6 servers running at any time. Seeing high total memory/CPU/IO being used is the main thing I'm looking for as a red flag to investigate high load or failure on a particular project.

Why not sort by both? E.g. list the projects using the most aggregate memory from top -> bottom, then within each project, sort the leaf containers by memory use as well.

stokito added a commit to stokito/ctop that referenced this issue Oct 26, 2020
…then by name

In 99% of cases container name anyway contains its compose project name.
For example we have a folder wp which has docker-compose.yaml with two services: db and wordpress. Then after docker-compose up container names will be: wp_wordpress_1 and wp_db_1.

But in docker-compose.yaml for a specific service may be explicitly set `container_name` e.g. for wordpress service it may be just "blog".
Or some other container that is not part of compose project may have a similar name like wp_admin.
Then on sorting by name we'll see:
blog <- part of wp compose project
wp_admin  <- NOT part of wp compose project
wp_db  <- part of wp compose project

To keep container always together on name sorting we'll first sort by compose project and only then by container name inside of the project.
Thus we'll always have:
wp_admin
blog
wp_db

In this case blog and wp_db was sorted separately.
@stokito
Copy link
Contributor

stokito commented Oct 26, 2020

I see, we just have different usage scenarios: for me as a developer the most important is to easily shutdown compose projects but for you as server admin is more important to see usages.
Then yes, we should use a tree view.
Tomorrow I'll try to implement the tree view

stokito added a commit to stokito/ctop that referenced this issue Nov 1, 2020
Added "compose project", "compose service", "compose config", "compose workdir" fields.
They are shown in container info view.
Since the fields may be empty so added a condition to show them only if they have a value
stokito added a commit to stokito/ctop that referenced this issue Nov 16, 2020
Each container have a Project which may represent a Docker Compose project.
The name of project is simply the name of folder from which `docker-compose up` executed.
If container was started not from Compose then it anyway will be assigned to the noneProject with empty name.

Each project will be rendered as a separate CompactRow widget.
Currently to determine that this line is a project instead of status will be shown a down arrow ▼. TBD: use ident instead.
All containers will be sorted by the project first and only then by name.
On rendering in grid.go we know that containers from the same project are always together.
Rendered result looks like:

 ▼
  ◉ container1
  ◉ container2
 ▼ proj1
  ◉ proj1_db
  ◉ proj1_serv
 ▼ proj2
  ◉ proj2_db
  ◉ proj2_serv
stokito added a commit to stokito/ctop that referenced this issue Nov 16, 2020
stokito added a commit to stokito/ctop that referenced this issue Nov 16, 2020
stokito added a commit to stokito/ctop that referenced this issue Nov 16, 2020
stokito added a commit to stokito/ctop that referenced this issue Nov 16, 2020
We can't sort by id ot status as we did it for project's metrics. But at least inside of a project we can sort.
I.e. we anyway sort by project name and only then by status or id
stokito added a commit to stokito/ctop that referenced this issue Nov 16, 2020
@stokito
Copy link
Contributor

stokito commented Nov 16, 2020

Hi @pirate please checkout and test my branch stokito:docker_compose
image

@pirate
Copy link

pirate commented Nov 19, 2020

Could you bump the grouping carets out 1 character to the left so that the hierarchy can be visually scanned a bit easier? other than that it looks great @stokito!

@stokito
Copy link
Contributor

stokito commented Nov 20, 2020

At this moment we can't: down arrow is shown if status is empty which happens only for groups while empty health check column is almost always empty by itself.
This should be implemented somehow on UI level and unfortunately this is too complicated for me and I hope @bcicen can easily make a tree.
The PR must be reviewed, discussed and accepted only then I'll continue to work on this feature.
ATM I want to test and receive a feedback. For example:

  1. If this feels ok to group all non compose projects into noname group. I.e. each container always belongs to a group
  2. If this feels ok with sorting, especially sorting by status field.

@luckydonald
Copy link

luckydonald commented Dec 1, 2020

Could maybe the caret be a separate new first column? That way it would be on a different vertical level.

@pirate
Copy link

pirate commented Dec 1, 2020

Everything feels ok to me @stokito, I can pay out your bounty however you prefer (message me on twitter/email to coordinate?). Would love to see it reviewed and merged too, but don't want to hold your bounty hostage because the review process is subject to @bcicen's time availability :)

stokito added a commit to stokito/ctop that referenced this issue Dec 2, 2020
@stokito
Copy link
Contributor

stokito commented Dec 2, 2020

In 6b96656 I tried to make the stack triangle look better:

ctop with triangle

I used a Small Triangle symbol because it looks better in Monospace (default font in Ubuntu's terminal). Also the symbol is from Unicode 1993 so probably it will supported much better then others newer.
We can try another triangle symbols: https://unicode-table.com/en/search/?q=Triangle
Please check how it looks on MacOS.

@pirate thank you, I just found a job so you can donate to some other project.
Anyway if you'll need anything else just ping me to stokito@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

No branches or pull requests

4 participants