Monitoring Memory Usage
I'm more in line with one of the preceding posts that mentioned Cacti as a great way to monitor memory usage. However, since it appears cacti is no longer popular in the mainstream, there is an alternative graphing application called Graphite.
Graphite is relatively easy to install on a ubuntu server and to install it, you can check out this link for the easy to follow installation procedures.
After graphite has been installed, now, you can send memory metrics to it, at whichever interval you wish; every 5 seconds, every minute, every hour...etc.
To graph memory metrics, as already suggested in previous posts, you can write your own script using system tools to gather the necessary memory information. Or, you can use a prewritten snmp plugin that'll do all the work for you.
If you wish to write your own memory script, it'll be wise to ensure you account for buffered and cached memory when calculating used memory, otherwise, you'll end up gathering false data.
If you wish to instead utilize an snmp plugin that already does all the necessary calculations for you, here's a link to one that works pretty well: checkMemoryviaSNMP.
Pros of SNMP:
I have snmp installed on all the remote nodes I monitor. This allows me to monitor all my systems from one central server(s), without having to copy or put a plugin on the remote nodes.
Cons of SNMP:
You'd have to ensure the snmp agent is installed on each of the remote nodes you wish to monitor memory on. However, this installation will be a one time deal. If you're using automation tools such as chef or puppet or similar tools in your environment, then this isn't a problem at all.
Configuration of the SNMP agent on the remote node(s):
After the snmp agent has been installed, simply vi the /etc/snmpd/snmpd.conf file and add this line to it:
rocommunity (specify-a-community-string-aka-password-here)
Then restart the snmpd agent, with:
/etc/init.d/snmpd restart
Then, on your central server, from which you instead to monitor all your other servers, you can run the following command:
$ time ./checkMemoryviaSNMP -v2 public gearman001.phs.blah.com 30 90 graphite,10.10.10.10,2003,typical
WARNING: Used = [ 3.26154 GB ], Installed = [ 5.71509 GB ], PCT.Used = [ 57.069% ], Available.Memory = [ 2.00291 GB ]. Buffer = [ 137.594 MB ], Cached = [ 1.3849 GB ]. Thresholds: [ W=(30%) / C=(90%) ]. System Information = [ Linux gearman001.phs.blah.com 2.6.32-504.30.3.el6.x86_64 #1 SMP Thu Jul 9 15:20:47 EDT 2015 x86_64 ].
real 0m0.23s
user 0m0.03s
sys 0m0.02s