Skip to content

Conversation

@tcinbis
Copy link
Contributor

@tcinbis tcinbis commented May 18, 2021

Hey all, first of all, thanks for this amazing tool!

What?

This PR adds a --json flag to the plotman status command which allows for printing the status report in a more machine-readable JSON format. It is not enabled by default.

Example command: plotman status --json

Why?

Monitoring my plotter with tools like Grafana + Prometheus I felt like it would also be nice to display the status of the different plotting jobs.
And following the DRY principle I wanted to make use of plotman's existing logic for parsing the plotter logs.

Normal status report

$ plotman status
  plot id    k                        tmp                         dst   wall   phase    tmp      pid   stat     mem   user    sys     io
1cc209a0   32   /home/joe/chia-tmp-plots   /home/joe/chia-dst3-plots   0:41     1:4   166G   267150    SLP   10.1G   2:01   0:05     0s
112796b3   32   /home/joe/chia-tmp-plots    /home/joe/chia-dst-plots   1:16     1:6   180G   262864    SLP    9.8G   3:26   0:08     0s
8a487bcd   32   /home/joe/chia-tmp-plots   /home/joe/chia-dst2-plots   1:51     2:2   184G   261343    RUN    2.3G   4:32   0:11   0:02
ac0c0a81   32   /home/joe/chia-tmp-plots   /home/joe/chia-dst3-plots   2:27     2:4   238G   259886    RUN    2.4G   5:06   0:12   0:01
7c0cf3c6   32   /home/joe/chia-tmp-plots    /home/joe/chia-dst-plots   3:02     3:2   217G   248549    RUN    9.5G   5:38   0:15   0:02
acce5f90   32   /home/joe/chia-tmp-plots   /home/joe/chia-dst2-plots   3:37     3:4   179G   247103    RUN    9.5G   6:09   0:17   0:02
422ca8ea   32   /home/joe/chia-tmp-plots   /home/joe/chia-dst3-plots   4:12     3:5   145G   245655    RUN    9.6G   6:40   0:20   0:04
c478046e   32   /home/joe/chia-tmp-plots    /home/joe/chia-dst-plots   4:48     4:0   109G   244216    DSK    1.2G   7:03   0:23   0:13

Total jobs: 8
Jobs in /home/joe/chia-tmp-plots: 8

Updated at: Tue May 18 09:08:20 2021

JSON status report

$ plotman status --json
{"jobs": [{"plot_id": "1cc209a0", "k": 32, "tmp_dir": "/home/joe/chia-tmp-plots", "dst_dir": "/home/joe/chia-dst3-plots", "progress": "1:4", "tmp_usage": 166320107810, "pid": 267150, "run_status": "SLP", "mem_usage": 10094567424, "time_wall": 2471, "time_user": 7282, "time_sys": 306, "time_iowait": 0}, {"plot_id": "112796b3", "k": 32, "tmp_dir": "/home/joe/chia-tmp-plots", "dst_dir": "/home/joe/chia-dst-plots", "progress": "1:6", "tmp_usage": 179732746286, "pid": 262864, "run_status": "SLP", "mem_usage": 9807249408, "time_wall": 4587, "time_user": 12407, "time_sys": 515, "time_iowait": 0}, {"plot_id": "8a487bcd", "k": 32, "tmp_dir": "/home/joe/chia-tmp-plots", "dst_dir": "/home/joe/chia-dst2-plots", "progress": "2:2", "tmp_usage": 184047759180, "pid": 261343, "run_status": "RUN", "mem_usage": 2272600064, "time_wall": 6707, "time_user": 16338, "time_sys": 688, "time_iowait": 142}, {"plot_id": "ac0c0a81", "k": 32, "tmp_dir": "/home/joe/chia-tmp-plots", "dst_dir": "/home/joe/chia-dst3-plots", "progress": "2:4", "tmp_usage": 237575920886, "pid": 259886, "run_status": "RUN", "mem_usage": 2415083520, "time_wall": 8823, "time_user": 18391, "time_sys": 774, "time_iowait": 113}, {"plot_id": "7c0cf3c6", "k": 32, "tmp_dir": "/home/joe/chia-tmp-plots", "dst_dir": "/home/joe/chia-dst-plots", "progress": "3:2", "tmp_usage": 216903223166, "pid": 248549, "run_status": "RUN", "mem_usage": 9525575680, "time_wall": 10937, "time_user": 20333, "time_sys": 905, "time_iowait": 122}, {"plot_id": "acce5f90", "k": 32, "tmp_dir": "/home/joe/chia-tmp-plots", "dst_dir": "/home/joe/chia-dst2-plots", "progress": "3:4", "tmp_usage": 178545500405, "pid": 247103, "run_status": "RUN", "mem_usage": 9527705600, "time_wall": 13052, "time_user": 22173, "time_sys": 1069, "time_iowait": 161}, {"plot_id": "422ca8ea", "k": 32, "tmp_dir": "/home/joe/chia-tmp-plots", "dst_dir": "/home/joe/chia-dst3-plots", "progress": "3:5", "tmp_usage": 144826809110, "pid": 245655, "run_status": "RUN", "mem_usage": 9556246528, "time_wall": 15166, "time_user": 24057, "time_sys": 1218, "time_iowait": 251}, {"plot_id": "c478046e", "k": 32, "tmp_dir": "/home/joe/chia-tmp-plots", "dst_dir": "/home/joe/chia-dst-plots", "progress": "4:0", "tmp_usage": 108822368512, "pid": 244216, "run_status": "DSK", "mem_usage": 1166336000, "time_wall": 17278, "time_user": 25416, "time_sys": 1409, "time_iowait": 828}], "total_jobs": 8, "updated": 1621321698.4130452}

