使用 jmeter 插件的 Nagios 测试失败并出现 CRITICAL: ... java.util.prefs.FileSystemPreferences$1 运行

Nagios test with jmeter plugin failed with CRITICAL: ... java.util.prefs.FileSystemPreferences$1 run

该问题已在全新安装和升级的 Lubuntu 20.04 和 5.4.0-42 通用内核、Nagios 4.4.6、Java 1.8.0_265、Jmeter 5.3 上重现。

手动运行此插件时:

user@ubuntu:~$ /usr/bin/perl /usr/local/nagios/libexec/jmeter.pl -j=/usr/local/nagios/share/jmeter -p=/usr/local/nagios/libexec/test.jmx -t 80 -w 90 -c 100
OK :  | sum_time=26.91
user@ubuntu:~$ echo $#
0

一旦我通过 运行 使用 sudo 获得与上面屏幕截图相同的结果,但无法再次重现它:

$ sudo /usr/bin/perl /usr/local/nagios/libexec/jmeter.pl -j=/usr/local/nagios/share/jmeter -p=/usr/local/nagios/libexec/test.jmx -t 80 -w 90 -c 100
[sudo] password for user: 
CRITICAL: 'java -server  -jar /usr/local/nagios/share/jmeter/bin/ApacheJMeter.jar --nongui --propfile /usr/local/nagios/share/jmeter/bin/jmeter.properties --testfile /usr/local/nagios/libexec/test.jmx --logfile /tmp/1597861570.41537.jtl' exit with wait status of 0 Errors Aug 19, 2020 9:26:21 PM java.util.prefs.FileSystemPreferences run

INFO: Created user preferences directory.

为了获得更详细的输出,我在 nagios.cfg 文件 (debug_level=-1):

中启用了调试
[1597866795.863118] [001.0] [pid=44433] handle_async_service_check_result()
[1597866795.863907] [016.0] [pid=44433] ** Handling ACTIVE async check result for service 'Test production jmeter test' on host 'test.company.com' from 'Core Worker 44437'... current state 2 last_hard_state 2 
[1597866795.864002] [016.1] [pid=44433]  * OPTIONS: 0, SCHEDULED: 1, RESCHEDULE: 1, EXITED OK: 1, RETURN CODE: 2, OUTPUT:
CRITICAL: 'java -server  -jar /usr/local/nagios/share/jmeter/bin/ApacheJMeter.jar --nongui --propfile /usr/local/nagios/share/jmeter/bin/jmeter.properties --testfile /usr/local/nagios/libexec/test.jmx --logfile /tmp/1597866748.44494.jtl' exit with wait status of 0 Errors Aug 19, 2020 10:52:34 PM java.util.prefs.FileSystemPreferences run

WARNING: Couldn't create user preferences directory. User preferences are unusable.

Aug 19, 2020 10:52:34 PM java.util.prefs.FileSystemPreferences run

WARNING: java.io.IOException: No such file or directory

Aug 19, 2020 10:53:06 PM java.util.prefs.FileSystemPreferences checkLockFile0ErrorCode

WARNING: Could not lock User prefs.  Unix error code 2.

Aug 19, 2020 10:53:06 PM java.util.prefs.FileSystemPreferences syncWorld

WARNING: Couldn't flush user prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.


[1597866795.864097] [001.0] [pid=44433] get_service_check_return_code()
[1597866795.864135] [016.1] [pid=44433] Service is in a non-OK state!
[1597866795.864262] [016.1] [pid=44433] Host is currently UP, so we'll recheck its state to make sure...
[1597866795.864337] [016.1] [pid=44433] Service was NOT OK at last check (CRITICAL).
[1597866795.864374] [016.1] [pid=44433] Service is still in a non-OK state (CRITICAL)!

谷歌搜索

WARNING: Could not lock User prefs.  Unix error code 2

我通过查看调试日志文件 (sudo tail -F /usr/local/nagios/var/nagios.debug) 得到的,我发现我需要创建 /home/nagios 文件夹:

$ sudo mkdir /home/nagios
$ sudo chmod nagios:nagios /home/nagios

在此之后,在 nagios 服务处理的情况下创建了下一个文件夹:

root@ubuntu:/home/nagios/.java# ls -ailh
total 0
100900054 drwxr-xr-x 4 nagios nagios 44 сер 19 23:23 .
 67258544 drwxr-xr-x 3 nagios nagios 87 сер 19 23:24 ..
 67261722 drwxr-xr-x 2 root   root   52 сер 19 23:23 .systemPrefs
   109430 drwx------ 3 nagios nagios 73 сер 19 23:23 .userPrefs

nagios 开始显示 OK 状态:

Reference