- Abdussamad.com
- Linux Server Administration and Website Development
- CPU load average history in Linux
- Understanding CPU load
- Tracking CPU load average
- Viewing statistics
- Final thoughts
- Get CPU Information via Command Prompt in Windows 10
- About Sergey Tkachenko
- Retrieving CPU Load Percent total in Windows with C++
- How to get history report of the CPU/Memory usage on windows 2008 R2 (64-bit) ?
- 18 Replies
- Tracking CPU and Memory usage per process
- 17 Answers 17
Abdussamad.com
Linux Server Administration and Website Development
CPU load average history in Linux
CPU load average is a metric used to determine CPU usage in Linux. CPU load is a measure of the number of processes that are running as well processes that are waiting for CPU access. Tracking CPU load averages over a period of time can help system administrators diagnose the cause of server slowdowns.
Understanding CPU load
Ideally you want your CPU load to remain equal to or less than the number of CPU cores in your server. So if you have a single core server a 1.0 load average will indicate almost complete utilization. If you have quad core system then a 4.0 or less load average will be ideal.
However, under Linux you can generally get away with at least 2x the core count as load average during peak times. That is because Linux is very efficient at CPU scheduling and on a web server network delays have a bigger impact than processor delays.
Tracking CPU load average
To keep track of your system’s CPU load averages you will need to install the sar program. This program is usually found in the sysstat package.
To install sysstat on Centos or Fedora type the following command as root:
yum install sysstat
On OpenSUSE you would do:
zypper install sysstat
Once installed sysstat will automatically run at periodic intervals via a cronjob. Each time it runs it will record statistics about the server to its log files. So before you can invoke sar for the first time you will need to wait for the cronjob to run at least once.
Viewing statistics
Type the following command to get today’s CPU load average statistics:
The output of sar is piped to the text viewing program or pager called ‘less’ for easy viewing. Press q to quit less when you are done viewing the stats.
sar stores its statistics in log files. On CentOS and SUSE these files are stored in the /var/log/sa directory. Each file in that directory is named after a different date of the month. So if you want to view the load averages for the 10th you would do:
cd /var/log/sa
sar -q -f sa10 | less
You can also narrow down the time period of the statistics using the -s and -e arguments. The -s argument is for the starting time and -e for the ending time. In both cases you specify the time in 24 hour format:
sar -q -s 22:00:00 -e 00:00:00 -f /var/log/sa/sa10
In the above example the columns ldavg-1, ldavg-5 and ldavg-15 represent load averages 1 minute, 5 minutes and 15 minutes in the past respectively. The idea is to show a rising or falling trend in CPU load. In this case you can see that the system is under very little load. Its a 2 core system yet load is less than 1 so that means there are no processes waiting for CPU time.
Final thoughts
Using sysstat you can record statistics about your system including CPU load averages over a period of time. However, keep in mind that CPU load figures are just part of the picture and it is important to consider other metrics as well for a complete picture. Try the command man sar to learn how to view other statistics about your system.
Get CPU Information via Command Prompt in Windows 10
In Windows 10, it is possible to get information about the CPU installed in your PC using the command line. If you need to print it out or just view your CPU details without restarting your PC or using a third party tool, here is how it can be done.
To see some information about the CPU of your Windows 10 device, do the following.
The command produces the following output:
While this trick can’t replace powerful apps like AIDA64 or HWiNFO, it is a nice option to see the information quickly without third party tools. It is possible to use it in various automation scripts if required.
If you need to use GUI tools, you can see some CPU information via the built-in Task Manager tool. In the «More details» mode it has a tab «Performance» which shows the CPU name and its clock:
Another option is the application «System Information». Use it as follows:
- Press the Win + R hotkeys together on the keyboard and type the following command in your Run box:
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
Share this post
About Sergey Tkachenko
Sergey Tkachenko is a software developer from Russia who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.
Retrieving CPU Load Percent total in Windows with C++
I’ve been working on this tool to quickly log some system stats, like memory info, and cpu load percentage (like what’s shown in the Task Manager). I seem to have the memory and logging part taken care of, but figuring out the CPU percentage has been very tough 🙁 I’ve found a lot info on methods to check CPU info, but outside of abstracts pretty much none of the code samples I’ve found compile, or are well commented, so it’s been hard for me to hash out a way to do this. I’ve already read through a lot of stackoverflow questions about getting CPU timings and such, but I haven’t been able to put the pieces together.
Maybe I’m missing the point, but it seems like a popular way to figure this out is by querying the CPU two times with at least 200ms between each check to help avoid problems with something called. resolution? So yeah! How the heck do I do that? 🙁 I’m syntactically challenged D:
I’m going to share my source code so you can see what exactly I’ve been up to, up until now. It’s all in just one .cpp, I’m using VS2013 Express for C++, and it’s only for Windows for multicore CPUs.
Warning in advance: I’m so sorry for all the comments in the code 😡 Also, if you copy this code and run it, it’s going to generate a .CSV file called log.CSV
I ran across this
It seems like it is getting the stuff I need, but I don’t know how to actually use it or even make a unit test out of it, which I’d prefer before throwing it in the rest of my Source.cpp
I am completely lost. I’ve tried all sorts of things for the last few hours, but I can’t even get a simple unit test compiling.
I feel like this comment has me on the right path, but I don’t actually know what to do with it: How is CPU usage calculated?
I’m showing a Unit Test for Jeremy Friesner’s code, as well as the completed logging tool that I was working on.
How to get history report of the CPU/Memory usage on windows 2008 R2 (64-bit) ?
We have a Windows 2008 R2 (64-bit) server with oracle database and IIS running on it.
Anytime if users complain slowness we just open the task manager on the above server
and look at the CPU & memory usage and see which is consuming more resources.
How do we be able to get the following reports ?
1) what was the CPU usage from to
2) what was the memory usage from time:date:X to time:date:Y
3) what is average CPU/memory usage of the server for last month
— If the above needs some repository setup and changes on the windows 2008 R2 , please let us know how.
Thanks in advance
The help desk software for IT. Free.
Track users’ IT needs, easily, and with only the features you need.
18 Replies
Perfmon in server 2008 really is your best option.
We will use system memory as an example but you can add the processor counters just as easily.
In the left, expand «Monitoring Tools». Now right click «Performance Monitor» and choose, «New»>»Data Collector Set».
Give it a name of «Memory» and click «Next»
Now browse to where you want to save the logged data, lets make it easy and drop it into the root of » and then click «Next»
Choose save and close on the next screen and click «Finish»
Now in the left hand side, expand «Data collector sets» then «User Defined» and click on your new «Memory» one we created.
In the right hand screen double click the «System monitor log»
In this screen, click the «Processor» that’s already listed and then click the «Remove» button.
Now click the «Add» button, scroll through the list and click the plus symbol next to «Memory». Click on any one of the things in the list to deselect all of them. We are going to individually select jsut the ones that interest us and judging by what you want to see I would hold down the control key and specifically select,
% Committed Bytes in use
We can start with these and add more if needed later, click the add button to add them to the right hand side.
Now click «OK» then «Apply» and then «OK» again.
Now on the left hand side in the tree, right click your user defined «Memory» and choose «Start».
On the left, expand «Reports»>»User Defined»>»Memory»>»System Monitor Log.blg»
Clicking on that last one should show you your current monitor is running in the right hand side. If we go back to our data collector set on the left right click and say stop, then click again on the system monitor log, we can now see a graph of what is being collected. This same data is also being saved to a log file in the C root which when we open it shows something similar.
In the steps above where we chose what to see, had we left everything selected for memory, it would have been around 30 things it would graph out making it difficult to read.
From here, run it for a week and check your results. It should give you a nice graphical baseline.
Good luck and let me know if you need any further assistance.
Your how to do step-by-step is excellent. Even a kid can do it. Appreciate your help.
1) If I click on START now and then do a STOP a week later. Does it put an overhead on the server, since I am collecting this memory stats for a week ?
If yes much overhead will it be.
2) The Memory and Processor counters have several items listed. You had made me select only 3-4 of them. Which one do I need to select under MEMORY & PROCESSOR . If all I need is the graph showing me the usage. Just how the basic task manger shows. But for Date X to Date Y.
If it’s the processor you are concerned with then you could add the «Processor Performance» counter, and take a look through the «Processor Information» counter. Expanding the processor information counter you could add the «Transition/sec» and priority time.
Here is an example of one. I would select the processor info and expand the collector, then choose «Processor Time», «User Time», «Privileged Time», and «Interrupts/sec». Watch that for a bit and see if it gives the expected data you want. You can compare the active graph with the processor tab in task manager.
Your first goal is to get the base a few base lines. So if it were me, I would create a few collectors to start each one having different collectors until you determine just which ones will serve your needs. This will also give you your baseline which will be needed over a several week period to look for patterns either by time of day or user activity. Then you can begin narrowing down what might be going on behind the scenes when users complain that things are slow, (virus scanner running a scheduled scan, a daily backup that should be going off after hours is actually going off everyday at 10am, and so on)
As for performance issues with the counters, it shouldn’t be that significant if you keep the number of counters low or to what you need. Adding everything from a particular collector set or adding multiple full collector sets then yes you would see some performance issues, not to mention the data would be difficult to read with all of those lines.
I typically try to keep the counters to no more than 15, and change the colors of my lines to something I can easily read and scan after a weeks time. Anything more than that and the lines just get too jumbled up to interpret the data.
Tracking CPU and Memory usage per process
I suspect that one of my applications eats more CPU cycles than I want it to. The problem is — it happens in bursts, and just looking at the task manager doesn’t help me as it shows immediate usage only.
Is there a way (on Windows) to track the history of CPU & Memory usage for some process. E.g. I will start tracking «firefox», and after an hour or so will see a graph of its CPU & memory usage during that hour.
I’m looking for either a ready-made tool or a programmatic way to achieve this.
17 Answers 17
Just type perfmon into Start > Run and press enter. When the Performance window is open, click on the + sign to add new counters to the graph. The counters are different aspects of how your PC works and are grouped by similarity into groups called «Performance Object».
For your questions, you can choose the «Process», «Memory» and «Processor» performance objects. You then can see these counters in real time
You can also specify the utility to save the performance data for your inspection later. To do this, select «Performance Logs and Alerts» in the left-hand panel. (It’s right under the System Monitor console which provides us with the above mentioned counters. If it is not there, click «File» > «Add/remove snap-in», click Add and select «Performance Logs and Alerts» in the list».) From the «Performance Logs and Alerts», create a new monitoring configuration under «Counter Logs». Then you can add the counters, specify the sampling rate, the log format (binary or plain text) and log location.