Now the very first thing that we're going to take a look at
analyzing as far as performance is concerned is taking a
look at our CPU load averages.
Now we can get that with the uptime command,
and we're going to see our load averages for our CPUs over the last 1 minute,
5 minutes, and 15 minutes,
but we have to understand what it actually means to us.
We can see with the uptime that we can go through and see both,
how long the system has been up, how many users are currently logged on,
as well as the load averages.
When we go through and use uptime ‑s,
it just shows us our uptime and no load averages or users that are logged in.
When we use uptime ‑p, ‑p for the so‑called pretty output,
it's just simplified output of our uptime.
We can always go through and read a little bit more.
There is nothing wrong in reading the documentation,
but it does explain then a little bit about how we see our
information and what the load averages are,
so 1 minute, 5 minutes, and 15 minutes.
The information for our uptime is coming from the file /proc/uptime.
Now that just has two columns.
The first column is taking a look at how long in seconds the system has been
up and then the second column is looking at the idle time.
If you've got more than one processor, and let's say
your processes have not been too busy, you're likely to see the second column,
the idle time being greater than the uptime because
it's the idle time for each processor.
We can always go through and look at the files and the
documentation that we're going to find from our procfs by
looking at the man page for that.
Now when we're looking at the load averages though,
a load of 1 might represent 100% utilization,
but that's only if we've got 1 CPU.
If we've got 4 CPUs, then we can go to a load of 4.
So we have to understand how many CPUs that we've got.
Now there our CPU will go through and give me all of the
information about the CPUs including our CPU count,
however, if we wanted to get clever,
and the idea here is just to introduce some of our command line utilities,
but we can then go through and grep the lines beginning with CPUs,
we can then go through and cut on our second field using
the colon as a delimiter, and then we can remove any
additional spaces with a tr command.
So it's a little overkill for what we need because we can
read the information from the screen,
but let's say you needed a number of CPUs to be
generated and used within the script,
then this way we are just returning the information about the
physical number of CPUs that we have within our system so it's
quite a good little hack to play around with,
and of course, it's introducing to you the commands.
Now we need to go out and just take a look at a little bit of this information,
so why don't we go through and take a look at the uptime command and
our load averages to get a better understanding.
We're going to be taking a look at the uptime command,
our underlying file within the procfs, we can list out our CPUs,
and here we are and welcome to the command line, and I do hope
you're working on the command line of your system.
We're going to begin by taking a look at our uptime,
and when we run through this, we can see then our current date and time.
We've been up 8 minutes,
so I've only just booted this system, there is 1 user logged on,
and then our load average in the 3 columns starting from the left,
1 minute, 5 minutes, and then we can go through and see it for 15 minutes.
Now when we look at the load average over the last 1 minute,
we can see well it's 1.08,
but we don't really know what that means until we go through and take
a look at the number of processes that we have.
So if I go through look at the lscpu command,
we're able to see all of the information about our CPU.
Now, of course, there is a lot of information,
but if I scroll back up,
we can see then there is a line beginning with CPUs and we've got 2.
So it's very easy for me to be able to go through and look at the information,
but if we needed a script to extract that,
we could then go through and send the output through to grep where
we can search then for lines beginning with CPU and then
parentheses and s and then close off our quote,
and when we go through and take a look at that, we've got
then our correct result coming back, but if we only wanted the figure 2,
we can then go through and further send it through to cut and maybe go
through and say ‑f2 where the delimiter is a colon.
Now that's good,
but we can see now we've got two and we've got white space around it,
so we then need to go through and send this information
further through to tr ‑d for delete, and then deleting the white space.
So now we've been left with just the figure 2.
So a lot of work I know,
but it's getting used to the command line tools so when you do need to
extract data like that, how can we get just the raw value.
So having 2 CPUs, and let's not forget why we're looking at this value,
means then that my load average, let's go back up and look at our uptime,
my load average could go up to 2.00 before we're starting to queue.
If the load averages something let's say like 2.50 for the last minute,
well that's not such a bad thing.
It just means that we got a burst of activity,
and we were queuing for a short amount of time.
However,
if we were looking at the 15‑minute interval and we
were looking at something like 2.50, then of course,
we've been queuing on average for the last 15 minutes which means the
system is going to be behaving slowly so we need to investigate a little
bit more about what is taking our performance.
The actual data that we're reading for our load average is
coming from cat /proc/ and then the uptime file.
Now the first column is our uptime in seconds.
The second column is the idle time.
Now we can see then that our idle time is more or less double
somewhat short of being double of our uptime.
Now that is correct because what we're really looking at is each CPU.
So again, where we've got 2 CPUs,
we really then are seeing the idle time for each of our CPUs
during the 700 seconds or so that it's been up.
We can always go through and take a look at what the uptime file means,
so man procfs.
So this then is on everything that we're going to
find within our proc file system.
I'm going to use / and we'll see then towards the bottom
corner, we can go through and search for uptime.
I'm just about to procfs back in there.
That's not the one that I want so I'm going to use n again
and then n again when we get to that file,
and then we get a description of those two number values
that we're going to see within the file.
When I quit out of this, if we ever get confused about the load average,
if we go through and take a look at our uptime command,
then we can see the system load averages and then we can see then the
time intervals that it's gathering information from.
So the past 1, 5, and 15 minutes.
So I really do hope this has been useful.
I do hope you've been carrying along on your own systems,
but we're going to now go through and move on and take a look
at how we can start diagnosing issues when our load average might appear a little bit high.