Hey guys and welcome back.
So with the LPEG 2 examination, naturally it follows we do have to have access to some
type of Linux based system.
In my case, I actually have a Windows machine, but the way I can access a Linux machine is
that I just happen to use some type of virtualization software such as VMware or in my case right
here, virtual box.
So within my own virtual box, I have a whole ton of different Linux distributions.
In this case right now, I happen to be using Zubuntu.
Now if you were following along from the LPEG 1 examination, I actually went through how
we could install things like VMware and virtual box and how we could install within those
things like Zubuntu or Red Hat Rocky Linux.
So what I'm saying is that if you don't have a virtual machine up and running, then I definitely
would recommend you do that just now to make sure you're up and running.
My preference here is to be using the Zubuntu distribution, which is a lightweight version
of the Ubuntu distribution.
But if you would prefer to use something like say Ubuntu itself, then that is absolutely
okay.
So with that little word at the beginning, just to get us up and running.
Now let's begin and log into my system.
So right here I have my virtual machine.
What I'm going to do is I'm going to log into this virtual machine and here I am right here.
So this should be a familiar site.
I have my Linux terminal.
In fact, let me just open this up a fresh so we can see here, just go to terminal emulator
and this is all I'm doing.
So let's begin talking about our subject then.
So what we've planned to do is to talk about how we can monitor CPU and memory utilization.
Now why would that be important?
Well think about it.
What would be the number one complaint that your users would happen to mention when looking
for help with their computers?
Pretty much.
And I feel fairly safe in saying this is that people are probably going to be complaining
that for whatever reason, their computer, their system, their network happens to be
slow.
And to nobody likes a slow sluggish system, it just really brings down productivity.
This is something that we as system administrators would want to be able to solve quite quickly.
So very often what you would have to do would be to identify the actual bottleneck going
on here.
So what do I mean when I say the bottleneck?
Well I'm talking about the part of the system, the component that is actually slowing things
down.
So you just have let's say a computer here and you're connected to a router or a router
if you prefer.
And that connects to your ISP which is a massive network and then you can go out to the internet.
Now this is obviously a masterpiece of artwork right here.
Clearly my drawing skills have not really improved.
So if we happen to experience some real sluggish behavior on our machine right here, we would
want to be able to determine is this something because the server we're reaching over the
internet is very slow or maybe our ISP is having some issues, maybe our local router
is experiencing some issues, maybe there's too many users within the local network actually
using this router and overloading it or perhaps the problem lies directly on our system itself.
Maybe we are taxing the CPU too much, maybe we are taxing the memory too much.
So ultimately this is something we would want to be able to investigate.
Now we will actually look at things such as network input outputs and how we can test
such things and that maybe indeed it is our local network itself that is slow.
But let's just talk for now about our own system, our own local computer.
Let's dive in and try to monitor the CPU usage as well as the memory usage.
Now check this out, what I'm going to do here is let me just full screen this for now.
The first thing I will say is that on this little virtual machine I'm not really taxing
my computer too hard right now so in order to be able to simulate such problems whereby
my memory is being really harshly used or abused or my CPU is really overloaded, what
I want to do is to install the stress package, this is going to allow to simulate such conditions.
So what I'll do is I will say sudo apt install stress.
If I hit enter I'll have to type in my administrator password and hit enter again and this package
is now going to begin installing.
Cool, so I just wanted to get that installed on the system because we're going to be using
it very very shortly.
But before we do that one tool I want to talk to you about straight away is one called VM
stat.
This is going to allow to report our virtual memory statistics.
This will give us information about processes, about memory, about paging, CPU activities
so on and so forth.
So what I'll do is I'll clear the screen and I will just issue the command VM stat.
If I hit enter here we can actually see some information right now and at the very top
we can see our headings, we can see processes, we can see memory, we can see information
relating to swap as well as input output, system and our CPU.
If we check out the memory here we can see our swap memory as well as our free memory,
our buffer and our cache.
So when we see swap memory what we're talking about is when the hard drive is being used
as a source of memory.
This is a concept we did talk about in the LPIC 1 examination but if you don't remember.
What happens when we use so much memory, i.e. we have so much demands on our RAM that our
RAM is fully exerted.
What the system could do in that case, it could just crash if you try to open another program
because there is no more memory left.
But really that is not a good solution.
Instead of crashing what we can do is use this swap memory.
So this is going to allow us to temporarily dump that information which would ordinarily
be held in RAM and use the hard drive instead.
Now really this is not a good sign for your system if you happen to be seeing your swap
memory being used.
This tends to mean that your system is being taxed quite heavily when it comes to memory.
i.e. there are some conditions whereby you're actually using more memory than you do have
available on your system.
This is something to watch out for.
But we can also see information relating to our free memory as well as memory cache.
Now another command we could use to get similar output is the free command.
So what I'll do is I'll say free and again we're seeing similar information.
We can see our memory that is used, how much memory is free as well as what is available
for our cache.
Similarly we can see our swap memory which is coming from our hard drive and we can actually
see how much swap memory has been used.
Now if we want to happen to see this information perhaps in a little bit more readable format
we could do free-m to get these values in megabytes.
This can make things a little bit more readable.
But honestly one of my favourite commands to use with respect to monitoring things such
as CPU utilization and memory utilization is the top command.
This is going to allow us to see running processes and even more.
So what I'll do is I'll just clear my screen and just use the command top.
So check this out we actually get a lot of cool information right here.
We can see the number of tasks we have, 176 to our running.
That has now changed to one on the fly.
We have 175 sleeping and so on.
Other things we can see though are these statistics right here.
Check this out right there.
We can see our CPU percentage that is being used as well as the percentage of memory that
is actually being used and we can actually correlate that with a particular process.
So the process ID on the left we can actually correlate that to the CPU usage or the memory
usage and what I can actually do here is use the greater than sign which is going to allow
me to sort by the memory that is being used.
You see that?
Very top we see the process with the most memory or rather that is demanding the most
memory should I say which happens to be updates manager and then we have XORG and then XF
desktop and if I press the less than symbol that's going to flip once again.
So we're actually going to see it by CPU utilization the top being the process using the most CPU.
So the top command really is very useful and the respect that it allows you to drill in
and see the processes themselves that happen to be swallowing your CPU and swallowing your
memory if they happen to be getting taxed really quite heavily.
So check this out right now I have the top command running what I'm going to do is I'm
going to actually create a new terminal.
So I'll just open another terminal window right here for now and actually let me just
temporarily full screen this and what I will say is I will say stress dash dash help this
is the tool we just happened to install.
So we can see here some information relating to how we can actually use this tool.
Say for example I want to put some stress on the CPU I can use the dash C flag or dash
dash CPU and this is going to spawn some CPU processes.
So check this out then I shall clear the screen I will say stress dash C and then one IE
spin up one CPU process and to enter.
So we're now dispatching hogs as it says we're going to be increasing the CPU demands if
I go back to my other terminal right here.
Notice the CPU right here is being utilized at 100% you see that at the very top CPU and
we can tell straight away that it happens to be the process ID of 14603 and the command
that is actually using all this CPU is the stress command.
Now you might not be able to hear this because of the microphone filters that I do happen
to be using but my computer is beginning to aware that is the fans coming on because
the demands on the computer is beginning to heat this computer up.
So right now what I'll do is I'll go back to my other terminal press control C to stop
the stress command and if I go back to top notice we are no longer utilizing 100% of
the CPU.
Now if I wanted to simulate stressing some of the memory what I could do is I could go
back here and again if we look at the man page or rather not even the man page just
go back to the help page rather.
We can use the dash M flag which will allow us to tax our memory so let's try this then
so I'll say clear and I'll say stress dash M let's just give it a value of maybe C4.
We're running for VM if I go back to the top output right now we are seeing what is
consuming the most CPU at the very top which is this process right here but we can again
press the greater than sign so that would be the right arrow in my case.
Now we are actually seeing what is causing or consuming the most memory at the top so
in this case it is this process for now consuming 9.9% and it's just changed to 7.5.
This is obviously very fluid output and always changing in real time but nevertheless you're
always going to see at least in this view what is consuming the most memory in real
time and in this case right now we can see it is the stress command.
So I'll go back here I'll press control C clear the screen and in fact let me just
close this terminal.
So as we can see here we do have different tools available to us that we can use to interrogate
our CPU usage or memory usage things like the free command the VM stack command as well
as my favorite the top command and it's using these types of tools that is going to allow
you as a Linux administrator to be able to diagnose when you have a CPU problem or a
memory problem and as you can see here particularly from the top command you can actually identify
the process that is actually causing that problem or contributing to that problem and
you can take the appropriate action needed to begin to stabilize your system.
So that is all for our little introduction into monitoring CPU and memory the next thing
I want to talk to you about is monitoring disk input and outputs and well that is what
we're going to be talking about in the very next nuggets I hope this has been informative
for you and I'd like to thank you for viewing.