IBM Support

IBM AIX: TCP Connection Monitoring and Analysis Using sockmon

How To


Summary

sockmon is a TCP connection monitoring tool for AIX systems to provide real-time analysis of TCP socket states, process management capabilities, and comprehensive network health monitoring. It allows system administrators, and individuals involved in network troubleshooting and performance analysis to assess TCP connection states, identify processes with problematic connections, and manage network resources effectively.

Objective

  • Download and install sockmon
  • Configure TCP state monitoring
  • Run sockmon in interactive and daemon modes
  • Analyze TCP connection states and process relationships
  • Export monitoring data for analysis
  • Manage processes with problematic TCP connections

Environment

  • AIX 7.1 or later
  • Required libraries: libperfstat, curses
  • Root or appropriate system privileges recommended

Steps

DISCLAIMER

This program is provided AS-IS with no warranty or support by IBM.

SOCKMON is a tool designed to assist application development teams in debugging socket state issues within their applications. This tool focuses on application-level network behavior analysis rather than operating system diagnostics. Socket state issues typically stem from application logic within the code itself - such as improper socket lifecycle management, premature closures, or inadequate cleanup of duplicated file descriptors. These programming-level concerns require code review and application modifications that fall outside the scope of IBM AIX support.

Download SOCKMON from HERE

Installing SOCKMON

Follow these steps to install and configure SOCKMON on your AIX system:

  1. Verify file integrity before installation:

    $ csum -h MD5 sockmon
                6889feda929f03e42d3fc5e3d30f1d6a  sockmon
                $ sum sockmon
                36845   150 sockmon
  2. Make the program executable:

    $ chmod 755 sockmon
  3. Optionally, copy to system path:

    $ cp sockmon /usr/sbin/

Command Reference

Complete Command Help

Use ./sockmon --help or ./sockmon -h to display comprehensive usage information:

AIX SOCKMON - Enhanced TCP State Process Monitor v1.0
        ======================================================
        DESCRIPTION:
          Advanced TCP connection monitoring tool for AIX systems
          Supports interactive interface, daemon mode, and comprehensive reporting
        USAGE:
          sockmon [OPTIONS]
        OPTIONS:
          -i                     Interactive mode
          -d                     Run as background daemon
          -states <list>         Comma-separated list of TCP states to monitor
                                 (overrides saved configuration)
          --list-states          Show all available TCP states and exit
          -r <seconds>           Refresh interval for interactive mode (default: 5)
          -dr <seconds>          Daemon report interval (default: 60)
          -v                     Verbose output
          -debug                 Enable debug mode
          -cpu <percent>         CPU usage threshold for alerts
          -mem <kb>              Memory usage threshold for alerts
          -conn <count>          Connection count threshold for alerts
          -h, --help             Show this help message
        TCP STATES:
          Available states for monitoring:
            CLOSE_WAIT   - Waiting for connection termination
            TIME_WAIT    - Waiting for enough time to pass
            FIN_WAIT_1   - Waiting for termination request
            FIN_WAIT_2   - Waiting for termination request
            SYN_SENT     - Waiting for matching connection request
            SYN_RCVD     - Waiting for confirming connection request
            ESTABLISHED  - Connection established
            LISTEN       - Listening for incoming connections
            CLOSING      - Closing connection
            LAST_ACK     - Waiting for final ACK
        INTERACTIVE MODE KEYS:
          1-5             Switch between views (Health/Processes/Tree/States/ProcessMgmt)
          q               Quit application
          e               Export current view to timestamped file
          r               Force refresh
          s               Save configuration (in States view)
          UP/DOWN         Navigate in configuration and management modes
          SPACE           Toggle selections
          k               Kill selected processes
          a               Select all processes for termination
        DAEMON MODE CONFIGURATION:
          Method 1 - Command Line (Recommended):
            Use -states flag to specify TCP states directly
            Example: sockmon -d -states CLOSE_WAIT,FIN_WAIT_1,SYN_SENT
          Method 2 - Interactive Configuration:
            1. Run interactive mode: sockmon -i
            2. Press '4' to enter States view
            3. Use SPACE to toggle states, 's' to save
            4. Run daemon mode: sockmon -d
          Configuration file: /tmp/sockmon_daemon_config.dat
        EXAMPLES:
          sockmon -i                                    # Interactive mode
          sockmon -d -states CLOSE_WAIT                 # Daemon monitoring CLOSE_WAIT only
          sockmon -d -states CLOSE_WAIT,FIN_WAIT_1      # Daemon monitoring multiple states
          sockmon -d -dr 300 -states TIME_WAIT          # Daemon with 5-min reports
          sockmon --list-states                         # Show available states
          sockmon -i -r 2 -cpu 80                       # Interactive, 2s refresh, 80% CPU alert
        Compatible with AIX 7.1+
        ======================================================
        Author: Mustafa Atallah - mustafa.atallah@ibm.com
        Created: 2025/07/15 - Version: 1.0
        This program is provided AS-IS with no warranty or support by IBM.

