Use PowerShell To Find Resource Hogs

Tools IconHere’s a quick tidbit for any and all Windows jockeys out there. Need to figure out what is chewing up all of your system resources? Need to do it quickly and easily? Have no fear, Laz and the PowerShell are here. Some of you may know this already, so let those who don’t have some air!

OK, bring up the PowerShell (*note, this is different from the DOS “like” Command Prompt and can usually be installed through Windows Update). Once the PowerShell is open, you can use the ‘ps’ command to get a list of the currently running pr0cesses, but believe you me there are a lot of them and they scroll by all unformatted and hard to read and stuff. All in all you get a bunch of info that is hard to understand!

“So, what are we doing here?” you ask. Well, this is where just like with the ‘ps’ command (and the PowerShell in and of itself too), Windows takes some inspiration from UNIX and not only adds some nifty commands to help wrangle all that information that goes scrolling by, but also the idea of “piping” commands or a more simpler analogy, a way to link commands together. Making them talk to each other, work together and share information like never before. You pipe commands together with the ‘|’ character, and it allows you to run a command and take that output and send it to the next command. You will see this in the final command we will use, take a look:

ps | sort -desc cpu | select -f 20 | ft -a;

So, let’s take a look at what this command or set of commands really, does. First off the ps command gets the current list of processes running on the machine along with certain information about each and every one of them like the ‘Process ID’, the ‘ProcessName’ and the amount of ‘CPU’ time it’s using to name just a few. We then take all of that ‘ps’ data and “pipe” or feed it into the ‘sort’ command, telling sort to … well, sort that information by the ‘CPU’ column in “Descending” order. We then take all that sorted data and use the ‘select’ command to only grab or select the top ’20’ items in the list. Last but not least, we use the ‘ft’ command to “format” the list that we have now, which has been cut down to just the top 20 processes sorted by how much of your CPU they are using starting with the most at the top of the list and then listing the top 20 going down from there.

Ultimately, you run this command just like you see it above and you will get a list of the top processes that looks like this:

PS C:\temp> ps | sort -desc cpu | select -f 20 | ft -a;

Handles NPM(K)   PM(K)   WS(K) VM(M)   CPU(s)   Id ProcessName
------- ------   -----   ----- -----   ------   -- -----------
    197     14    6700   11456    92 1,008.66 2744 AODAssist
    422     15    6272   11572    53   886.27 1112 svchost
   2398   1032  115224   10804   420   863.37 2020 AvastSvc
    827     48  253744  247248   371   641.55 1388 svchost
   1132    106   86252  118472   421   575.07 3596 explorer
    140     69   45028   49456   173   572.51 5012 Everything
    485     47   46612   69228   284   565.83 9608 explorer
   1535     90   33912   49260   433   453.93 1460 svchost
    717     52   29416   27460   124   451.45 1352 svchost
    363     43   41048   11472   176   370.32 4436 svchost
    909     63   94836  129776   726   366.38 6388 dopus
    596     54   24476   26196   248   364.06 5136 avastui
    684     44   22172   23564   241   352.66 1048 svchost
    140     13  119472  113980   183   328.48 6972 vmware-usbarbitrator64
    300     13    9940   14796    64   306.90 6516 WmiPrvSE
    346     31   35176   29280   203   302.42 4688 tlbHost
    225     24 1431016 1339160  1460   263.47 1500 stacsv64
    865     81   27488   36708   149   216.86 1420 svchost
    202     16    7300   15020    96   215.45 1744 WHSTrayApp
    110     10    7144   10368    58   200.74 3252 BitMeterCaptureService

There you go, a nice handy little list of your top offenders! If you keep a PowerShell handy, it can be a very fast way to take a quick look at what’s going on under the hood of your PC. Enjoy!

iOS7 is ready to install!

20130919-095455.jpgOK, iOS7 is finally here after much hype and banter from all sides of the park. I went ahead and took the plunge on my iPhone 5 and installed the new OS last night. This is a bit different from my normal way of doings because usually I wait a bit to see how it all shakes out. That way if there are major issues with the launch, or the OS itself, or whatever, I can wait until all the issues are resolved before jumping in.

OK, now I have already been hearing a lot of talk from folk on the ‘net about the new OS. I have been hearing grumblings from iDevice users that installed the upgrade (mostly about the way 7 looks), from Android fanbois that just want to trash anything Apple they can, and even users that like the upgrade and have positive things to say. I’m in the latter category, although you never know, things may change as time goes on, we’ll see.

