Skip to content

JVM process monitoring on Windows

Monitoring Java Virtual Machine (JVM) processes on Windows can be achieved using command-line tools like jps, jcmd, and jinfo, or integrated into a monitoring system like Zabbix via PowerShell scripts^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

Native Command Line Tools

The Java Development Kit (JDK) provides several utilities for monitoring and managing JVM processes locally^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

jcmd

The jcmd utility is a versatile tool used to send diagnostic command requests to running Java processes^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

  • List Processes: To list all JVM processes on the local machine, use the -l flag^[600-developer-operation-maintenance-zabbix-zabbix-key.md].
  • Process Details: You can query specific details, such as the command line used to start the JVM, by targeting the Process ID (PID)^[600-developer-operation-maintenance-zabbix-zabbix-key.md].
    jcmd <pid> VM.command_line
    
  • Help: Available commands vary by JVM. Running jcmd <pid> help displays the specific diagnostics available for that process (e.g., GC.heap_dump, Thread.print, VM.flags)^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

jinfo

The jinfo command generates configuration and system property information for a specific Java process^[600-developer-operation-maintenance-zabbix-zabbix-key.md]. This is useful for inspecting the Java System Properties and VM Flags (such as heap size settings) active at runtime^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

jps

The jps tool lists the instrumented Java HotSpot Virtual Machines on the target system^[600-developer-operation-maintenance-zabbix-zabbix-key.md]. Combined with PowerShell, jps -lm can be used to filter and identify specific Java applications by their main class or arguments^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

Monitoring with Zabbix and PowerShell

To automate monitoring, Zabbix can be configured to run PowerShell scripts on Windows agents^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

Prerequisites

  • Execution Policy: PowerShell scripts may fail if the system's execution policy restricts them. This can be resolved by running Set-ExecutionPolicy RemoteSigned with administrator privileges^[600-developer-operation-maintenance-zabbix-zabbix-key.md].
  • Agent Configuration: The Zabbix Agent configuration file (zabbix_agentd.conf) must be updated to allow custom parameters and remote commands^[600-developer-operation-maintenance-zabbix-zabbix-key.md]:
    • UnsafeUserParameters=1: Allows passing complex arguments to user-defined parameters.
    • EnableRemoteCommands=1: Allows the Zabbix server to trigger scripts on the client.
    • Timeout: May need to be increased if scripts take time to execute (e.g., checking multiple JVMs)^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

UserParameter Implementation

A UserParameter is defined in the configuration file to map a specific key to a PowerShell script^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

UserParameter=mypay.robot[*],C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\Zabbix\robot.ps1 $1 $2 $3 $4 $5 $6 $7 $8 $9

PowerShell Logic

The PowerShell script typically iterates through running Java processes to verify if specific applications or paths are active^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

  1. Retrieving PIDs: Use Get-Process -Name java | select -expand id to get the IDs of all Java processes^[600-developer-operation-maintenance-zabbix-zabbix-key.md].
  2. Querying Properties: For each PID, use jinfo to retrieve the process arguments or configuration string^[600-developer-operation-maintenance-zabbix-zabbix-key.md].
  3. Pattern Matching: Parse the output to check for specific identifiers (e.g., a main class name like com.zonpay.robot.base.MyPayRobot or a path like robot1047)^[600-developer-operation-maintenance-zabbix-zabbix-key.md].
  4. Output: Return a status code (e.g., 1 for found, 0 for not found, or a count) to Zabbix^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

Example logic snippet:

$mark = 0
Get-Process -Name java | select -expand id | ForEach {
    $queryCondition = jinfo $_
    $isExist = $queryCondition.split(' ') | Select-String -include string "robot1047" -CaseSensitive 
    if ($isExist.length -gt 0) {
        $mark += 1
    }
}
echo $mark

  • [[Zabbix]]
  • [[PowerShell]]
  • [[JVM]]

Sources

^[600-developer-operation-maintenance-zabbix-zabbix-key.md]