Detailed Flag Descriptions

Mode Selection Flags

  • -i: Launches the interactive interface with real-time monitoring and five different views. Use this for hands-on troubleshooting and process management.
  • -d: Runs SOCKMON as a background daemon process that generates periodic reports. Ideal for continuous monitoring without user interaction.

Configuration Flags

  • -states <list>: Specifies which TCP states to monitor as a comma-separated list (e.g., CLOSE_WAIT,FIN_WAIT_1). This overrides any saved configuration and is the recommended way to configure daemon mode.
  • --list-states: Displays all available TCP states with descriptions and exits. Use this to see what states you can monitor before configuring SOCKMON.

Timing Control Flags

  • -r <seconds>: Sets the refresh interval for interactive mode (default: 5 seconds). Lower values provide more frequent updates but use more CPU. Minimum value is 1 second.
  • -dr <seconds>: Sets the report generation interval for daemon mode (default: 60 seconds). Typical values range from 60-1800 seconds depending on monitoring needs.

Alert Threshold Flags

  • -cpu <percent>: Sets CPU usage threshold for generating alerts in reports. Processes exceeding this percentage will be highlighted in daemon reports and exports.
  • -mem <kb>: Sets memory usage threshold in kilobytes for generating alerts. Processes using more memory than this value will be flagged in reports.
  • -conn <count>: Sets connection count threshold for generating alerts. Processes with more connections than this value will be highlighted as potentially problematic.

Diagnostic Flags

  • -v: Enables verbose output mode, providing detailed information about SOCKMON's operations. Useful for understanding what the tool is doing and verifying configuration.
  • -debug: Enables debug mode with extensive diagnostic output. Use this when troubleshooting SOCKMON itself or when connections aren't appearing as expected.
  • -h, --help: Displays the complete help message with usage examples and exits. Always available for quick reference.

Flag Combination Guidelines

  • Interactive Mode: Combine -i with -r for custom refresh rates and threshold flags for alert highlighting
  • Daemon Mode: Always use -d with -states to specify monitoring focus, optionally add -dr for custom reporting intervals
  • Troubleshooting: Add -v or -debug to any combination when investigating issues
  • Production Monitoring: Use -d -states -dr combination with appropriate threshold flags for automated monitoring

Basic Usage

Interactive Mode

Interactive mode provides a real-time interface for monitoring TCP connections:

# ./sockmon -i

Interactive Mode Navigation

  • Keys 1-5: Switch between views
  • q: Quit application
  • e: Export current view to file
  • r: Force refresh
  • UP/DOWN: Navigate in configuration modes
  • SPACE: Toggle selections
  • k: Kill selected processes
  • s: Save configuration (in States view)

Daemon Mode - Automated Monitoring

For continuous monitoring and automated reporting, use daemon mode:

# ./sockmon -d -states CLOSE_WAIT,FIN_WAIT_1,TIME_WAIT

Typical daemon mode configurations:

Monitor CLOSE_WAIT connections (most common issue)
# ./sockmon -d -states CLOSE_WAIT
Monitor multiple problematic states with 5-minute reports
# ./sockmon -d -states CLOSE_WAIT,FIN_WAIT_1,SYN_SENT -dr 300
Verbose daemon mode for debugging
# ./sockmon -d -states TIME_WAIT -v

Configuration Management

Method 1 - Command Line (Recommended)

Use the -states parameter to specify TCP states directly:

# ./sockmon -d -states CLOSE_WAIT,FIN_WAIT_1,SYN_SENT

Method 2 - Interactive Configuration

  1. Run interactive mode: ./sockmon -i
  2. Press '4' to enter States configuration view
  3. Use SPACE to toggle desired states
  4. Press 's' to save configuration
  5. Run daemon mode: ./sockmon -d

Available TCP States for Monitoring

# ./sockmon --list-states
        CLOSE_WAIT   - Waiting for connection termination (most critical)
        TIME_WAIT    - Waiting for enough time to pass
        FIN_WAIT_1   - Waiting for termination request
        FIN_WAIT_2   - Waiting for termination request  
        SYN_SENT     - Waiting for matching connection request
        SYN_RCVD     - Waiting for confirming connection request
        ESTABLISHED  - Connection established
        LISTEN       - Listening for incoming connections
        CLOSING      - Closing connection
        LAST_ACK     - Waiting for final ACK