I am going to continue to learn more about iOS7 (all I can really) and I will report back with everything that I can. From my impressions and advice, to tips and tricks, and whatever else I can think of.

Now, make no mistake, this upgrade is huge, and very different in how things look, how they work and how your device does things and responds to you the user. However, after having spent a few hours with the upgrade, I like it a lot and I plan on going into why that is in more detail in subsequent posts here soon.

For now, if you feel adventurous try it out, otherwise it sure as heck won’t hurt to wait a few days or more to see what things are like after it’s been out for more than one night. Stay tuned, more to come!

Cool Tools: Networx – Track Your Network Bandwidth Usage

NetworxI wanted to let everyone know about a new tool that I found that has, coincidentally, been added to our Cool Tools list. It’s called Networx and it is a supremo wonderful tool for monitoring your bandwidth. Now, this tool has more features than I can list here so I will list some of my favorites and link to the site for this piece of software, and I urge you to go check it out. If for no other reason, check it out because it’s a FREE tool that looks and operates like it ought to cost a lot of money.

OK, first of all you can install it or just extract and run, how cool is that this thing is so tight and so well written that you can just run it without installing it, using it’s own SQLite database. You can use this to grab all of your network usage in order to get the total picture of total bandwidth consumption, but here is some of the cool stuff, you can break off your network buy things like an interface or a network subnet and/or IP address and monitor those pieces of your network as well if you want to track bandwidth usage separately.  In one instance, I know of someone who set this up to monitor the bandwidth of each roommate on the same cable subnet in order to make sure that whoever was using the bandwidth, paid for the bandwidth. No more pointing fingers and saying it’s all those streaming videos you watch and there really being no way to know. Now you can, and it’s really easy to setup. The reports it generates are way cool, the data can be exported to Excel and other standard output formats for even more tinkering, this thing has it all. And did I mention that it is totally FREE???

What are you freaking waiting for, go check it out, download it and use it, it’s awesome!!! While you are there, check out some of their other products (most of them are FREE!!).

*Note: Please remember that this is not any kind of paid advertisement or review. I am posting this because of exactly what I said in the article, I found this tool and found it to be useful and wanted to share it with my readers. I just want to make sure that you know that I in no way am getting paid for this article, nor do I get paid if you buy anything from the software vendor, etc. This is a 100% honest review from a happy user!

A little history for all us starnix guys (and gals) out there

<a href="http://www.solarum weight reduction” target=”_blank”>Ken Thompson (seated) and Dennis RitchieIf you spend any amount of time working with or administering UNIX and/or linux »”>Linux servers, especially unix »”>UNIX, you should be familiar with the text editor ‘vi’ and some commands like ‘sed’ and ‘awk’. If you have been around a while, or had the good(?) fortune of working on some old(er) systems, you might even remember the line editor ‘ed’. I’ll show my age here and recall fond memories of using ‘ed’ to write code many years back.

OK, on to the point, I was looking through Wikipedia for something entirely un-related, but ran across a tidbit of information that I thought was really cool, and that I knew I had to share with Solarum’s readers. It gives a bit of history about some of the tools that we use and love today.

From Wikipedia:

“ed is a line editor for the Unix operating system. It was one of the first end-user programs hosted on the system and has been standard in Unix-based systems ever since. ed was originally written in PDP-11/20 assembler by Ken Thompson in 1971. Ken Thompson was very familiar with an earlier editor known as qed from University of California at Berkeley, Ken Thompson’s alma mater; he reimplemented qed on the CTSS and Multics systems, so it is natural that he carried many features of qed forward into ed. Ken Thompson’s versions of qed were the first to implement regular expressions, an idea that had previously been formalized in a mathematical paper, which Ken Thompson had read. The implementation of regular expressions in ed is considerably less general than the implementation in qed.

ed went on to influence ex, which in turn spawned vi. The non-interactive Unix command grep was inspired by a common special use of qed and later ed, where the command g/re/p means globally search for the regular expression re and print the lines containing it. The Unix stream editor, sed implemented many of the scripting features of qed that were not supported by ed on Unix; sed, in turn, influenced the design of the programming language AWK, which in turn inspired aspects of PERL »”>Perl.”

It’s pretty cool how stuff flows and comes together. Who knew or would have thought that a couple simple commands or programs would turn into what we have today.

*Note: starnix refers to the combination of UNIX, Linux and any other ix/ux OS that we work with.

Navicat SSH Tunnel Error – 2013 Lost connection to MySQL server

