Jack Wallen shows you how to make use of the Linux smem command to get useful memory usage information on your data center servers.
It is crucial to understand what is going on with your data center servers. You need to know how well they are performing and how their operating systems are making use of resources. One very critical resource is memory. When something goes awry with memory, a server can be rendered inoperable thereby inflicting much-unwanted downtime on your business. To that end, you need the right monitoring tools at the ready.
If your data center includes Linux machines, you have a lot of tools at your command. Many of those tools go unheard of. One such lesser-known tool for keeping tabs on memory usage is smem. The smem command reports physical memory usage, but unlike top, smem takes shared memory pages into account.
But what makes smem a much better solution for memory usage reports is that it can generate graphs to make reading memory usage even easier. Of course, to make use of the graph feature, your server must have a GUI. Should you be working with a headless Linux server, smem can still report usage, but in a more standard fare.
The smem command features the following:
- System overview listing
- Process, mapping, or user listing and filtering
- Configurable output from multiple data sources
- Configurable output units and percentages
- Reads live data from /proc
- Can read data snapshots from directory mirrors or compressed tarballs
- Lightweight enough for embedded systems
- Built-in chart generation
Let's get this tool installed and see how it is used.
I'll be installing smem on the Debian 9 platform, one with the GNOME GUI. The installation of smem can be easily installed on the likes of CentOS, by simply modifying the installation command to suit your platform's package manager (i.e. swap out apt for yum).
To install smem on Debian, open up a terminal window and issue the following command:
sudo apt install smem
NOTE: The above command does require your user to be a member of sudoers. If they are not, you can first su to the root user and then issue the installation command.
Once the command completes, you're ready to start using smem.
I'm going to first show you how to use smem to report memory usage within the terminal window. The basic command is simply smem. This will report Swap, USS (Unique Set Size--the portion of main memory that is occupied by a process and guaranteed to be private), PSS (Proportional Set Size--the portion of main memory that is occupied by a process and composed by private memory), and RSS (Resident Set Size--the portion of memory that is occupied by a process held in main memory). This command will also report on all running PIDs (Figure A).
Let's make smem a bit more useful. Say you want to check the memory usage of a specific PID. First, let's take a look at system-wide memory usage. Issue the command smem -w to see how areas such as hardware, kernel, userspace memory, free memory are using memory (Figure B).
What if you want to view memory usage on a per-user basis? For this command to work properly, we have to evoke it using sudo, otherwise it will only report on memory usage of the user calling the command. The command for this is sudo smem -u (Figure C).
Now, let's say you need to find out the memory usage of a particular application. Say, for example, your machine includes a web server and you want to find out how the server is handling memory. For that, you could issue the command sudo smem --processfilter="apache2". The results would be the memory in use by your running web server (Figure D).
All of the above commands can be used on a headless Linux server. But if your server has a GUI, you can take advantage of smem's ability to present information in graph form. Say you want to see Apache's memory usage in a bar graph. For that, the command would be:
sudo smem --processfilter="apache2" --bar pid -c"pss rss"
The output of that command would be presented in an easy to read bar graph (Figure E).
There's quite a bit more to be had with smem. I highly recommend you issue the command man smem and read through the entire man page to find out what all smem has to offer. This is a very powerful and useful tool, one that any admin would be happy to have on their data center servers.
- How to use the Linux iostat command to check on your storage subsystem (TechRepublic)
- How to use syslog-ng to collect logs from remote Linux machines (TechRepublic)
- How to install and use Dockstation for easy container builds (TechRepublic)
- How to install the Prometheus monitoring system on Ubuntu 16.04 (TechRepublic)
- How to use the Canonical Livepatch service to patch a kernel without rebooting (TechRepublic)
- CES 2018: Seagate announces 1PB high-density enclosure (ZDNet)