SOCKMON Interface Views

AIX SOCKMON provides five specialized views to analyze TCP connection issues from different perspectives. Each view focuses on specific aspects of network monitoring to help administrators quickly identify and resolve connection problems.

  1. Health Dashboard: System-wide network health overview with TCP state summaries and resource utilization metrics
  2. Process View: Links TCP connections to specific processes, showing which applications are responsible for problematic connection states
  3. Tree View: Displays process hierarchies and their network usage, useful for understanding parent-child process relationships
  4. State Configuration: Allows customization of which TCP states to monitor based on your specific environment needs
  5. Process Management: Enables termination of processes that are creating problematic connections

Health Dashboard (View 1)

The Health Dashboard serves as your primary system overview, displaying comprehensive network health metrics and TCP connection state summaries.

health-dashboard

Key Features

  • TCP Connection States Summary: Real-time counts of all TCP connection states including ESTABLISHED, TIME_WAIT, CLOSE_WAIT, FIN_WAIT states, SYN states, LISTEN, CLOSING, and LAST_ACK
  • System Resource Integration: CPU usage, memory utilization, and load averages correlated with network activity
  • Network Statistics: Packet throughput, byte counts, and error rates for comprehensive network health assessment
  • Alert Indicators: Automatic highlighting of problematic metrics such as excessive TIME_WAIT or CLOSE_WAIT connections

When to Use Health Dashboard

  • Starting point for any network troubleshooting investigation
  • Quick assessment of overall system network health
  • Identifying which TCP states are consuming resources
  • Correlating network issues with system resource usage

Navigation: Press '1' to access Health Dashboard view

=== SYSTEM HEALTH DASHBOARD ===
            TCP Connection States:
              ESTABLISHED: 45
              TIME_WAIT: 234    (MODERATE)
              CLOSE_WAIT: 12    (HIGH!)
              FIN_WAIT_1: 5
              FIN_WAIT_2: 8
              SYN_SENT: 2
              SYN_RCVD: 1
              LISTEN: 18
              CLOSING: 0
              LAST_ACK: 3
            System Resources:
              CPU Usage: 35.2%
              Memory Usage: 2048576 KB
              Load Average: 1.45
            Network Statistics:
              Packets In: 145628, Out: 98456
              Bytes In: 89562374, Out: 45236891
              Network Errors: 12
 

Process View (View 2)

The Process View provides detailed information about each process that has connections in monitored TCP states, linking network behavior directly to specific applications.

process-view

Key Features

  • Process Identification: PID, process name, and full command line for each application
  • Connection Details: Total connection count and unique connection count per process
  • Resource Usage: CPU percentage, memory usage, and I/O statistics integrated with connection data
  • TCP State Summary: Which specific TCP states each process currently has connections in
  • User Information: Which user account is running each process

When to Use Process View

  • Identifying which applications are creating problematic connections
  • Investigating connection leaks or excessive connection usage
  • Correlating application behavior with network resource consumption
  • Finding processes that need optimization or termination

Navigation: Press '2' to access Process view

=== PROCESSES WITH MONITORED TCP STATES ===
            PID      PROCESS          CONNS  CPU%    MEM(KB)   MEM%   I/O(R/W)    USER     STATES
            ----------------------------------------------------------------------------------------
            1234     httpd            25     12.5    102400    5.2    1024/2048   apache   ESTABLISHED,CLOSE_WAIT
            5678     database         8      45.2    524288    15.8   5120/8192   db2inst  CLOSE_WAIT
            9101     java_app         15     8.1     256000    8.4    2048/1024   webapp   FIN_WAIT_1,TIME_WAIT
            2345     sshd             3      0.5     8192      0.2    512/256     root     ESTABLISHED

Process Details Integration: Each process entry includes comprehensive socket information showing local and remote addresses, connection states, and queue sizes for detailed troubleshooting.

Tree View (View 3)

The Tree View displays processes in a hierarchical structure, showing parent-child relationships and how network usage propagates through process families.

process-tree-view

Key Features

  • Hierarchical Display: Parent processes with their child processes indented below
  • Inherited Behavior Analysis: Understanding how parent processes spawn children that inherit network behavior
  • Family Resource Tracking: Combined resource usage for process families
  • Root Process Identification: Clear identification of top-level processes that start process chains

