Forum Discussion

thekoreanguy's avatar
thekoreanguy
Icon for Nimbostratus rankNimbostratus
Jun 05, 2024

CPU average, max usage for a month in CLI

I want to check GUI > Statistics > Analytics > CPU in CLI.
May I know the path or the saved database?

Also, is there a way to know the average monthly usage & maximum usage of the CPU from the CLI?

 

Thank you very much.

1 Reply

  • I want to check GUI > Statistics > Analytics > CPU in CLI.
    May I know the path or the saved database? marykayintouch

    Also, is there a way to know the average monthly usage & maximum usage of the CPU from the CLI?

     

    Thank you very much.

    Hello,

    There typically isn't a single file or database location that stores CPU usage statistics on Linux systems. However, there are several command-line tools you can use to view and calculate CPU usage for a specific timeframe:

    1. Using sar:

    The sar (System Activity Reporter) command provides detailed historical information about system resources, including CPU utilization. You can use it like this to get average and maximum CPU usage for the last month:

    sar 1 3000 | awk '/CPU/ {print $2, $4}'

    Here's what this command does:

    sar 1: Captures system activity every 1 second.


    3000: Captures data for 3000 seconds (around 50 minutes). This ensures you capture data for a full month even if the script runs slightly less than a month.


    awk '/CPU/ {print $2, $4}': Filters the output to show only CPU utilization lines (lines starting with "CPU"). Then, it prints the second column (user CPU %) and the fourth column (idle CPU %) for each line.


    2. Using uptime and historical data:

    The uptime command provides basic system information, including the current CPU load average for the last 1, 5, and 15 minutes. However, it doesn't store historical data.

    3. Using historical tools with parsing:

    Some systems might have historical data collection tools like collectd or munin. These tools store data in specific formats. You can use the tools' commands or scripts to access the data and then parse it using tools like awk or sed to calculate average and maximum CPU usage for a month.

    4. Third-party monitoring tools:

    Some server monitoring tools like htop or atop offer historical data views. You can explore these tools' functionalities to see if they meet your needs.

    I hope the information may help you. 

    Best regards,
    Cassie Bratt