 So I have a little free time this morning. I was gonna walk to church, but it's raining so much So I think I'm gonna skip it out today But I figured I might as well put it to a little bit of use by writing some modules for my status bar Now I'm gonna do that, but that's gonna involve well Let me tell you what the modules I want are gonna be I want to have a memory module and that shows me the used memory on my computer as a proportion of the whole memory and I want to be able to click on that and I want it to show me the 10 most memory intensive processes and then on the other side I also want a CPU module that shows CPU temperature and if I click on that it shows me the most intensive CPU processes So that's my goal in this video, but even if you don't have a status bar Or you know you can still follow along because I actually want to go through the different commands to produce this kind of output How do you actually find memory? You know in most intensive processes and stuff like that It's relatively simple. Some of you might already know But we can go through it. So again, here's my wish list I'm gonna show All of the memory like a proportion of the used memory and total memory on my computer I'm gonna show CPU temperature one command to generate CPU temperature And I want to be able to show the most the 10 most memory intensive or CPU intensive processes That's what I want. And so I'm gonna do that I'm gonna Find four commands for those four different things and then I'm gonna create a status bar module Which is gonna be specific the eye to i3 blocks, but it'll be similar if you have some other kind of status bar Because but i3 blocks is the one I'm using So let's go ahead and start out the first one. I'll do is this show memory used over total Okay, so I want if I have eight gigs of RAM. I want it to show, you know Maybe I'm using 200 megs over eight gigs. That's what I want the output to look like now in order to do that It's relative. This is actually Relatively simple. You can really just use the free command now if you run free This will actually show you your memory used of course you can see it's not in human readable format But it's relatively easy to get it that way We can just do free with the option of H and you'll see that we pretty much already have what we want here We have our total memory here and our use memory here These these can be relevant as well But I'm just gonna take the use memory and total memory as well and that's it So in order to get this in the format we want if we want it to be used Slash total we really just need an awk command to do this. I'm gonna pipe this output Into awk now the first thing I really only want this line So I'm gonna say to awk only give me the line that starts with mim That's all I want But I want what I want you to do with that is I want you to print it out in the following format So this thing here is the third element So I'm gonna say first print out the third element then give me a slash and then give me the second element Which is going to be this thing here, of course close that print command close that awk and That produces the exact output we want so whenever I run this command It's gonna show me use memory out of total memory of course we can run it a couple times It's not really changing that much because my memory amount is pretty much the same But we can take this command actually I'll I'll copy this out And I'm gonna put it over here in our wish list because that's we already have one of the commands We want okay, so I'm gonna keep that and I'll make my status bar with it later Now the next thing I want to do is I want to do CPU temperature So how do I get CPU temperature now? This actually requires a program. Well, you probably already have it. It's LM sensors I think If I just run that yeah, so this is already installed on my computer It's probably actually installed on your computer because it's pulled as a dependency for a lot of things But LM sensors gives you yet another very simple command just sensors So if I run that If I run that you'll see that it gives me Basically, whatever temperature module or temperature Monitors there on your machine it shows you what values they have so you'll see right here here is ours are basically our temperature that we're looking for It's 63 degrees Celsius, so we can get that out. We can awk this out in the same way Now you can check the options of sensors if you want I mean if you really insist in your you know your CPU temperature being in Fahrenheit for example You can give the f option, but I feel like even Americans refer to CPU temperature and Celsius That's just how it is. But anyway, so we can do the same thing with this We did with the last option we can just pipe it in the awk and we only want the line that says CPU or Temperature one or that starts with that so we can go temp One that's what we're looking for and find that line and print out the second element because well This is the first one. This is the second one nice and simple close that off and there is our our degrees Celsius that's all we need one again one another little simple command I'm gonna copy this out and I'm gonna put it in here so now we have our CPU temperature command and the last two things are Maybe a little more difficult. I don't want to say more difficult But they involve slightly more complicated of a command and that is show the most Memory intensive processes and show the most CPU intensive processes. Now. These are gonna be similar commands as we'll see Now the program we're going to use for this is PS so if you don't know what PS is It's really just a Command that shows you the kind of processes you have and Different information about them and it can show how much memory one is using or how much CPU Usage it has or something like that now PS I encourage you to look at the manual because there's a lot you can do with this command Just because it has so many options now. I'm gonna give PS a couple options I was sort of racking my brain as for which ones I should best give to it before I turn this video on but the ones I've decided on our AX and C Now AX let me just run PS AX You'll usually see people running this and this will in effect I mean you can check the documentation on the A option and the X option yourself It really has to do with you know, what's a user process with the case of of a or not not really user Well, just read read the manual. I don't it's not important what they do here But PS AX is gonna basically print out what we think of as being processes, you know, so you have bash You have ST you have different stuff going on here. You even have well show that in a second So you have the different process of processes. I also want to give it the C option And what C does is well, maybe I should compare them So if you don't give the C option, it's gonna give some full paths to some things like user bin pulse audio But if I just give C, it's just gonna show pulse audio. So that's a little more intuitive I want the user interface to be cleaner. I don't want all that junk and I'm also gonna give it the H option Gonna give it the H option, which will get rid of the header at the very top because we're gonna be using We're gonna be messing around with this kind of stuff and the next thing I want to do So my goal here, this prints out a bunch of information, but I want it specifically Let's do the memory first. We want it specifically to show us how much memory is used by a process And what we can do here, and we make this just a little bigger You can give it the O option or whatever and then Set some kind of specific output So the output that I want is I'm gonna say command and then percent mem And this pretty much does exactly what you expect It's gonna list out the command and the percentage of memory used So now we have all of these commands and we have them sorted by or not sorted, but you have the memory percentage Uh memory percent of each one of them. You can also give ps options like sort So I can say specifically I want you to sort this and I want you to sort this by percentage of memory So now we have all of these you'll notice that the biggest ones are at the very bottom Ffmpeg is the most intensive process running that of course is recording this video An mpv that's the thing that's generating my head right here, but you know, that's what we expect Um, but I actually actually now that I think about it, we really want Minus memory because we want the most intensive process Processes to be at the top, right? So if uh, well, maybe I should rerun that So if I go up here to the very top, you'll see that that's where they are Because this allows us to let's say Pipe it into to head or something like that I know we talked about using said 11q in the last video, but we'll just do something normal and use head Um, so if you pipe this in the head, you'll actually get What in effect is our 10 most memory intensive processes sorted with the memory percentage But I want to change this command a little more first off if I you know, again as I said I want my module to print out these um, I wanted to print out these values if I click on them But I don't I don't like this these big spaces here So luckily we can in this uh output format we can actually specifically say I want the command to only be 15 pixels Or 15 pixels uh 15 spaces or whatever it is Um The what's the word for it totally. Yeah, definitely not 15 pixels But anyway, so if I give it a 15 here, it's only going to have you know a width of 15 characters Um, and that's going to be it. So that's sort of like what I want here So I'm going to take this command. I don't think there's anything else I need in this I'm going to copy it over again to this little document where I'm keeping all of these commands And actually the cpu temperature Um is going to be pretty much the same thing We can actually take all of this but I'm going to replace memory With cpu and ps will give us the exact same stuff. So now we're looking at the most I won't look at this ffmpeg that that's how how much uh memory or not memory how intensive You know some kind of process like this can be so you can sort you know by cpu percentage and now we have that So I'm going to take this command copy it I'm going to take it over here. So now we have all the commands we really want Oops did not copy all of this So now we have all of the commands that we want and um We can go ahead and start building our i3 blocks modules now. Let me close out of this So we have all these I'm going to Make this normal Now I'm going to pull up. So I have this other window in On my other workspace and this is the general format of an i3 blocks module Now this is I'm going to start out. I think I've named this file i3 mim because this is going to be the memory Module now by default. I want it to just print out the Percentage of memory or the the ratio of memory used. So I'm going to put in this command that says Uh, you know that prints out the used memory over the total memory now I'm going to go to my i3 blocks config Which is in i3 blocks config and I'm going to set let's say A new module for memory. That's what I'm going to name it the command I'm going to run is this script here Which is i3 mim So i3 mim and it's already my path directory. So I don't have to worry about that the interval Let's say I want it every 30 seconds and You can also give it a label. That's going to be like a decorative You know logo or something I'm going to choose a brain because it's about memory So I'm going to put this in I'm going to save both of these documents And I'm going to restart i3 blocks and you'll see up here I have I now have a brain icon and it has the used memory over the total memory And that's pretty much exactly what I want. Now. Additionally, as I said, I want to be able to click on this Um and for it to show the um, what was I about to say the the most intensive processes Now I actually already have this case statement Up here. I'm going to uncomment all this now in i3 blocks again This is going to be i3 blocks specific But in i3 blocks when you have a script that you're running as your You know, you're the the script for your module or whatever When you click on it, it automatically gives it a block button Variable you'll see I just clicked on it and it printed out left click action because When I clicked on that it set block button equal to one and then it ran this command here So what we wanted to do is I wanted to print out I'm going to have it print out a pop-up that has the most intensive processes on it. So I'm going to get rid of this now. I'm going to be using notify send Um, just as an example So notify send is the little command that prints out some kind of notification Just to show you that this thing works if I click on this you'll see that I have I printed out this text right here But I wanted to print out this little command. So I'm going to take this command most intensive memory most intensive memory Processes so I'm going to have it print That Make it to put it all on the line. So it's pretty I think that this should just work. Let's see Okay. Yeah, great. So that prints out all of our processes And it shows the percentage of memory usage of each. That's exactly what we want So I'm going to leave it at this. I might add in some other things in a second just to make it A little more specific what we're looking at. You could say for example, let's say you know most memory well, let's say biggest memory hogs Put that on a new line. So print out print that out and it'll print. Uh, oops, probably I guess put in another. Oh, no I'm going to tab it over. That's what it is because it's sensitive to white space Um, yeah, so that prints that out. So that's pretty much what what we want So I'm going to leave it at that. I'll I'll put some this is going to be on my github But I'll probably add some other stuff in before I actually push it But pretty much the same thing would be Let's make our cpu module. So I'm going to open up actually maybe I'm not quite sure what directory I'm in I'm going to go to Uh, my status bar I'm going to create i3 cpu and that's going to be my new script Um Then I am going to copy and paste pretty much everything from here into this script I'm going to make it executable. Probably should have done this before the Video is on. You'll notice that I'm Craining my head. That's because I have my microphone in the way. I don't know why I just don't move that Um, anyway, I should probably edit that out but I'm too lazy Okay, so now that we have all that we can make a cpu module. I'm going to set that up in i3 blocks command i3 cpu Interval let's say I want that maybe every 15 seconds and the label I'm going to give it Maybe I'll give it some kind of I don't know computer Of a laptop computer. It doesn't really matter I'll put that in And if I let's see if I run this yeah, so that'll pop up now We just have to change the commands to the things we want So our cpu temperature is this command. So I'm going to go in here and replace The memory command with that. So now it will show cpu. Oops. It'll show cpu So 61 degrees Celsius and now I will take instead of that memory command Actually, I don't need a paste that I can just replace mem with cpu And that will give us our most intensive cpu processes. So And I will biggest cpu pods So now redo that reload i3 blocks and if I click on this it'll show me biggest cpu hogs again ffmpeg just steals today look at all that But yeah, so that's pretty much all we want. I guess so anyway So this has been sort of I guess just a real life implementation of something I'm going to toy around with these scripts a little more maybe add some bells and whistles Usually what I do is I if you like right click on a module I want it to show some information about it. So I'll probably add those as well You can just put them in this block Actually just undo this and that'll be your right click action Um, so anyway, you can check these out on my github. If you have any questions recommendations Ask or put them in the comments or something like that. But anyway, that's going to be pretty much it and I'll see you guys next time