When to Use Tree View

  • Understanding complex application architectures with multiple processes
  • Identifying whether connection issues come from parent or child processes
  • Analyzing web servers, application servers, or database systems with worker processes
  • Planning process termination strategies that account for dependencies

Navigation: Press '3' to access Tree view

=== PROCESS TREE VIEW ===
            PID      PROCESS          PPID     CONNS  CPU%    MEM(KB)   USER     STATES
            --------------------------------------------------------------------------------
            1234     httpd            1        5      2.1     51200     apache   LISTEN
              -->2456 httpd           1234     8      12.3    40960     apache   ESTABLISHED,CLOSE_WAIT
              -->2457 httpd           1234     12     15.8    45056     apache   ESTABLISHED,TIME_WAIT
              -->2458 httpd           1234     6      8.4     38912     apache   CLOSE_WAIT
            5678     java             1        2      5.2     102400    webapp   ESTABLISHED  
              -->6789 java            5678     25     45.8    256000    webapp   CLOSE_WAIT,FIN_WAIT_1
 

State Configuration (View 4)

The State Configuration View allows you to customize which TCP connection states SOCKMON monitors, focusing your analysis on states most relevant to your environment.

state-management

Available TCP States for Configuration

  • CLOSE_WAIT - Waiting for connection termination (often indicates connection leaks)
  • TIME_WAIT - Waiting for enough time to pass (high counts suggest rapid cycling)
  • FIN_WAIT_1 - Waiting for termination request (accumulation suggests poor cleanup)
  • FIN_WAIT_2 - Waiting for termination request (accumulation suggests poor cleanup)
  • SYN_SENT - Waiting for matching connection request (connectivity issues)
  • SYN_RCVD - Waiting for confirming connection request (connectivity issues)
  • ESTABLISHED - Connection established (normal operations)
  • LISTEN - Listening for incoming connections (server processes)
  • CLOSING - Closing connection (rare transitional state)
  • LAST_ACK - Waiting for final ACK (final cleanup stage)

Configuration Actions

  • UP/DOWN arrows: Navigate through available states
  • SPACE: Toggle state monitoring on/off
  • s: Save configuration for daemon mode persistence
  • ENTER: Apply current configuration

Best Practices for State Selection

  • Enable CLOSE_WAIT for detecting connection leak issues
  • Enable FIN_WAIT states for applications with poor connection cleanup
  • Enable SYN states for connectivity troubleshooting
  • Disable ESTABLISHED for performance unless investigating active connection issues

Navigation: Press '4' to access State Configuration

=== TCP STATE CONFIGURATION ===
            (Use SPACE to toggle, UP/DOWN to navigate, ENTER to apply)
            > [X] CLOSE_WAIT - Waiting for connection termination
              [ ] TIME_WAIT - Waiting for enough time to pass  
              [ ] FIN_WAIT_1 - Waiting for termination request
              [ ] FIN_WAIT_2 - Waiting for termination request
              [X] SYN_SENT - Waiting for matching connection request
              [ ] SYN_RCVD - Waiting for confirming connection request
              [ ] ESTABLISHED - Connection established
              [ ] LISTEN - Listening for incoming connections
              [ ] CLOSING - Closing connection
              [ ] LAST_ACK - Waiting for final ACK
            Currently monitoring 2 TCP states
            Press 's' to save configuration for daemon mode
 

Process Management (View 5)

The Process Management View provides capabilities to terminate processes that are creating problematic network connections, with built-in safety mechanisms.

process-management

Key Features

  • Process Selection: Mark individual processes or select all processes for termination
  • Safety Confirmations: Multiple confirmation steps prevent accidental termination
  • Batch Operations: Handle multiple problematic processes simultaneously
  • Status Tracking: Visual indicators show which processes are marked for termination
  • Process Protection: Built-in protection against terminating critical system processes

Management Actions

  • UP/DOWN arrows: Navigate through process list
  • SPACE: Mark/unmark process for termination
  • k: Kill selected processes (with confirmations)
  • a: Select all processes for termination
  • ESC: Cancel termination process

Termination Process

  1. Selection Phase: Mark processes using SPACE key
  2. First Confirmation: Press 'y' to confirm intent to terminate
  3. Final Confirmation: Press 'Y' (uppercase) for final confirmation
  4. Execution: SOCKMON attempts graceful termination (SIGTERM) first, then forced termination (SIGKILL) if necessary
Safety Features
  • Protection against terminating processes with PID ≤ 10
  • Warning when attempting to terminate critical processes
  • Multiple confirmation steps with clear warnings
  • Graceful termination attempt before forced kill

Navigation: Press '5' to access Process Management