This post is for anyone out there running any Navicat database tools.  The company, PremiumSoft, that makes the line of Navicat tools is probably best known for there incredible database administration tool, Navicat.  That’s where I first found them.  They make a database admin tool that can connect to MySQL, MS SQL Server, Oracle, SQLite and everything in between.  Aside from being able to connect to just about anything that stores data, once connected you can do so many cool things with your databases in the name of database administration, that it would take me a week to create a post for it all.  Besides, this post isn’t a commercial for Navicat, but I did have to share just how good this product is.  Believe me, it is amazing, and now they have this really wicked data modelling tool that works hand in hand with the database admin tool.  You need to see it to believe it.  Check out their site [link], they have very good demos and lots of information about the products.

My apologies, I digress, the main purpose of my post was to inform any people already using Navicat or any of the other PremiumSoft products about a problem I ran into and a way to fix it.  I am using the software with MySQL databases primarily, but I believe the principle of the fix will apply to any database and server out there, especially Linux.

Now, one of the really cool things about the database admin and data modeling tools is that they can connect to your database via a SSH (Secure Shell Port 22) tunnel, instead of the normal default and usually plain text method.  For example, by default, when you connect to a MySQL server, the username and password you give to the server is sent in plain text, so anyone can read it.  Any command you type on that database console is also sent in plain text, so anyone can read it.  Think about the new user you just created for your new web hosting customer. What if their database username and password fell into the wrong hands.  It might be bad, it might not, it might be localized just to that one customer/user which would be bad enough, but suppose they found an exploit and got root on your server.  Now they have all of your data.  Even if you don’t have any data that is secret, just the hassle alone, not to mention explaining all of this to your customer(s) make this a really bad day.

This isn’t usually a big concern if you are running the database on the same server as the web server (which is common practice in many hosting scenarios), and if your database tools are on the server like the MySQL command line tools and such.  But what if you want to connect to the database from say, your PC?  Like you would do if using a database admin tool like Navicat.  You certainly don’t want all of the data that you will be sending back and forth to be in plain text, right?  Well, now you don’t have to leave it in plain text!  You can setup the connection in Navicat to connect to the Secure Shell server, which means you have an encrypted connection and not plain text.  Then, you can use the SSH tunnel that was created to connect to the database server itself.  What this means is that you use the SSH server to redirect your communications to the database server locally, so no one can see it.  Just like you were sitting at the server itself.

I’ll run through it again real quick, see if this makes sense.  The connection between your PC and the server running database is now encrypted and secure from prying eyes because instead of connecting to the database server directly, you are connecting to the Secure Shell server.  It is now the Secure Shell server that takes your communication and hands it off to the database server internally, so it’s safe from anyone watching outside.  It’s really cool, and just another reason I love the Navicat product so much.  Not to mention Linux as well!

The problem that I found was this, when I created the link to the SSH server in order to talk to the MySQL server, it wouldn’t connect.  I would get the connection to the SSH server, but when it then tried to talk to the database server, the database server kicked it out like no connection could be made.  I tried connecting locally from the Linux console think that maybe I killed some MySQL process that listens for connections, but it was working fine.  I tried it again and again but it just didn’t work.  The error I was getting from Navicat was this:

2013 – Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0

I did some digging and found a basic setting to check.  This didn’t fix the problem, but I thought I would share it here since it has to be set in order for the tunnel to work:

  1. In the sshd config file (/etc/ssh/sshd.config) make sure that AllowTcpForwarding is enabled, because the default is disabled in most cases.

What I finally found to be causing the problem, was TCP_WRAPPERS.  Naturally, in my hosts.allow file I had the IP address of my PC in there, so that I could connect to the server.  So at first this seemed odd that this was my problem.  However, when you think about it, it makes sense.  The connection that is coming to the MySQL server originates not from my PC, but from the SSH server itself.  That’s right, because my connection stops at the SSH server, and then the SSH server sends the data to the database server.  This is a simplified view of things, but it should work to illustrate what’s going on.  Therefore, the simple fix was to add mysqld: localhost or to the hosts.allow file in order to allow the traffic to go through TCP_WRAPPERS and to the MySQL server.  I read more about this once I worked it out, and I saw some “technicians” offering the solution of adding mysqld: ALL to their hosts.allow file.  Egads! I said!  Technically that would work, but damn, don’t open it up to allow everyone into your databases!!!  Just add localhost or and you will be fine, and you will keep out the other riff raff.  I hope this helps some of you out there, enjoy!