And if formatted it looks like this:

{
    "jobs": [
        {
            "plot_id": "1cc209a0",
            "k": 32,
            "tmp_dir": "/home/joe/chia-tmp-plots",
            "dst_dir": "/home/joe/chia-dst3-plots",
            "progress": "1:4",
            "tmp_usage": 166320107810,
            "pid": 267150,
            "run_status": "SLP",
            "mem_usage": 10094567424,
            "time_wall": 2471,
            "time_user": 7282,
            "time_sys": 306,
            "time_iowait": 0
        },
        {
            "plot_id": "112796b3",
            "k": 32,
            "tmp_dir": "/home/joe/chia-tmp-plots",
            "dst_dir": "/home/joe/chia-dst-plots",
            "progress": "1:6",
            "tmp_usage": 179732746286,
            "pid": 262864,
            "run_status": "SLP",
            "mem_usage": 9807249408,
            "time_wall": 4587,
            "time_user": 12407,
            "time_sys": 515,
            "time_iowait": 0
        },
        {
            "plot_id": "8a487bcd",
            "k": 32,
            "tmp_dir": "/home/joe/chia-tmp-plots",
            "dst_dir": "/home/joe/chia-dst2-plots",
            "progress": "2:2",
            "tmp_usage": 184047759180,
            "pid": 261343,
            "run_status": "RUN",
            "mem_usage": 2272600064,
            "time_wall": 6707,
            "time_user": 16338,
            "time_sys": 688,
            "time_iowait": 142
        },
        {
            "plot_id": "ac0c0a81",
            "k": 32,
            "tmp_dir": "/home/joe/chia-tmp-plots",
            "dst_dir": "/home/joe/chia-dst3-plots",
            "progress": "2:4",
            "tmp_usage": 237575920886,
            "pid": 259886,
            "run_status": "RUN",
            "mem_usage": 2415083520,
            "time_wall": 8823,
            "time_user": 18391,
            "time_sys": 774,
            "time_iowait": 113
        },
        {
            "plot_id": "7c0cf3c6",
            "k": 32,
            "tmp_dir": "/home/joe/chia-tmp-plots",
            "dst_dir": "/home/joe/chia-dst-plots",
            "progress": "3:2",
            "tmp_usage": 216903223166,
            "pid": 248549,
            "run_status": "RUN",
            "mem_usage": 9525575680,
            "time_wall": 10937,
            "time_user": 20333,
            "time_sys": 905,
            "time_iowait": 122
        },
        {
            "plot_id": "acce5f90",
            "k": 32,
            "tmp_dir": "/home/joe/chia-tmp-plots",
            "dst_dir": "/home/joe/chia-dst2-plots",
            "progress": "3:4",
            "tmp_usage": 178545500405,
            "pid": 247103,
            "run_status": "RUN",
            "mem_usage": 9527705600,
            "time_wall": 13052,
            "time_user": 22173,
            "time_sys": 1069,
            "time_iowait": 161
        },
        {
            "plot_id": "422ca8ea",
            "k": 32,
            "tmp_dir": "/home/joe/chia-tmp-plots",
            "dst_dir": "/home/joe/chia-dst3-plots",
            "progress": "3:5",
            "tmp_usage": 144826809110,
            "pid": 245655,
            "run_status": "RUN",
            "mem_usage": 9556246528,
            "time_wall": 15166,
            "time_user": 24057,
            "time_sys": 1218,
            "time_iowait": 251
        },
        {
            "plot_id": "c478046e",
            "k": 32,
            "tmp_dir": "/home/joe/chia-tmp-plots",
            "dst_dir": "/home/joe/chia-dst-plots",
            "progress": "4:0",
            "tmp_usage": 108822368512,
            "pid": 244216,
            "run_status": "DSK",
            "mem_usage": 1166336000,
            "time_wall": 17278,
            "time_user": 25416,
            "time_sys": 1409,
            "time_iowait": 828
        }
    ],
    "total_jobs": 8,
    "updated": 1621321698.4130452
}