=== PROCESS MANAGEMENT ===
            (Use SPACE to mark, UP/DOWN to navigate, 'k' to kill selected, 'a' to kill all)
            PID      PROCESS          CONNS  CPU%    STATUS      USER
            ----------------------------------------------------------------
            > 1234   httpd            25     12.5    [MARKED]    apache
              5678   database         8      45.2    Active      db2inst  
              9101   java_app         15     8.1     Active      webapp
              2345   sshd             3      0.5     Active      root
            Marked for termination: 1 processes
            WARNING: You are about to terminate 1 process(es)!
            This action cannot be undone!
            Press 'y' to confirm, any other key to cancel
 

Troubleshooting Common Issues

High CLOSE_WAIT Count

Issue: Applications are not properly closing TCP connections

  • Use sockmon to identify specific processes: ./sockmon -i -states CLOSE_WAIT
  • Review application connection handling code
  • Consider process restart if connections are stuck

High TIME_WAIT Count

Analysis: Normal behavior but excessive counts may indicate rapid connection cycling

  • Monitor with: ./sockmon -d -states TIME_WAIT -dr 300
  • Consider tuning TCP parameters if consistently high

Process Management Workflow

  1. Enter Process Management view (key '5' in interactive mode)
  2. Use SPACE to mark processes for termination
  3. Press 'k' to kill selected processes
  4. Confirm termination when prompted

Export and Analysis

  • Press 'e' in any interactive view to export data
  • Export files saved to /tmp/sockmon_export_TIMESTAMP.txt
  • Use exported data for trend analysis and capacity planning

Advanced Usage Examples

Monitor specific thresholds with alerts

# ./sockmon -i -cpu 80 -mem 1048576 -conn 100

Debug mode for troubleshooting

# ./sockmon -i -debug

Daemon with custom report intervals

# ./sockmon -d -states CLOSE_WAIT -dr 1800 -v

Quick health check

# ./sockmon -d -states CLOSE_WAIT,TIME_WAIT -dr 60

Configuration and Performance

Configuration Files

  • Daemon Configuration: /tmp/sockmon_daemon_config.dat
  • Daemon PID File: /tmp/sockmon_daemon.pid
  • Export Files: /tmp/sockmon_export_TIMESTAMP.txt
  • Daemon Reports: /tmp/sockmon_daemon_report_TIMESTAMP.txt

Performance Impact

SOCKMON is designed for minimal system impact:

  • Uses efficient libperfstat APIs for system metrics
  • Caches CPU statistics to reduce overhead
  • Optimized parsing of network connection data
  • Interactive mode: ~1-2% CPU usage
  • Daemon mode: <0.5% CPU usage

Best Practices and Recommendations

Monitoring Strategy

  1. Start with CLOSE_WAIT monitoring for most environments
  2. Use daemon mode for continuous monitoring
  3. Export data regularly for trend analysis
  4. Monitor TIME_WAIT in high-traffic environments
  5. Use process management features carefully - always verify before termination
  6. Configure appropriate report intervals (60-300 seconds typical)
  7. Review daemon reports regularly for performance insights

Based on monitoring results, administrators can:

  • Identify applications with poor connection management
  • Detect network resource leaks before they impact performance
  • Plan capacity requirements based on connection patterns
  • Troubleshoot network-related performance issues
  • Implement proactive process management strategies
 

Additional Information

SUPPORT

If you require more assistance, use the following step-by-step instructions to contact IBM to open a case for software with an active and valid support contract.  

1. Document (or collect screen captures of) all symptoms, errors, and messages related to your issue.

2. Capture any logs or data relevant to the situation.

3. Contact IBM to open a case:

   -For electronic support, see the IBM Support Community:
     https://www.ibm.com/mysupport
   -If you require telephone support, see the web page:
      https://www.ibm.com/planetwide/

4. Provide a clear, concise description of the issue.

 - For more information, see: Working with IBM AIX Support: Describing the problem.

5. If the system is accessible, collect a system snap, and upload all of the details and data for your case.

 - For more information, see: Working with IBM AIX Support: Collecting snap data

 
Click here to submit feedback for this document.
 
Author:
Mustafa Atallah

Document Location

Worldwide

[{"Type":"MASTER","Line of Business":{"code":"LOB08","label":"Cognitive Systems"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG10","label":"AIX"},"ARM Category":[{"code":"a8m0z000000cvzIAAQ","label":"Networking"}],"ARM Case Number":"","Platform":[{"code":"PF002","label":"AIX"}],"Version":"7.1.0;7.2.0;7.3.0"}]

Document Information

Modified date:
12 September 2025

UID

ibm17241023