CTOP.py

Current version is v.0.7.7 updated on 2020-08-19 19:00 IST (Irish Standard Time).

Find the source code in: https://gitlab.com/carles.mateo/ctop

Clone it with:

git clone https://gitlab.com/carles.mateo/ctop.git

ctop.py is an Open Source tool for Linux System Administration that I’ve written in Python3. It uses only the System (/proc), and not third party libraries, in order to get all the information required.
I use only this modules, so it’s ideal to run in all the farm of Servers and Dockers:

  • os
  • sys
  • time
  • shutil (for getting the Terminal width and height)

The purpose of this tool is to help to troubleshot and to identify problems with a single view to a single tool that has all the typical indicators.

It provides in a single view information that is typically provided by many programs:

  • top, htop for the CPU usage, process list, memory usage
  • meminfo
  • cpuinfo
  • hostname
  • uptime
  • df to see the free space in / and the free inodes
  • iftop to see real-time bandwidth usage
  • ip addr list to see the main Ip for the interfaces
  • netstat or lsof to see the list of listening TCP Ports
  • uname -a to see the Kernel version

Other cool things it does is:

  • Identifying if you’re inside an Amazon VM, Virtual Box, Docker Containers or lxc
  • Uses colors, and marks in yellow the warnings and in red the errors, problems like few disk space reaming or high CPU usage according to the available cores and CPUs.
  • Redraws the screen and adjust to the size of the Terminal, bigger terminal displays more information
  • It doesn’t use external libraries, and does not escape to shell. It reads everything from /proc /sys or /etc files.
  • Identifies the Linux distribution
  • Shows the most repeated binaries, so you can identify DDoS attacks (like having 5,000 apache instances where you have normally 500 or many instances of Python)
  • Indicates if an interface has the cable connected or disconnected
  • Shows the Speed of the Network Connection (useful for Mellanox cards than can operate and 200Gbit/sec, 100, 50, 40, 25, 10…)
  • It displays the local time and the Linux Epoch Time, which is universal (very useful for logs and to detect when there was an issue, for example if your system restarted, your SSH Session would keep latest Epoch captured)
  • No root required
  • Displays recent errors like NFS Timed outs or Memory Read Errors.
  • You can enforce the output to be in a determined number of columns and rows, for data scrapping.
  • You can specify the number of loops (1 for scrapping, by default is infinite)
  • You can specify the time between screen refreshes, for long placed SSH sessions
  • You can specify to see the output in b/w or in color (default)

Limitations:

  • It only works for Linux, not for Mac or for Windows. Although the idea is to help with Server’s Linux Administration and Troubleshot and Mac and Windows do not have /proc
  • The list of process of the System is read every 30 seconds, to avoid adding much overhead on the System, other info every second

I decided to code name the version 0.7 as “Catalan Republic” to support the dreams and hopes and democratic requests of the Catalans people to become and independent republic.

I created this tool as Open Source and if you want to help I need people to test under different versions of:

  • Atypical Linux distributions

If you are a Cloud Provider and want me to implement the detection of your VMs, so the tool knows that is a instance of the Amazon, Google, Azure, Cloudsigma, Digital Ocean… contact me through my LinkedIn.

Monitoring an Amazon Instance, take a look at the amount of traffic sent and received

Some of the features I’m working on are parsing the logs checking for errors, kernel panics, processed killed due to lack of memory, iscsi disconnects, nfs errors, checking the logs of mysql and Oracle databases to locate errors

Views: 1,648 views

7 thoughts on “CTOP.py

  1. Jian

    Cool! Carles.
    The new update 0.7.8 works well with Python 3.5.2 on my system now.
    Thanks for your prompt changes and sharing.

    Reply
  2. Jian

    Hi Carles,

    I clone the tool to my ubuntu 14.04.6 system. Found one failure with Traceback:

    Traceback (most recent call last):
    File “ctop.py”, line 14, in
    from lib.fileutils import FileUtils
    File “/home3/kangjian/work/ctop/ctop/src/ctop/lib/fileutils.py”, line 45
    b_success: bool = True
    ^
    SyntaxError: invalid syntax

    Just remove “: bool” to “b_success = True”. It works.

    Thanks for the powerful tool!

    Reply
    1. Carles Mateo Post author

      Many thanks Jian.

      I think that you tried with Python2, which doesn’t support type hinting. This was introduced in Python 3.5. I’m only testing with Python3.
      I may try to do some work to ensure full compatibility with Python2. Even being EOL there are many Servers in the world using it. :)

      I’ve created this ticket for a Feature Request to support Python 2.7 and 2.6.
      https://gitlab.com/carles.mateo/ctop/-/issues/19

      Thanks Jian!.

      Reply
      1. Jian

        Understood, Carles.

        If tried with system (default) python2
        $ python ctop.py
        Traceback (most recent call last):
        File “ctop.py”, line 14, in
        from lib.fileutils import FileUtils
        File “/home3/kangjian/work/ctop/ctop/src/ctop/lib/fileutils.py”, line 38
        def create_folder(self, s_folder: str) -> bool:
        ^
        SyntaxError: invalid syntax

        $ python –version
        Python 2.7.6

        In last post, I just missed the python version info. Actually, I tried with python3 as noticed you mentioned the program written in Python3.

        $python3 ctop.py
        Then comes with the last post failure log. and fixed to run well with mentioned change.

        The Python3 version print on my system as:
        $ python3 –version
        Python 3.5.2

        The hinting syntax error existing with Python3. Hope the info can help on compatible improvement. I can verify on my system when changes available:)

        Reply
        1. Carles Mateo Post author

          Thanks for the tests Jian!.
          That’s very much appreciated.

          I’m going to remove the type hinting to make it compatible with Python 3.5.2.
          The minimum version I was testing is 3.6 so your test are really great.
          Thanks. Is super cool counting with your help. :)

          Reply

Leave a Reply to Jian Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.