I am happy about any feedback/change requests.
Thanks for your time!

@tcinbis tcinbis changed the title Adding json flag to status command. req: Adding json flag to status command. May 18, 2021
@altendky
Copy link
Collaborator

altendky commented Jun 6, 2021

#430 (comment)

It would be good for people to have a discussion about this since I don't know my way around prometheus. It seems useful in general to offer a json output so maybe the two PRs remain independent, but since they target the same goal I would be interested in some commentary about the need for both. I would generally expect this to be a distinct command rather than an option. This is because there could be other options which would be relevant only to json (indentation, force ascii, etc) and subcommands work better for that than exclusive options.

Same as in the other PR, my apologies for the delay in responding.

@altendky
Copy link
Collaborator

I still think JSON output would be good to have. It's a pain when software only outputs human readable data... :| sorry. I think I will make subcommands for plotman status json and others. Each output format will end up with its own unique command line options and that is most easily implemented and used with separate subcommands. But, I will probably try to switch over to click from argparse as well. Anyways, I think we can except some CLI thrash on the development branch so it will be ok to merge this first and then I can do the click conversion etc.

So, tl;dr, if you can get this caught up I'll take another look over it and hopefully we can get it merged soon. Thanks for your contribution and my apologies for (still) being slow.

@tcinbis
Copy link
Contributor Author

tcinbis commented Jun 14, 2021

Hey, thanks for coming back to me and sorry for the long wait. I will check it out today and come back to you :)

@tcinbis tcinbis force-pushed the tom/dev-json-status branch from 38b850c to 0d6412b Compare June 14, 2021 08:09
@tcinbis
Copy link
Contributor Author

tcinbis commented Jun 14, 2021

@altendky I rebased my branch onto development to resolve the merge conflicts.
To fix a circular import, I moved the phase_str method from reporting.py to the Phase class as a __str__. That way, job.py and reporting.py don't have to import one another, and we can do str(phase) instead of phase_str(phase).

If I understood you correctly we can leave the CLI as is for now (with --json flag) and in a later iteration, we will move the entire CLI over to click, right?

Let me know what you think.

@altendky
Copy link
Collaborator

Yep, that's the plan. I had actually considered moving phase_str as you did here, but resisted to keep the diff at the time more focused... or something. Glad to have it moved. :] I just recently added type hints and started taking care of the changelog. I hope you don't mind me taking the liberty of adding those along with a couple code 'style' tweaks. Pending tests passing here, I'll go ahead and merge this. Thanks for the contribution. :]

@altendky altendky merged commit 0ad4929 into ericaltendorf:development Jun 15, 2021
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.

2 participants