This repository has been archived on 2026-05-29. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
indexterm:[system information,gathering]indexterm:[information,about your system]
In order to configure the system, system administrators often need to determine the amount of free memory, how much free disk space is available, how the hard drive is partitioned, or what processes are running.
The [command]#ps# command allows you to display information about running processes. It produces a static list, that is, a snapshot of what is running when you execute the command. If you want a constantly updated list of running processes, use the [command]#top# command or the [application]*System Monitor* application instead.
To list all processes that are currently running on the system including processes owned by other users, type the following at a shell prompt:
[subs="quotes, macros"]
----
[command]#ps# [option]`ax`
----
For each listed process, the [command]#ps ax# command displays the process ID (`PID`), the terminal that is associated with it (`TTY`), the current status (`STAT`), the cumulated CPU time (`TIME`), and the name of the executable file (`COMMAND`). For example:
[subs="quotes, macros"]
----
~]$ [command]#ps ax#
PID TTY STAT TIME COMMAND
1 ? Ss 0:02 /usr/lib/systemd/systemd --system --deserialize 20
2 ? S 0:00 [kthreadd]
3 ? S 0:00 [ksoftirqd/0]
5 ? S 0:00 [kworker/u:0]
6 ? S 0:00 [migration/0]
_[output truncated]_
----
To display the owner alongside each process, use the following command:
[subs="quotes, macros"]
----
[command]#ps# [option]`aux`
----
Apart from the information provided by the [command]#ps ax# command, [command]#ps aux# displays the effective username of the process owner (`USER`), the percentage of the CPU (`%CPU`) and memory (`%MEM`) usage, the virtual memory size in kilobytes (`VSZ`), the non-swapped physical memory size in kilobytes (`RSS`), and the time or date the process was started. For instance:
[subs="quotes, macros"]
----
~]$ [command]#ps aux#
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
You can also use the [command]#ps# command in a combination with [command]#grep# to see if a particular process is running. For example, to determine if [application]*Emacs* is running, type:
[subs="quotes, macros"]
----
~]$ [command]#ps ax | grep emacs#
2625 ? Sl 0:00 emacs
----
For a complete list of available command line options, refer to the *ps*(1) manual page.
The [command]#top# command displays a real-time list of processes that are running on the system. It also displays additional information about the system uptime, current CPU and memory usage, or total number of running processes, and allows you to perform actions such as sorting the list or killing a process.
To run the [command]#top# command, type the following at a shell prompt:
[subs="quotes, macros"]
----
[command]#top#
----
For each listed process, the [command]#top# command displays the process ID (`PID`), the effective username of the process owner (`USER`), the priority (`PR`), the nice value (`NI`), the amount of virtual memory the process uses (`VIRT`), the amount of non-swapped physical memory the process uses (`RES`), the amount of shared memory the process uses (`SHR`), the percentage of the CPU (`%CPU`) and memory (`%MEM`) usage, the cumulated CPU time (`TIME+`), and the name of the executable file (`COMMAND`). For example:
----
~]$ top
top - 19:22:08 up 5:53, 3 users, load average: 1.08, 1.03, 0.82
xref:System_Monitoring_Tools.adoc#interactive-top-command[Interactive top commands] contains useful interactive commands that you can use with [command]#top#. For more information, refer to the *top*(1) manual page.
The `Processes` tab of the [application]*System Monitor* tool allows you to view, search for, change the priority of, and kill processes from the graphical user interface.
To start the [application]*System Monitor* tool, either select menu:Applications[System Tools > `System Monitor`pass:attributes[{blank}]] from the Activities menu, or type [command]#gnome-system-monitor# at a shell prompt. Then click the `Processes` tab to view the list of running processes.
For each listed process, the [application]*System Monitor* tool displays its name (`Process Name`),
user (`User`),
percentage of the CPU usage (`% CPU`),
process ID (`ID`),
memory usage (`Memory`),
total disk read and write (`Disk read total` and `Disk write total`),
current disk read and write (`Disk read` and `Disk write`),
and prioritiy (`Priority`).
To sort the information by a specific column in ascending order, click the name of that column. Click the name of the column again to toggle the sort between ascending and descending order.
By default, the [application]*System Monitor* tool displays a list of processes that are owned by the current user. Selecting various options from the View menu allows you to:
* view only active processes,
* view all processes,
* view your processes,
* view process dependencies,
* view a memory map of a selected process,
* view the files opened by a selected process, and
* refresh the list of processes.
Additionally, various options in the Edit menu allows you to:
* stop a process,
* continue running a stopped process,
* end a process,
* kill a process,
* change the priority of a selected process, and
* edit the [application]*System Monitor* preferences, such as the refresh interval for the list of processes, or what information to show.
You can also end a process by selecting it from the list and clicking the btn:[End Process] button.
The [command]#free# command allows you to display the amount of free and used memory on the system. To do so, type the following at a shell prompt:
[subs="quotes, macros"]
----
[command]#free#
----
The [command]#free# command provides information about both the physical memory (`Mem`) and swap space (`Swap`). It displays the total amount of memory (`total`), as well as the amount of memory that is in use (`used`), free (`free`), shared (`shared`), in kernel buffers (`buffers`), and cached (`cached`). For example:
----
~]$ free
total used free shared buffers cached
Mem: 761956 607500 154456 0 37404 156176
-/+ buffers/cache: 413920 348036
Swap: 1540092 84408 1455684
----
By default, [command]#free# displays the values in kilobytes. To display the values in megabytes, supply the [option]`-m` command line option:
[subs="quotes, macros"]
----
[command]#free# [option]`-m`
----
For instance:
----
~]$ free -m
total used free shared buffers cached
Mem: 744 593 150 0 36 152
-/+ buffers/cache: 404 339
Swap: 1503 82 1421
----
For a complete list of available command line options, refer to the *free*(1) manual page.
The `Resources` tab of the [application]*System Monitor* tool allows you to view the amount of free and used memory on the system.
To start the [application]*System Monitor* tool, either select menu:Applications[System Tools > `System Monitor`pass:attributes[{blank}]] from the Activities menu, or type [command]#gnome-system-monitor# at a shell prompt. Then click the `Resources` tab to view the system's memory usage.
[[fig-sysinfo-memory]]
.System Monitor — Resources
image::system-monitor-resources.png[The Resources tab of the System Monitor application.]
In the `Memory and Swap History` section, the [application]*System Monitor* tool displays a graphical representation of the memory and swap usage history, as well as the total amount of the physical memory (`Memory`) and swap space (`Swap`) and how much of it is in use.
The `Resources` tab of the [application]*System Monitor* tool allows you to view the current CPU usage on the system.
To start the [application]*System Monitor* tool, either select menu:Applications[System Tools > `System Monitor`pass:attributes[{blank}]] from the Activities menu, or type [command]#gnome-system-monitor# at a shell prompt. Then click the `Resources` tab to view the system's CPU usage.
[[fig-sysinfo-cpu]]
.System Monitor — Resources
image::system-monitor-resources.png[The Resources tab of the System Monitor application.]
In the `CPU History` section, the [application]*System Monitor* tool displays a graphical representation of the CPU usage history and shows the percentage of how much CPU is currently in use.
The [command]#lsblk# command allows you to display a list of available block devices. To do so, type the following at a shell prompt:
[subs="quotes, macros"]
----
[command]#lsblk#
----
For each listed block device, the [command]#lsblk# command displays the device name (`NAME`), major and minor device number (`MAJ:MIN`), if the device is removable (`RM`), what is its size (`SIZE`), if the device is read-only (`RO`), what type is it (`TYPE`), and where the device is mounted (`MOUNTPOINT`). For example:
By default, [command]#lsblk# lists block devices in a tree-like format. To display the information as an ordinary list, add the [option]`-l` command line option:
The [command]#blkid# command allows you to display information about available block devices. To do so, type the following at a shell prompt as `root`:
[subs="quotes, macros"]
----
[command]#blkid#
----
For each listed block device, the [command]#blkid# command displays available attributes such as its _universally unique identifier_ (`UUID`), file system type (`TYPE`), or volume label (`LABEL`). For example:
By default, the [command]#lsblk# command lists all available block devices. To display information about a particular device only, specify the device name on the command line:
[subs="macros"]
----
blkid pass:quotes[_device_name_]
----
For instance, to display information about `/dev/vda1`, type:
You can also use the above command with the [option]`-p` and [option]`-o udev` command line options to obtain more detailed information. Note that `root` privileges are required to run this command:
The [command]#partx# command allows you to display a list of disk partitions. To list the partition table of a particular disk, as `root`, run this command with the [option]`-s` option followed by the device name:
[subs="macros"]
----
partx -s pass:quotes[_device_name_]
----
For example, to list partitions on `/dev/vda`, type:
----
~]# partx -s /dev/vda
NR START END SECTORS SIZE NAME UUID
1 2048 1026047 1024000 500M
2 1026048 41943039 40916992 19.5G
----
For a complete list of available command line options, refer to the *partx*(8) manual page.
The [command]#findmnt# command allows you to display a list of currently mounted file systems. To do so, type the following at a shell prompt:
[subs="quotes, macros"]
----
[command]#findmnt#
----
For each listed file system, the [command]#findmnt# command displays the target mount point (`TARGET`), source device (`SOURCE`), file system type (`FSTYPE`), and relevant mount options (`OPTIONS`). For example:
By default, [command]#findmnt# lists file systems in a tree-like format. To display the information as an ordinary list, add the [option]`-l` command line option:
The [command]#df# command allows you to display a detailed report on the system's disk space usage. To do so, type the following at a shell prompt:
[subs="quotes, macros"]
----
[command]#df#
----
For each listed file system, the [command]#df# command displays its name (`Filesystem`), size (`1K-blocks` or `Size`), how much space is used (`Used`), how much space is still available (`Available`), the percentage of space usage (`Use%`), and where is the file system mounted (`Mounted on`). For example:
----
~]$ df
Filesystem 1K-blocks Used Available Use% Mounted on
By default, the [command]#df# command shows the partition size in 1{nbsp}kilobyte blocks and the amount of used and available disk space in kilobytes. To view the information in megabytes and gigabytes, supply the [option]`-h` command line option, which causes [command]#df# to display the values in a human-readable format:
Note that the `/dev/shm` entry represents the system's virtual memory file system, `/sys/fs/cgroup` is a cgroup file system, and `/run` contains information about the running system.
For a complete list of available command line options, refer to the *df*(1) manual page.
The [command]#du# command allows you to displays the amount of space that is being used by files in a directory. To display the disk usage for each of the subdirectories in the current working directory, run the command with no additional command line options:
[subs="quotes, macros"]
----
[command]#du#
----
For example:
[subs="quotes, macros"]
----
~]$ [command]#du#
8 ./.gconf/apps/gnome-terminal/profiles/Default
12 ./.gconf/apps/gnome-terminal/profiles
16 ./.gconf/apps/gnome-terminal
_[output truncated]_
460 ./.gimp-2.6
68828 .
----
By default, the [command]#du# command displays the disk usage in kilobytes. To view the information in megabytes and gigabytes, supply the [option]`-h` command line option, which causes the utility to display the values in a human-readable format:
At the end of the list, the [command]#du# command always shows the grand total for the current directory. To display only this information, supply the [option]`-s` command line option:
[subs="quotes, macros"]
----
[command]#du# [option]`-sh`
----
For example:
[subs="quotes, macros"]
----
~]$ [command]#du -sh#
68M .
----
For a complete list of available command line options, refer to the *du*(1) manual page.
The `File Systems` tab of the [application]*System Monitor* tool allows you to view file systems and disk space usage in the graphical user interface.
To start the [application]*System Monitor* tool, either select menu:Applications[System Tools > `System Monitor`pass:attributes[{blank}]] from the Activities menu, or type [command]#gnome-system-monitor# at a shell prompt. Then click the `File Systems` tab to view a list of file systems.
[[fig-sysinfo-filesystems]]
.System Monitor — File Systems
image::system-monitor-file-systems.png[The File Systems tab of the System Monitor application.]
For each listed file system, the [application]*System Monitor* tool displays the source device (`Device`), target mount point (`Directory`), and file system type (`Type`), as well as its size (`Total`) and how much space is free (`Free`), available (`Available`), and used (`Used`).
The [command]#lsusb# command allows you to display information about USB buses and devices that are attached to them. To list all USB devices that are in the system, type the following at a shell prompt:
[subs="quotes, macros"]
----
[command]#lsusb#
----
This displays a simple list of devices, for example:
[subs="quotes, macros"]
----
~]$ [command]#lsusb#
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
_[output truncated]_
Bus 001 Device 002: ID 0bda:0151 Realtek Semiconductor Corp. Mass Storage Device (Multicard Reader)
Bus 008 Device 002: ID 03f0:2c24 Hewlett-Packard Logitech M-UAL-96 Mouse
Bus 008 Device 003: ID 04b3:3025 IBM Corp.
----
You can also use the [option]`-v` command line option to display more verbose output:
[subs="quotes, macros"]
----
[command]#lsusb# [option]`-v`
----
For instance:
[subs="quotes, macros"]
----
~]$ [command]#lsusb -v#
_[output truncated]_
Bus 008 Device 002: ID 03f0:2c24 Hewlett-Packard Logitech M-UAL-96 Mouse
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x03f0 Hewlett-Packard
idProduct 0x2c24 Logitech M-UAL-96 Mouse
bcdDevice 31.00
iManufacturer 1
iProduct 2
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
_[output truncated]_
----
For a complete list of available command line options, refer to the *lsusb*(8) manual page.
You can also use the [option]`-v` command line option to display more verbose information, or [option]`-vv` to increase the verbosity level even further:
The [command]#lscpu# command allows you to list information about CPUs that are present in the system, including the number of CPUs, their architecture, vendor, family, model, CPU caches, etc. To do so, type the following at a shell prompt:
[subs="quotes, macros"]
----
[command]#lscpu#
----
For example:
----
~]$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 1
Core(s) per socket: 4
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 23
Stepping: 7
CPU MHz: 1998.000
BogoMIPS: 4999.98
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 3072K
NUMA node0 CPU(s): 0-3
----
For a complete list of available command line options, refer to the *lscpu*(1) manual page.
The [command]#hw-probe# command allows you to list all hardware devices, perform sanity tests for some of them and submit result to the link:++https://github.com/linuxhw++[hardware database]. To do so, type the following at a shell prompt:
{MAJOROSVER} includes the [application]*Net-SNMP* software suite, which includes a flexible and extensible _Simple Network Management Protocol_ (*SNMP*) agent. This agent and its associated utilities can be used to provide performance data from a large number of systems to a variety of tools which support polling over the SNMP protocol.
This section provides information on configuring the Net-SNMP agent to securely provide performance data over the network, retrieving the data using the SNMP protocol, and extending the SNMP agent to provide custom performance metrics.
The Net-SNMP software suite is available as a set of RPM packages in the {MAJOROS} software distribution. xref:System_Monitoring_Tools.adoc#tabl-System_Monitoring_Tools-Net-SNMP-Packages[Available Net-SNMP packages] summarizes each of the packages and their contents.
|[package]*net-snmp*|The SNMP Agent Daemon and documentation. This package is required for exporting performance data.
|[package]*net-snmp-libs*|The `netsnmp` library and the bundled management information bases (MIBs). This package is required for exporting performance data.
|[package]*net-snmp-utils*|SNMP clients such as [command]#snmpget# and [command]#snmpwalk#. This package is required in order to query a system's performance data over SNMP.
|[package]*net-snmp-perl*|The [command]#mib2c# utility and the `NetSNMP` Perl module.
|[package]*net-snmp-python*|An SNMP client library for Python.
|===
To install any of these packages, use the [command]#dnf# command in the following form:
Note that you must have superuser privileges (that is, you must be logged in as `root`) to run this command. For more information on how to install new packages in {MAJOROS}, refer to xref:package-management/DNF.adoc#sec-Installing[Installing Packages].
The [package]*net-snmp* package contains `snmpd`, the SNMP Agent Daemon. This section provides information on how to start, stop, and restart the `snmpd` service, and shows how to enable or disable it in the `multi-user` target unit. For more information on the concept of target units and how to manage system services in {MAJOROS} in general, refer to xref:infrastructure-services/Services_and_Daemons.adoc#ch-Services_and_Daemons[Services and Daemons].
This will stop the service and start it again in quick succession. To only reload the configuration without stopping the service, run the following command instead:
To change the Net-SNMP Agent Daemon configuration, edit the `/etc/snmp/snmpd.conf` configuration file. The default `snmpd.conf` file shipped with {MAJOROSVER} is heavily commented and serves as a good starting point for agent configuration.
This section focuses on two common tasks: setting system information and configuring authentication. For more information about available configuration directives, refer to the *snmpd.conf*(5) manual page. Additionally, there is a utility in the [package]*net-snmp* package named [command]#snmpconf# which can be used to interactively generate a valid agent configuration.
Note that the [package]*net-snmp-utils* package must be installed in order to use the [command]#snmpwalk# utility described in this section.
.Applying the changes
[NOTE]
====
For any changes to the configuration file to take effect, force the `snmpd` service to re-read the configuration by running the following command as `root`:
Net-SNMP provides some rudimentary system information via the `system` tree. For example, the following [command]#snmpwalk# command shows the `system` tree with a default agent configuration.
----
~]# snmpwalk -v2c -c public localhost system
SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost.localdomain 2.6.32-122.el6.x86_64 #1 SMP Wed Mar 9 23:54:34 EST 2011 x86_64
By default, the `sysName` object is set to the hostname. The `sysLocation` and `sysContact` objects can be configured in the `/etc/snmp/snmpd.conf` file by changing the value of the [option]`syslocation` and [option]`syscontact` directives, for example:
[subs="quotes"]
----
syslocation Datacenter, Row 3, Rack 2
syscontact UNIX Admin <admin@example.com>
----
After making changes to the configuration file, reload the configuration and test it by running the [command]#snmpwalk# command again:
----
~]# systemct reload snmpd.service
~]# snmpwalk -v2c -c public localhost system
SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost.localdomain 2.6.32-122.el6.x86_64 #1 SMP Wed Mar 9 23:54:34 EST 2011 x86_64
The Net-SNMP Agent Daemon supports all three versions of the SNMP protocol. The first two versions (1 and 2c) provide for simple authentication using a _community string_. This string is a shared secret between the agent and any client utilities. The string is passed in clear text over the network however and is not considered secure. Version 3 of the SNMP protocol supports user authentication and message encryption using a variety of protocols. The Net-SNMP agent also supports tunneling over SSH, TLS authentication with X.509 certificates, and Kerberos authentication.
.Configuring SNMP Version 2c Community
To configure an *SNMP version 2c community*, use either the [option]`rocommunity` or [option]`rwcommunity` directive in the `/etc/snmp/snmpd.conf` configuration file. The format of the directives is the following:
… where _community_ is the community string to use, _source_ is an IP address or subnet, and _OID_ is the SNMP tree to provide access to. For example, the following directive provides read-only access to the `system` tree to a client using the community string "`redhat`" on the local machine:
To configure an *SNMP version 3 user*, use the [command]#net-snmp-create-v3-user# command. This command adds entries to the `/var/lib/net-snmp/snmpd.conf` and `/etc/snmp/snmpd.conf` files which create the user and grant access to the user. Note that the [command]#net-snmp-create-v3-user# command may only be run when the agent is not running. The following example creates the "`sysadmin`" user with the password "`redhatsnmp`":
[press return to reuse the authentication pass-phrase]
adding the following line to /var/lib/net-snmp/snmpd.conf:
createUser admin MD5 "redhatsnmp" DES
adding the following line to /etc/snmp/snmpd.conf:
rwuser admin
~]# systemctl start snmpd.service
----
The [option]`rwuser` directive (or [option]`rouser` when the [option]`-ro` command line option is supplied) that [command]#net-snmp-create-v3-user# adds to `/etc/snmp/snmpd.conf` has a similar format to the [option]`rwcommunity` and [option]`rocommunity` directives:
… where _user_ is a username and _OID_ is the SNMP tree to provide access to. By default, the Net-SNMP Agent Daemon allows only authenticated requests (the [option]`auth` option). The [option]`noauth` option allows you to permit unauthenticated requests, and the [option]`priv` option enforces the use of encryption. The [option]`authpriv` option specifies that requests must be authenticated and replies should be encrypted.
To test the configuration, create a `.snmp` directory in your user's home directory and a configuration file named `snmp.conf` in that directory (`~/.snmp/snmp.conf`) with the following lines:
[subs="quotes"]
----
defVersion 3
defSecurityLevel authPriv
defSecurityName admin
defPassphrase redhatsnmp
----
The [command]#snmpwalk# command will now use these authentication settings when querying the agent:
----
~]$ snmpwalk -v3 localhost system
SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost.localdomain 2.6.32-122.el6.x86_64 #1 SMP Wed Mar 9 23:54:34 EST 2011 x86_64
The Net-SNMP Agent in {MAJOROS} provides a wide variety of performance information over the SNMP protocol. In addition, the agent can be queried for a listing of the installed RPM packages on the system, a listing of currently running processes on the system, or the network configuration of the system.
This section provides an overview of OIDs related to performance tuning available over SNMP. It assumes that the [package]*net-snmp-utils* package is installed and that the user is granted access to the SNMP tree as described in xref:System_Monitoring_Tools.adoc#sect-System_Monitoring_Tools-Net-SNMP-Configuring-Authentication[Configuring Authentication].
The `Host Resources MIB` included with Net-SNMP presents information about the current hardware and software configuration of a host to a client utility. xref:System_Monitoring_Tools.adoc#tabl-System_Monitoring_Tools-Net-SNMP-OIDs[Available OIDs] summarizes the different OIDs available under that MIB.
|`HOST-RESOURCES-MIB::hrSystem`|Contains general system information such as uptime, number of users, and number of running processes.
|`HOST-RESOURCES-MIB::hrStorage`|Contains data on memory and file system usage.
|`HOST-RESOURCES-MIB::hrDevices`|Contains a listing of all processors, network devices, and file systems.
|`HOST-RESOURCES-MIB::hrSWRun`|Contains a listing of all running processes.
|`HOST-RESOURCES-MIB::hrSWRunPerf`|Contains memory and CPU statistics on the process table from HOST-RESOURCES-MIB::hrSWRun.
|`HOST-RESOURCES-MIB::hrSWInstalled`|Contains a listing of the RPM database.
|===
There are also a number of SNMP tables available in the Host Resources MIB which can be used to retrieve a summary of the available information. The following example displays `HOST-RESOURCES-MIB::hrFSTable`:
In particular, the `ssCpuRawUser`, `ssCpuRawSystem`, `ssCpuRawWait`, and `ssCpuRawIdle` OIDs provide counters which are helpful when determining whether a system is spending most of its processor time in kernel space, user space, or I/O. `ssRawSwapIn` and `ssRawSwapOut` can be helpful when determining whether a system is suffering from memory exhaustion.
More memory information is available under the `UCD-SNMP-MIB::memory` OID, which provides similar data to the [command]#free# command:
The `Host Resources MIB` provides information on file system size and usage. Each file system (and also each memory pool) has an entry in the `HOST-RESOURCES-MIB::hrStorageTable` table:
The OIDs under `HOST-RESOURCES-MIB::hrStorageSize` and `HOST-RESOURCES-MIB::hrStorageUsed` can be used to calculate the remaining capacity of each mounted file system.
I/O data is available both in `UCD-SNMP-MIB::systemStats` (`ssIORawSent.0` and `ssIORawRecieved.0`) and in `UCD-DISKIO-MIB::diskIOTable`. The latter provides much more granular data. Under this table are OIDs for `diskIONReadX` and `diskIONWrittenX`, which provide counters for the number of bytes read from and written to the block device in question since the system boot:
Information on network devices is provided by the Interfaces MIB. `IF-MIB::ifTable` provides an SNMP table with an entry for each interface on the system, the configuration of the interface, and various packet counters for the interface. The following example shows the first few columns of `ifTable` on a system with two physical network interfaces:
Index Descr Type Mtu Speed PhysAddress AdminStatus
1 lo softwareLoopback 16436 10000000 up
2 eth0 ethernetCsmacd 1500 0 52:54:0:c7:69:58 up
3 eth1 ethernetCsmacd 1500 0 52:54:0:a7:a3:24 down
----
Network traffic is available under the OIDs `IF-MIB::ifOutOctets` and `IF-MIB::ifInOctets`. The following SNMP queries will retrieve network traffic for each of the interfaces on this system:
The Net-SNMP Agent can be extended to provide application metrics in addition to raw system metrics. This allows for capacity planning as well as performance issue troubleshooting. For example, it may be helpful to know that an email system had a 5-minute load average of 15 while being tested, but it is more helpful to know that the email system has a load average of 15 while processing 80,000 messages a second. When application metrics are available via the same interface as the system metrics, this also allows for the visualization of the impact of different load scenarios on system performance (for example, each additional 10,000 messages increases the load average linearly until 100,000).
A number of the applications that ship with {MAJOROS} extend the Net-SNMP Agent to provide application metrics over SNMP. There are several ways to extend the agent for custom applications as well. This section describes extending the agent with shell scripts and Perl plug-ins. It assumes that the [package]*net-snmp-utils* and [package]*net-snmp-perl* packages are installed, and that the user is granted access to the SNMP tree as described in xref:System_Monitoring_Tools.adoc#sect-System_Monitoring_Tools-Net-SNMP-Configuring-Authentication[Configuring Authentication].
The Net-SNMP Agent provides an extension MIB (`NET-SNMP-EXTEND-MIB`) that can be used to query arbitrary shell scripts. To specify the shell script to run, use the [option]`extend` directive in the `/etc/snmp/snmpd.conf` file. Once defined, the Agent will provide the exit code and any output of the command over SNMP. The example below demonstrates this mechanism with a script which determines the number of `httpd` processes in the process table.
.Using the proc directive
[NOTE]
====
The Net-SNMP Agent also provides a built-in mechanism for checking the process table via the [option]`proc` directive. See the *snmpd.conf*(5) manual page for more information.
====
The exit code of the following shell script is the number of [command]#httpd# processes running on the system at a given point in time:
----
#!/bin/sh
NUMPIDS=`pgrep httpd | wc -l`
exit $NUMPIDS
----
To make this script available over SNMP, copy the script to a location on the system path, set the executable bit, and add an [option]`extend` directive to the `/etc/snmp/snmpd.conf` file. The format of the [option]`extend` directive is the following:
[subs="quotes, macros"]
----
[option]`extend` _name_ _prog_ _args_
----
… where _name_ is an identifying string for the extension, _prog_ is the program to run, and _args_ are the arguments to give the program. For instance, if the above shell script is copied to `/usr/local/bin/check_apache.sh`, the following directive will add the script to the SNMP tree:
Note that the exit code ("`8`" in this example) is provided as an INTEGER type and any output is provided as a STRING type. To expose multiple metrics as integers, supply different arguments to the script using the [option]`extend` directive. For example, the following shell script can be used to determine the number of processes matching an arbitrary string, and will also output a text string giving the number of processes:
The following `/etc/snmp/snmpd.conf` directives will give both the number of `httpd` PIDs as well as the number of `snmpd` PIDs when the above script is copied to `/usr/local/bin/check_proc.sh`:
NET-SNMP-EXTEND-MIB::nsExtendOutLine."httpd_pids".1 = STRING: There are 8 httpd processes.
NET-SNMP-EXTEND-MIB::nsExtendOutLine."snmpd_pids".1 = STRING: There are 1 snmpd processes.
----
.Integer exit codes are limited
[WARNING]
====
Integer exit codes are limited to a range of 0–255. For values that are likely to exceed 256, either use the standard output of the script (which will be typed as a string) or a different method of extending the agent.
====
This last example shows a query for the free memory of the system and the number of `httpd` processes. This query could be used during a performance test to determine the impact of the number of processes on memory pressure:
Executing shell scripts using the [option]`extend` directive is a fairly limited method for exposing custom application metrics over SNMP. The Net-SNMP Agent also provides an embedded Perl interface for exposing custom objects. The [package]*net-snmp-perl* package provides the `NetSNMP::agent` Perl module that is used to write embedded Perl plug-ins on {MAJOROS}.
The `NetSNMP::agent` Perl module provides an `agent` object which is used to handle requests for a part of the agent's OID tree. The `agent` object's constructor has options for running the agent as a sub-agent of `snmpd` or a standalone agent. No arguments are necessary to create an embedded agent:
[subs="quotes"]
----
use NetSNMP::agent (':all');
my $agent = new NetSNMP::agent();
----
The `agent` object has a `register` method which is used to register a callback function with a particular OID. The `register` function takes a name, OID, and pointer to the callback function. The following example will register a callback function named `hello_handler` with the SNMP Agent which will handle requests under the OID `.1.3.6.1.4.1.8072.9999.9999`:
The OID `.1.3.6.1.4.1.8072.9999.9999` (`NET-SNMP-MIB::netSnmpPlaypen`) is typically used for demonstration purposes only. If your organization does not already have a root OID, you can obtain one by contacting your Name Registration Authority (ANSI in the United States).
The handler function will be called with four parameters, `HANDLER`, `REGISTRATION_INFO`, `REQUEST_INFO`, and `REQUESTS`. The `REQUESTS` parameter contains a list of requests in the current call and should be iterated over and populated with data. The `request` objects in the list have get and set methods which allow for manipulating the `OID` and `value` of the request. For example, the following call will set the value of a request object to the string "`hello world`":
The handler function should respond to two types of SNMP requests: the GET request and the GETNEXT request. The type of request is determined by calling the `getMode` method on the `request_info` object passed as the third parameter to the handler function. If the request is a GET request, the caller will expect the handler to set the `value` of the `request` object, depending on the OID of the request. If the request is a GETNEXT request, the caller will also expect the handler to set the OID of the request to the next available OID in the tree. This is illustrated in the following code example:
When `getMode` returns `MODE_GET`, the handler analyzes the value of the `getOID` call on the `request` object. The `value` of the `request` is set to either `string_value` if the OID ends in "`.1.0`", or set to `integer_value` if the OID ends in "`.1.1`". If the `getMode` returns `MODE_GETNEXT`, the handler determines whether the OID of the request is "`.1.0`", and then sets the OID and value for "`.1.1`". If the request is higher on the tree than "`.1.0`", the OID and value for "`.1.0`" is set. This in effect returns the "`next`" value in the tree so that a program like [command]#snmpwalk# can traverse the tree without prior knowledge of the structure.
The type of the variable is set using constants from `NetSNMP::ASN`. See the [command]#perldoc# for `NetSNMP::ASN` for a full list of available constants.
The entire code listing for this example Perl plug-in is as follows:
----
#!/usr/bin/perl
use NetSNMP::agent (':all');
use NetSNMP::ASN qw(ASN_OCTET_STR ASN_INTEGER);
sub hello_handler {
my ($handler, $registration_info, $request_info, $requests) = @_;
To test the plug-in, copy the above program to `/usr/share/snmp/hello_world.pl` and add the following line to the `/etc/snmp/snmpd.conf` configuration file:
----
perl do "/usr/share/snmp/hello_world.pl"
----
The SNMP Agent Daemon will need to be restarted to load the new Perl plug-in. Once it has been restarted, an [command]#snmpwalk# should return the new data: