<?xml version="1.0" encoding="utf-8" standalone="yes"?><feed xmlns="http://www.w3.org/2005/Atom">
  <title></title>
  <subtitle></subtitle>
  <id>https://www.endpointdev.com/blog/tags/nagios/</id>
  <link href="https://www.endpointdev.com/blog/tags/nagios/"/>
  <link href="https://www.endpointdev.com/blog/tags/nagios/" rel="self"/>
  <updated>2025-03-22T00:00:00+00:00</updated>
  <author>
    <name>End Point Dev</name>
  </author>
  
    <entry>
      <title>Getting Output from jps with NRPE</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2025/03/monitoring-java-based-process-with-jps-and-nrpe/"/>
      <id>https://www.endpointdev.com/blog/2025/03/monitoring-java-based-process-with-jps-and-nrpe/</id>
      <published>2025-03-22T00:00:00+00:00</published>
      <author>
        <name>Muhammad Najmi bin Ahmad Zabidi</name>
      </author>
      <content type="html">
        &lt;p&gt;&lt;img src=&#34;/blog/2025/03/monitoring-java-based-process-with-jps-and-nrpe/green-river.webp&#34; alt=&#34;A mellow river winds across the image, with verdant trees reaching over the water.&#34;&gt;&lt;/p&gt;
&lt;!-- Photo by Seth Jensen, 2024. --&gt;
&lt;p&gt;One of the tools our hosting team uses for server and site monitoring is Icinga (which is based on Nagios). When monitoring host resources, one of the tools we use is Nagios Remote Plugin Executor or NRPE.&lt;/p&gt;
&lt;p&gt;We encountered an issue when executing NRPE: though NRPE runs on the server being monitored, it wasn&amp;rsquo;t giving the same output as a script which was executed on the server itself. The NRPE-related call should have no issues be executed on the target server, as it is declared in the sudoers file (commonly /etc/sudoers). In this post, I will explain how to get the output from jps (Java Virtual Machine Process Status Tool), which can only be executed as root.&lt;/p&gt;
&lt;h3 id=&#34;getting-process-information-with-jps&#34;&gt;Getting process information with jps&lt;/h3&gt;
&lt;p&gt;Let’s say we have a &amp;ldquo;hello world&amp;rdquo; program named Hello.java. How do we get the process&amp;rsquo;s state from Icinga&amp;rsquo;s head server?&lt;/p&gt;
&lt;p&gt;First, let&amp;rsquo;s compile and run the program.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt;&lt;span style=&#34;color:#bbb&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#b06;font-weight:bold&#34;&gt;Hello&lt;/span&gt;&lt;span style=&#34;color:#bbb&#34;&gt; &lt;/span&gt;{&lt;span style=&#34;color:#bbb&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#bbb&#34;&gt;    &lt;/span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;public&lt;/span&gt;&lt;span style=&#34;color:#bbb&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;static&lt;/span&gt;&lt;span style=&#34;color:#bbb&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#888;font-weight:bold&#34;&gt;void&lt;/span&gt;&lt;span style=&#34;color:#bbb&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;main&lt;/span&gt;(String[]&lt;span style=&#34;color:#bbb&#34;&gt; &lt;/span&gt;args)&lt;span style=&#34;color:#bbb&#34;&gt; &lt;/span&gt;{&lt;span style=&#34;color:#bbb&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#bbb&#34;&gt;        &lt;/span&gt;System.&lt;span style=&#34;color:#369&#34;&gt;out&lt;/span&gt;.&lt;span style=&#34;color:#369&#34;&gt;println&lt;/span&gt;(&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;Hello, World!&amp;#34;&lt;/span&gt;);&lt;span style=&#34;color:#bbb&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#bbb&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#bbb&#34;&gt;        &lt;/span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;try&lt;/span&gt;&lt;span style=&#34;color:#bbb&#34;&gt; &lt;/span&gt;{&lt;span style=&#34;color:#bbb&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#bbb&#34;&gt;            &lt;/span&gt;Thread.&lt;span style=&#34;color:#369&#34;&gt;sleep&lt;/span&gt;(3000);&lt;span style=&#34;color:#bbb&#34;&gt;  &lt;/span&gt;&lt;span style=&#34;color:#888&#34;&gt;// Sleep for 3 seconds&lt;/span&gt;&lt;span style=&#34;color:#bbb&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#bbb&#34;&gt;        &lt;/span&gt;}&lt;span style=&#34;color:#bbb&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;catch&lt;/span&gt;&lt;span style=&#34;color:#bbb&#34;&gt; &lt;/span&gt;(InterruptedException&lt;span style=&#34;color:#bbb&#34;&gt; &lt;/span&gt;e)&lt;span style=&#34;color:#bbb&#34;&gt; &lt;/span&gt;{&lt;span style=&#34;color:#bbb&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#bbb&#34;&gt;            &lt;/span&gt;e.&lt;span style=&#34;color:#369&#34;&gt;printStackTrace&lt;/span&gt;();&lt;span style=&#34;color:#bbb&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#bbb&#34;&gt;        &lt;/span&gt;}&lt;span style=&#34;color:#bbb&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#bbb&#34;&gt;    &lt;/span&gt;}&lt;span style=&#34;color:#bbb&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#bbb&#34;&gt;&lt;/span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-plain&#34; data-lang=&#34;plain&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;java Hello.java
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Hello, World!&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The program will run until it times out.&lt;/p&gt;
&lt;p&gt;First, let&amp;rsquo;s check the process by running &lt;code&gt;ps&lt;/code&gt; on the server:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-plain&#34; data-lang=&#34;plain&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;# ps aux | grep Hello.java | grep -v grep
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;najmi      61609 16.7  0.3 11541184 109360 pts/5 Sl+  01:19   0:00 java Hello.java&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We can also get the process ID with jps. Here&amp;rsquo;s the output from the &amp;ldquo;najmi&amp;rdquo; user view:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-plain&#34; data-lang=&#34;plain&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;# sudo -s -u najmi jps -l
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;61609 jdk.compiler/com.sun.tools.javac.launcher.SourceLauncher
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;61695 jdk.jcmd/sun.tools.jps.Jps&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And from the &amp;ldquo;root&amp;rdquo; user view:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-plain&#34; data-lang=&#34;plain&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;# whoami
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;root
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;# jps -l
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;61609 jdk.compiler/com.sun.tools.javac.launcher.SourceLauncher
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;61852 jdk.jcmd/sun.tools.jps.Jps
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;# ps aux | grep Hello.java | grep -v grep
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;najmi      61609  1.2  0.3 11541184 109360 pts/5 Sl+  01:19   0:01 java Hello.java&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;However, the &amp;ldquo;nrpe&amp;rdquo; user does not see it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-plain&#34; data-lang=&#34;plain&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;# sudo -s -u nrpe jps -l
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;61790 jdk.jcmd/sun.tools.jps.Jps&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Instead of running the &lt;code&gt;jps&lt;/code&gt; command directly as Nagios, we will let the system run jps as root and dump the results into a file. An NRPE-based script will later read the output and feed the result to the dashboard.&lt;/p&gt;
&lt;h3 id=&#34;running-jps-as-root-with-output-to-a-file&#34;&gt;Running jps as root, with output to a file&lt;/h3&gt;
&lt;p&gt;For this example, I started the &lt;code&gt;jetty&lt;/code&gt; process with sudo.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-plain&#34; data-lang=&#34;plain&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;sudo /usr/share/jetty/bin/jetty.sh start&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now let&amp;rsquo;s check whether the &amp;ldquo;jetty&amp;rdquo; service is running or not.&lt;/p&gt;
&lt;p&gt;First we&amp;rsquo;ll check the status as a non-root user. It sees the process as &amp;ldquo;not running&amp;rdquo;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-plain&#34; data-lang=&#34;plain&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ /usr/share/jetty/bin/jetty.sh status
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;** WARNING: JETTY_LOGS is Deprecated. Please configure logging within the jetty base.
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Jetty NOT running
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JAVA                  =  /usr/bin/java
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JAVA_OPTIONS          =
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_HOME            =  /usr/share/jetty
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_BASE            =  /usr/share/jetty
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;START_D               =  /usr/share/jetty/start.d
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;START_INI             =  /usr/share/jetty/start.ini
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_START           =  /usr/share/jetty/start.jar
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_CONF            =  /usr/share/jetty/etc/jetty.conf
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_ARGS            =  jetty.state=/run/jetty/jetty.state jetty.pid=/run/jetty/jetty.pid --module=pid,state
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_RUN             =  /run/jetty
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_PID             =  /run/jetty/jetty.pid
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_START_LOG       =  /run/jetty/jetty-start.log
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_STATE           =  /run/jetty/jetty.state
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_START_TIMEOUT   =  60
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_SYS_PROPS       =
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;RUN_ARGS              =  -Djava.io.tmpdir=/tmp -Djetty.home=/usr/share/jetty -Djetty.base=/usr/share/jetty --class-path /etc/jetty/resources:/usr/share/jetty/lib/logging/slf4j-api-2.0.16.jar:/usr/share/jetty/lib/logging/jetty-slf4j-impl-12.0.16.jar:/usr/share/jetty/lib/jetty-http-12.0.16.jar:/usr/share/jetty/lib/jetty-server-12.0.16.jar:/usr/share/jetty/lib/jetty-xml-12.0.16.jar:/usr/share/jetty/lib/jetty-util-12.0.16.jar:/usr/share/jetty/lib/jetty-io-12.0.16.jar org.eclipse.jetty.xml.XmlConfiguration java.version=23.0.1 jetty.base=/usr/share/jetty jetty.base.uri=file:///usr/share/jetty jetty.home=/usr/share/jetty jetty.home.uri=file:///usr/share/jetty jetty.pid=/run/jetty/jetty.pid jetty.state=/run/jetty/jetty.state jetty.webapp.addHiddenClasses=org.eclipse.jetty.logging.,file:///usr/share/jetty/lib/logging/,org.slf4j. runtime.feature.alpn=true slf4j.version=2.0.16 /etc/jetty/jetty-bytebufferpool.xml /etc/jetty/jetty-pid.xml /etc/jetty/jetty-threadpool.xml /etc/jetty/jetty.xml /etc/jetty/jetty-state.xml
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ID                    =  uid=1000(user) gid=1000(user) groups=1000(user),90(network),98(power),984(users),987(storage),991(lp),994(input),996(audio),998(wheel)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_USER            =  jetty
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;USE_START_STOP_DAEMON =  0
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;START_STOP_DAEMON     =  0&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now, let&amp;rsquo;s check the status of the jetty service with &lt;code&gt;sudo&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-plain&#34; data-lang=&#34;plain&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ sudo /usr/share/jetty/bin/jetty.sh status
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;** WARNING: JETTY_LOGS is Deprecated. Please configure logging within the jetty base.
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Jetty running pid=89969
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JAVA                  =  /usr/bin/java
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JAVA_OPTIONS          =
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_HOME            =  /usr/share/jetty
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_BASE            =  /usr/share/jetty
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;START_D               =  /usr/share/jetty/start.d
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;START_INI             =  /usr/share/jetty/start.ini
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_START           =  /usr/share/jetty/start.jar
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_CONF            =  /usr/share/jetty/etc/jetty.conf
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_ARGS            =  jetty.state=/run/jetty/jetty.state jetty.pid=/run/jetty/jetty.pid --module=pid,state
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_RUN             =  /run/jetty
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_PID             =  /run/jetty/jetty.pid
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_START_LOG       =  /run/jetty/jetty-start.log
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_STATE           =  /run/jetty/jetty.state
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_START_TIMEOUT   =  60
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_SYS_PROPS       =
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;RUN_ARGS              =  -Djava.io.tmpdir=/tmp -Djetty.home=/usr/share/jetty -Djetty.base=/usr/share/jetty --class-path /etc/jetty/resources:/usr/share/jetty/lib/logging/slf4j-api-2.0.16.jar:/usr/share/jetty/lib/logging/jetty-slf4j-impl-12.0.16.jar:/usr/share/jetty/lib/jetty-http-12.0.16.jar:/usr/share/jetty/lib/jetty-server-12.0.16.jar:/usr/share/jetty/lib/jetty-xml-12.0.16.jar:/usr/share/jetty/lib/jetty-util-12.0.16.jar:/usr/share/jetty/lib/jetty-io-12.0.16.jar org.eclipse.jetty.xml.XmlConfiguration java.version=23.0.1 jetty.base=/usr/share/jetty jetty.base.uri=file:///usr/share/jetty jetty.home=/usr/share/jetty jetty.home.uri=file:///usr/share/jetty jetty.pid=/run/jetty/jetty.pid jetty.state=/run/jetty/jetty.state jetty.webapp.addHiddenClasses=org.eclipse.jetty.logging.,file:///usr/share/jetty/lib/logging/,org.slf4j. runtime.feature.alpn=true slf4j.version=2.0.16 /etc/jetty/jetty-bytebufferpool.xml /etc/jetty/jetty-pid.xml /etc/jetty/jetty-threadpool.xml /etc/jetty/jetty.xml /etc/jetty/jetty-state.xml
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ID                    =  uid=0(root) gid=0(root) groups=0(root)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;JETTY_USER            =  jetty
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;USE_START_STOP_DAEMON =  0
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;START_STOP_DAEMON     =  0&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Then, check that it&amp;rsquo;s running with jps as root, and note that the nrpe user still can&amp;rsquo;t see the process using jps:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-plain&#34; data-lang=&#34;plain&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ sudo /usr/share/jetty/bin/jetty.sh status 2&amp;gt;/dev/null | grep &amp;#34;running pid&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Jetty running pid=89969
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ sudo jps -l
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;89969 org.eclipse.jetty.xml.XmlConfiguration
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;91635 jdk.jcmd/sun.tools.jps.Jps
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ sudo -s -u nrpe jps -l
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;91711 jdk.jcmd/sun.tools.jps.Jps&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We can decide whether to use the &amp;ldquo;jetty&amp;rdquo; service script as the process check tool, or whether to use jps. For this post, we&amp;rsquo;ll focus on &lt;code&gt;jps&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We can run jps as root in a Bash script to dump the Java process ID into a temporary file. We can then use this script as an NRPE script.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#c00;font-weight:bold&#34;&gt;#!/bin/bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#c00;font-weight:bold&#34;&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# Check if program name was provided&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; [ -z &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#369&#34;&gt;$1&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&lt;/span&gt; ]; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#038&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;UNKNOWN: Please specify a program name to check&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#038&#34;&gt;exit&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;fi&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;TEMP_FILE&lt;/span&gt;=&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;/tmp/java_pid.txt&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# Clear the temp file first&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&amp;gt; &lt;span style=&#34;color:#369&#34;&gt;$TEMP_FILE&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# Run jps and save output to temp file&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;jps -l &amp;gt; &lt;span style=&#34;color:#369&#34;&gt;$TEMP_FILE&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# Check if program is in the temp file&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; grep -q &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#369&#34;&gt;$1&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#369&#34;&gt;$TEMP_FILE&lt;/span&gt;; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#369&#34;&gt;PID&lt;/span&gt;=&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;$(&lt;/span&gt;grep &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#369&#34;&gt;$1&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#369&#34;&gt;$TEMP_FILE&lt;/span&gt; | awk &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#39;{print $1}&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#038&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;OK - &lt;/span&gt;&lt;span style=&#34;color:#369&#34;&gt;$1&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt; is running with PID &lt;/span&gt;&lt;span style=&#34;color:#369&#34;&gt;$PID&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#038&#34;&gt;exit&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;else&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#038&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;CRITICAL - &lt;/span&gt;&lt;span style=&#34;color:#369&#34;&gt;$1&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt; is down&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#038&#34;&gt;exit&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;fi&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Most of time, using &lt;code&gt;ps&lt;/code&gt; or &lt;code&gt;pgrep&lt;/code&gt; will be adequate to check for running processes. This post just shows how to get the output from jps, when you need to use jps. As for checking the status of the &lt;code&gt;jetty&lt;/code&gt; service, &lt;code&gt;/usr/share/jetty/bin/jetty.sh status&lt;/code&gt; might be fine as well, but the process of filtering, parsing, and feeding the output to the NRPE plugin should be pretty much the same.&lt;/p&gt;
&lt;p&gt;There could be another way to solve this issue, which I am not be aware of. The method I shared above is just one way to get jps’s report working with NRPE. Please let me know if you have experience with jps and Icinga/​Nagios, and how you handle their reporting.&lt;/p&gt;
&lt;h3 id=&#34;related-reading&#34;&gt;Related reading&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://opensource.com/article/21/10/check-java-jps&#34;&gt;https://opensource.com/article/21/10/check-java-jps&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://docs.oracle.com/javase/7/docs/technotes/tools/share/jps.html&#34;&gt;https://docs.oracle.com/javase/7/docs/technotes/tools/share/jps.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

      </content>
    </entry>
  
    <entry>
      <title>Fetching Outputs From Java Process Monitoring Tool with Icinga/​Nagios</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2021/06/getting-inputs-from-jps-in-nagios-icinga/"/>
      <id>https://www.endpointdev.com/blog/2021/06/getting-inputs-from-jps-in-nagios-icinga/</id>
      <published>2021-06-07T00:00:00+00:00</published>
      <author>
        <name>Muhammad Najmi bin Ahmad Zabidi</name>
      </author>
      <content type="html">
        &lt;p&gt;&lt;img src=&#34;/blog/2021/06/getting-inputs-from-jps-in-nagios-icinga/banner.jpg&#34; alt=&#34;&#34;&gt;
Photo by &lt;a href=&#34;https://unsplash.com/@mlupascu&#34;&gt;Mihai Lupascu&lt;/a&gt; on &lt;a href=&#34;https://unsplash.com/photos/epLSTrZ9aOE&#34;&gt;Unsplash&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Recently, I encountered an issue when executing &lt;a href=&#34;https://exchange.nagios.org/directory/Addons/Monitoring-Agents/NRPE--2D-Nagios-Remote-Plugin-Executor/details&#34;&gt;NRPE&lt;/a&gt;, a Nagios agent which runs on servers that are being monitored from Icinga’s head server. Usually NRPE-related calls should run without issues on the target server, since it is declared in the sudoers file (commonly &lt;code&gt;/etc/sudoers&lt;/code&gt;). In this post, I will cover an issue I encountered getting the output from &lt;a href=&#34;https://docs.oracle.com/javase/7/docs/technotes/tools/share/jps.html&#34;&gt;jps&lt;/a&gt; (Java Virtual Machine Process Status Tool), which needed to be executed with root privileges.&lt;/p&gt;
&lt;h3 id=&#34;method&#34;&gt;Method&lt;/h3&gt;
&lt;p&gt;I wanted to use &lt;a href=&#34;https://icinga.com/&#34;&gt;Icinga&lt;/a&gt; to get a Java process’s state (in this case, the process is named “Lucene”) from Icinga’s head server, remotely. &lt;code&gt;jps&lt;/code&gt; works for this, functioning similarly to the &lt;code&gt;ps&lt;/code&gt; command on Unix-like systems.&lt;/p&gt;
&lt;p&gt;Usually, NRPE should be able to execute the remote process (on the target server) from Icinga’s head. In this case we are going to create a workaround through the following steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Dump the Java process ID into a text file.&lt;/li&gt;
&lt;li&gt;Dump the running threads into another text file.&lt;/li&gt;
&lt;li&gt;Put &lt;strong&gt;item 1&lt;/strong&gt; and &lt;strong&gt;item 2&lt;/strong&gt; above into a single bash script.&lt;/li&gt;
&lt;li&gt;Create a cronjob to automatically run the bash script.&lt;/li&gt;
&lt;li&gt;Create an NRPE plugin to evaluate the output of &lt;strong&gt;item 1&lt;/strong&gt; and &lt;strong&gt;item 2&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;test&#34;&gt;Test&lt;/h3&gt;
&lt;p&gt;To illustrate this, I ran the intended command locally on the target server as the nagios user. Theoretically, this should emulate the NRPE call as if it was executed from Icinga’s server remotely. The file &lt;code&gt;check_lucene_indexing_deprecated&lt;/code&gt; was meant to demonstrate the NRPE execution failure, whereas &lt;code&gt;check_lucene_indexing&lt;/code&gt; is the file which is expected to run the NRPE plugin successfully. The paths to both &lt;code&gt;check_lucene_indexing_deprecated&lt;/code&gt; and &lt;code&gt;check_lucene_indexing&lt;/code&gt; were already declared in &lt;code&gt;/etc/sudoers&lt;/code&gt; file on the target machine.&lt;/p&gt;
&lt;p&gt;To show the differences, I ran two different scripts from the Icinga’s head server.&lt;/p&gt;
&lt;p&gt;Here is the output from both local script executions: first as the nagios user, then as the root user:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# sudo -s -u nagios ./check_lucene_indexing_deprecated&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;CRITICAL -- Lucene indexing down
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# sudo -s -u root  ./check_lucene_indexing_deprecated&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;OK -- &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt; Lucene threads running&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;As you can see, the script worked fine running as root, but not as the nagios user.&lt;/p&gt;
&lt;p&gt;Let’s run the scripts from Icinga’s head server:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# /usr/lib64/nagios/plugins/check_nrpe -t 5 -H &amp;lt;the target server’s FQDN&amp;gt; -c  check_lucene_indexing_dep&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;CRITICAL -- Lucene indexing down (&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt; found)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# /usr/lib64/nagios/plugins/check_nrpe -t 5 -H  &amp;lt;the target server’s FQDN&amp;gt; -c  check_lucene_indexing&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;OK -- &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt; Lucene threads running&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In the background, we can see different output from running &lt;code&gt;jps&lt;/code&gt; on the target server using the root user compared to the nagios user. Let’s say I want to check the &lt;code&gt;jps&lt;/code&gt; process ID (PID):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# sudo -s -u nagios jps -l&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;29112&lt;/span&gt; sun.tools.jps.Jps&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And as root:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# jps -l&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;7541&lt;/span&gt; /usr/share/jetty9/start.jar
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;29131&lt;/span&gt; sun.tools.jps.Jps&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The point of running the &lt;code&gt;jps -l&lt;/code&gt; command is to get the process ID of &lt;code&gt;/usr/share/jetty9/start.jar&lt;/code&gt;, which is 7541. However, as indicated above, the nagios user’s execution did not display the intended result, but the root user’s did.&lt;/p&gt;
&lt;h3 id=&#34;the-workaround&#34;&gt;The workaround&lt;/h3&gt;
&lt;p&gt;We can check the existence of the process ID by dumping it into a text file and letting the NRPE plugin read it instead.&lt;/p&gt;
&lt;p&gt;In order to get NRPE to fetch the current state of the process, we will create a cronjob; in our case it will be executed every 10 minutes. This script will dump the PID of the Java process into a text file and later NRPE will run another script which will analyze the contents of the text file.&lt;/p&gt;
&lt;h4 id=&#34;cronjob-creating-dump-files&#34;&gt;Cronjob, creating dump files&lt;/h4&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;*/10 * * * * /root/bin/fetch_lucene_pid.sh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The cron script contains the following details:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;PID_TARGET&lt;/span&gt;=/var/run/nrpe-lucene.pid
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;THREADS_TARGET&lt;/span&gt;=/var/run/nrpe-lucene-thread.txt
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;/usr/bin/jps -l | grep &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;start.jar&amp;#34;&lt;/span&gt; | cut -d&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#39; &amp;#39;&lt;/span&gt; -f1 1&amp;gt;&lt;span style=&#34;color:#369&#34;&gt;$PID_TARGET&lt;/span&gt; 2&amp;gt;/dev/null
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;PID&lt;/span&gt;=&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;$(&lt;/span&gt;cat &lt;span style=&#34;color:#369&#34;&gt;$PID_TARGET&lt;/span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;re&lt;/span&gt;=&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#39;^[0-9]+$&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt;  [[ -z &lt;span style=&#34;color:#369&#34;&gt;$PID&lt;/span&gt; ]]  || ! [[ &lt;span style=&#34;color:#369&#34;&gt;$PID&lt;/span&gt; =~ &lt;span style=&#34;color:#369&#34;&gt;$re&lt;/span&gt; ]]  ; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#038&#34;&gt;exit&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;fi&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;THREADS&lt;/span&gt;=&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;$(&lt;/span&gt;/usr/bin/jstack &lt;span style=&#34;color:#369&#34;&gt;$PID&lt;/span&gt; | grep -A &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;ProjectIndexer\|ConsultantIndexer&amp;#34;&lt;/span&gt; | grep -c &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;java.lang.Thread.State: WAITING (parking)&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#038&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#369&#34;&gt;$THREADS&lt;/span&gt; &amp;gt; &lt;span style=&#34;color:#369&#34;&gt;$THREADS_TARGET&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;So instead of running the &lt;code&gt;jps&lt;/code&gt; command directly as nagios, we let the system run &lt;code&gt;jps&lt;/code&gt; (as root) and dump the result into a file. Our NRPE-based script will read the output later and feed the result to the dashboard.&lt;/p&gt;
&lt;h4 id=&#34;nrpe-plugin-file-reading-values-generated-from-the-cronjob&#34;&gt;NRPE plugin file, reading values generated from the cronjob&lt;/h4&gt;
&lt;p&gt;So we will take a look at what was written in the successfully executed Bash script (that is, &lt;code&gt;check_lucene_indexing&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;The NRPE plugin file, &lt;code&gt;check_lucene_indexing&lt;/code&gt;, contains the following script:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#c00;font-weight:bold&#34;&gt;#!/bin/bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#c00;font-weight:bold&#34;&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;PID_TARGET&lt;/span&gt;=/var/run/nrpe-lucene.pid
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;THREADS_TARGET&lt;/span&gt;=/var/run/nrpe-lucene-thread.txt
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;PID&lt;/span&gt;=&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;$(&lt;/span&gt;cat &lt;span style=&#34;color:#369&#34;&gt;$PID_TARGET&lt;/span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;THREADS&lt;/span&gt;=&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;$(&lt;/span&gt;cat &lt;span style=&#34;color:#369&#34;&gt;$THREADS_TARGET&lt;/span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;re&lt;/span&gt;=&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#39;^[0-9]+$&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt;  [[ -z &lt;span style=&#34;color:#369&#34;&gt;$PID&lt;/span&gt; ]]  || ! [[ &lt;span style=&#34;color:#369&#34;&gt;$PID&lt;/span&gt; =~ &lt;span style=&#34;color:#369&#34;&gt;$re&lt;/span&gt; ]]  ; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#038&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;CRITICAL -- Lucene indexing down (a)&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#038&#34;&gt;exit&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;fi&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; [ &lt;span style=&#34;color:#369&#34;&gt;$THREADS&lt;/span&gt; -eq &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt; ]
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#038&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;OK -- &lt;/span&gt;&lt;span style=&#34;color:#369&#34;&gt;$THREADS&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt; Lucene threads running&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#038&#34;&gt;exit&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;else&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#038&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;CRITICAL -- Lucene indexing down (b)&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#038&#34;&gt;exit&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;fi&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;From the NRPE plugin script you can see the following text files being used:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;PID_TARGET&lt;/span&gt;=/var/run/nrpe-lucene.pid
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;THREADS_TARGET&lt;/span&gt;=/var/run/nrpe-lucene-thread.txt&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;PID_TARGET&lt;/code&gt; contains the process’s PID, which I used to determine whether the intended process is running or not.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;THREADS_TARGET&lt;/code&gt; contains the number of the Java threads which are currently running.&lt;/p&gt;
&lt;p&gt;The following is the content of the &lt;code&gt;check_lucene_indexing_deprecated&lt;/code&gt; script:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#c00;font-weight:bold&#34;&gt;#!/bin/bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#c00;font-weight:bold&#34;&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;PID&lt;/span&gt;=&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;$(&lt;/span&gt;/usr/bin/jps -l | grep &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;start.jar&amp;#34;&lt;/span&gt; | cut -d&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#39; &amp;#39;&lt;/span&gt; -f1&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; [[ -z &lt;span style=&#34;color:#369&#34;&gt;$PID&lt;/span&gt; ]]; &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#038&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;CRITICAL -- Lucene indexing down&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#038&#34;&gt;exit&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;fi&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#369&#34;&gt;THREADS&lt;/span&gt;=&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;$(&lt;/span&gt;/usr/bin/jstack &lt;span style=&#34;color:#369&#34;&gt;$PID&lt;/span&gt; | grep -A &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;ProjectIndexer\|ConsultantIndexer&amp;#34;&lt;/span&gt; | grep -c &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;java.lang.Thread.State: WAITING (parking)&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;if&lt;/span&gt; [ &lt;span style=&#34;color:#369&#34;&gt;$THREADS&lt;/span&gt; -eq &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt; ]
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#038&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;OK -- &lt;/span&gt;&lt;span style=&#34;color:#369&#34;&gt;$THREADS&lt;/span&gt;&lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt; Lucene threads running&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#038&#34;&gt;exit&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;else&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#038&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#d20;background-color:#fff0f0&#34;&gt;&amp;#34;CRITICAL -- Lucene indexing down&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#038&#34;&gt;exit&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;fi&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;As you can see, &lt;code&gt;check_lucene_deprecated&lt;/code&gt; was able to get the result &lt;em&gt;if&lt;/em&gt; it is being executed locally on the target machine - but not from the remote (Icinga’s head server). This is because &lt;code&gt;jps&lt;/code&gt; will provide limited results when executed as the nagios compared to the local root user. Note that I have defined the path of the script in the sudoers file prior to the script execution.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-plain&#34; data-lang=&#34;plain&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Defaults: nagios !requiretty
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;nagios  ALL = NOPASSWD: /usr/local/lib/nagios/plugins/check_lucene_indexing
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;nagios  ALL = NOPASSWD: /usr/local/lib/nagios/plugins/check_lucene_indexing_deprecated&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;The method which I shared above is just one of the ways to use jps reports with Icinga/​Nagios plugins. As of now this solution works as expected. If you want to reuse the scripts, please customize them according to your environment to get the results you want. Also, as written in the &lt;a href=&#34;https://docs.oracle.com/javase/7/docs/technotes/tools/share/jps.html&#34;&gt;documentation&lt;/a&gt;, getting the output by parsing the output from jps means we need to update the script any time jps changes its output format.&lt;/p&gt;
&lt;p&gt;Please comment below if you have experience with jps and Icinga/​Nagios, and tell us how you handle the reporting.&lt;/p&gt;
&lt;p&gt;Related reading:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://developpaper.com/java-jps-commands-under-linux-are-parsed-in-detail/&#34;&gt;Java JPS commands under Linux are parsed in detail&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://docs.oracle.com/javase/7/docs/technotes/tools/share/jps.html&#34;&gt;jps - Java Virtual Machine Process Status Tool&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

      </content>
    </entry>
  
    <entry>
      <title>Streaming Replication time lag monitoring added to check_postgres</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2015/08/streaming-replication-time-lag/"/>
      <id>https://www.endpointdev.com/blog/2015/08/streaming-replication-time-lag/</id>
      <published>2015-08-10T00:00:00+00:00</published>
      <author>
        <name>Josh Williams</name>
      </author>
      <content type="html">
        &lt;p&gt;&lt;a href=&#34;https://www.flickr.com/photos/56278705@N05/8548635299/in/photolist-e2pZrM-5uDPns-71jap-5rbtCP-bua9Dn-p3KzAA-aJh7uD-7bgsx6-nvBRCq-4B2ng3-aSheyH-vADsy-kHby-9pZZVn-fMrcKa-p2egJ5-AnRMU-EXrr-eTYP7U-5ayMi6-sn5ecN-kCFz-bXANVG-46YU7g-gxoMCB-qGxWFt-dY3Cyx-68giiZ-wJ7e7-6SkM1-JZ3a6-a6otTh-9c9xPc-pHcHM2-wQNQD-oUrYYB-bR6BR8-qoAwB6-LzGU1-cjZBEJ-c5WzkQ-4JYvg5-ewJe9D-gVtTRu-U3oT-4gtg8Q-cjFWdQ-7brR3P-7bvDHy-9bTMZN/&#34; title=&#34;Clocks at Great Northern in Manchester, UK&#34;&gt;&lt;img alt=&#34;Clocks at Great Northern in Manchester, UK&#34; height=&#34;240&#34; src=&#34;/blog/2015/08/streaming-replication-time-lag/image-0.jpeg&#34; width=&#34;195&#34;/&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I almost let this one sneak past! Guess I need to do some lag monitoring on myself. About a month or so ago, a new version of &lt;a href=&#34;https://bucardo.org/wiki/Check_postgres&#34;&gt;check_postgres&lt;/a&gt; was released, and that includes a bit of code I wrote. While the patch has been available in the git checkout for a while, now that it’s in the official release and will start appearing in repos (if it hasn’t already) it’s probably worth writing up a quick note describing its reasoning and usage.&lt;/p&gt;
&lt;p&gt;What’s the feature? &lt;a href=&#34;https://github.com/bucardo/check_postgres/commit/6b765c839eaf80499f68d412a897f61f11db9bfc&#34;&gt;Time-based replication monitoring in the hot_standby_delay action.&lt;/a&gt; This was something that had been a long-standing item on my personal TODO list, and happened to scratch the itch of a couple of clients at the time.&lt;/p&gt;
&lt;p&gt;Previously it would only take an integer representing how many bytes of WAL data the master could be ahead of a replica before the threshold is crossed:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;check_hot_standby_delay --dbhost=master,replica1 --critical=16777594&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This is certainly useful for, say, keeping an eye on whether you’re getting close to running over your wal_keep_segments value. Of course it can also be used to indicate whether the replica is still processing WAL, or has become stuck for some reason. But for the (arguably more common) problem of determining whether a replica is falling too far behind determining what byte thresholds to use, beyond simply guessing, isn’t easy to figure out.&lt;/p&gt;
&lt;p&gt;Postgres 9.1 introduced a handy function to help solve this problem: pg_last_xact_replay_timestamp(). It measures a slightly different thing than the pg_last_xlog_* functions the action previously used. And it’s for that reason that the action now has a more complex format for its thresholds:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;check_hot_standby_delay --dbhost=master,replica1 --critical=&amp;#34;16777594 and 5 min&amp;#34;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;For backward compatibility, of course, it’ll still take an integer and work the same as it did before. Or alternatively if you only want to watch the chronological lag, you could even give it just a time interval, “5 min”, and the threshold only takes the transaction replay timestamp into account. But if you specify both, as above, then both conditions must be met before the threshold activates.&lt;/p&gt;
&lt;p&gt;Why? Well, that gets in to bit about the measurement of slightly different things. As its name implies, pg_last_xact_replay_timestamp() returns the timestamp of the last transaction it received and replayed. That’s fine if you have a database cluster that’s constantly active 24 hours a day. But not all of them are. Some have fluctuating periods of activity, perhaps busy during the business day and nearly idle during the night. In other words, if the master isn’t processing any transactions, that last transaction timestamp doesn’t change.&lt;/p&gt;
&lt;p&gt;Then there’s the other end of the scale. With the SSD’s/high speed disk arrays a master server may in a short interval process more transaction data than it can send over a network wire. For example, we have a system that runs an ETL process between two local databases on a master server, and generates a ton of transaction log data in a short amount of time. However even if it has many megabytes of WAL data to transmit, the replicas never get any more than a handful of seconds behind and soon catch up.&lt;/p&gt;
&lt;p&gt;Both conditions on their own are fine. It’s when both conditions are simultaneously met, when the replica is behind in both transaction log and it hasn’t seen a chronologically recent transaction, that’s when you know something is going wrong with your replication connection.&lt;/p&gt;
&lt;p&gt;Naturally, this updated check also includes the chronological lag metric, so you can feed that into Graphite, or some other system of choice. Just make sure you’re system handles the new metric; our Nagios system seemed to ignore it until the RRD data for the check was cleared and recreated.&lt;/p&gt;
&lt;p&gt;Oh, and make sure your clocks are in sync. The timestamp check executes only on the replica, so any difference between its clock and the master’s can show up as skew here. ntpd is an easy way to keep everything mostly synchronized, but if you really want to be sure, check_postgres also has a timesync action.&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>Monitorama, Berlin, EU - Day 2 and final considerations</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2013/09/monitorama-berlin-eu-day-2-and-final/"/>
      <id>https://www.endpointdev.com/blog/2013/09/monitorama-berlin-eu-day-2-and-final/</id>
      <published>2013-09-20T00:00:00+00:00</published>
      <author>
        <name>Emanuele “Lele” Calò</name>
      </author>
      <content type="html">
        &lt;p&gt;Moving toward the end of IT conferences your expectations sometime gets lower cause the speakers are tired and so are the attendees. You kind of expect things to get quieter but this wasn’t the case with Monitorama EU 2013.&lt;/p&gt;
&lt;p&gt;On this second day I found that all of the talks were as interesting, entertaining and inspiring as the ones on the first day.&lt;/p&gt;
&lt;p&gt;I enjoyed all the talks proposed today but I got very inspired by the ones from Jeff Weinstein which talked about how you can use data collected for metrics and monitoring to improve the whole company. I also appreciated the speech from Gareth Rushgrove which highlighted how security is actually still underrated in IT companies and how/why you should try to integrate monitoring with security auditing tools.&lt;/p&gt;
&lt;p&gt;I’ve been asked a few times, during the day and the evening, which was my opinion about the conference and the answer was always “absolutely positive!”. I always add that though I don’t expect to see any rocket science in these conferences I kind of suppose that I’ll get a lot of hints, ideas and tips which are a wonderful trampoline for new personal or work-related projects. That is exactly what I got.&lt;/p&gt;
&lt;p&gt;The other aspect you unexpectedly get in this kind of technical conferences is an incredibly positive social experience with plenty of information exchanged both on a personal and technical perspective. I always over-stress this aspect because sometimes people go to conferences, listen to the talks, learn something and go home unsatisfied. That’s mostly because they missed the point.&lt;/p&gt;
&lt;p&gt;If you want to learn new stuff you have a marvellous thing called Internet with GitHub, SlideShare and many useful books out there. What you’ll always miss from all this sources is the “human factor” which you only get when you hang out with other people that share interests with you. Who are willing to share their knowledge with you (hint: open source communities) and in general are there to enjoy staying together, just for a few days, with other weird humans which share their same passion: their IT work.&lt;/p&gt;
&lt;p&gt;So in the end my impressions are very positive, and I’d like to thank all the guys behind the conference organization to have it run as good as it did. I’m sure I’ll join you again, hopefully soon.&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>Monitorama, Berlin, EU - Day 1 </title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2013/09/monitorama-berlin-eu-day-1/"/>
      <id>https://www.endpointdev.com/blog/2013/09/monitorama-berlin-eu-day-1/</id>
      <published>2013-09-19T00:00:00+00:00</published>
      <author>
        <name>Emanuele “Lele” Calò</name>
      </author>
      <content type="html">
        &lt;p&gt;If you care about the quality of your IT infrastructure and work, there are times where you really need to focus on a valuable and important aspect: &lt;strong&gt;community&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The thing is that most people don’t realize how valuable the &lt;em&gt;human factor&lt;/em&gt; is when working in the IT field, until they happen to be in such a marvellous conference as &lt;a href=&#34;https://monitorama.eu&#34;&gt;Monitorama&lt;/a&gt; has been so far.&lt;/p&gt;
&lt;p&gt;I was lucky enough to be there, in Berlin from 2013.09.19 to 2013.09.20, to enjoy all the awesome talks and attendees which was present there. And what I’m really saying that besides most of the speeches were quite technically interesting and definitely good quality ones, they definitely didn’t only revolves about monitoring per se.&lt;/p&gt;
&lt;p&gt;I won’t mention each and every talk, though they all would have deserved it, but I’ll say that while I was very inspired by Danese Copper’s talk about Open Source value and importance,  I was also very entertained Ryan Dotsmith’s one about how you could/should learn from failures, either yours or others ones, or the very specific “on the field” one from Katherine Daniels.&lt;/p&gt;
&lt;p&gt;On top of that while I generally don’t appreciate sponsors having “talks” during this kind of conferences, I actually appreciated how they managed to handle the sponsor advertising part of the conference where you have this little, brief demos from the sponsors which are fairly related and never boring or out of context as I have experienced at other conferences.&lt;/p&gt;
&lt;p&gt;A few things I actually got from all talks is that future of monitoring will definitely be all about &lt;em&gt;machine learning&lt;/em&gt; and having computers mimic the way human interprets data. We just have to teach computers how to do this kind interpretive tasks as good as we do. It all revolves around this and only then we could all stop saying “You know computers are dumb, you just have to cope with it”.&lt;/p&gt;
&lt;p&gt;One last thing which needs to be told about this awesome conference and needs to be mentioned is the awesome location named “Golgatha Biergarten” park which hosted our dinner, based on local grilled meat and food and an awesome community binding moment which was the perfect enriching closing for such an awesome day.&lt;/p&gt;
&lt;p&gt;So it’s hard to hide how thrilled I am to see what’s coming next tomorrow.&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>Automating checking for new versions of PostgreSQL</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2013/07/automating-checking-for-new-versions-of/"/>
      <id>https://www.endpointdev.com/blog/2013/07/automating-checking-for-new-versions-of/</id>
      <published>2013-07-03T00:00:00+00:00</published>
      <author>
        <name>Greg Sabino Mullane</name>
      </author>
      <content type="html">
        &lt;div class=&#34;separator&#34; style=&#34;clear: both; text-align: center; float:right&#34;&gt;&lt;a href=&#34;/blog/2013/07/automating-checking-for-new-versions-of/image-0.jpeg&#34; imageanchor=&#34;1&#34; style=&#34;clear: right; margin-bottom: 1em; margin-left: 1em;&#34;&gt;&lt;img border=&#34;0&#34; src=&#34;/blog/2013/07/automating-checking-for-new-versions-of/image-0.jpeg&#34;/&gt;&lt;/a&gt;&lt;br/&gt;&lt;small&gt;Hubble image by &lt;a href=&#34;https://www.flickr.com/photos/77954350@N07/&#34;&gt;castielstar&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;It is important to run the latest revision of the major branch of Postgres you are using. While &lt;a href=&#34;https://www.postgresql.org/list/pgsql-announce/&#34;&gt;the pgsql-announce mailing list&lt;/a&gt; is often touted as a canonical way to become aware of new releases, a better method is to use &lt;a href=&#34;https://bucardo.org/check_postgres/&#34;&gt;the check_postgres program&lt;/a&gt;, which will let you know if the version you are running needs to be upgraded or not. An example usage:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ check_postgres.pl --action=new_version_pg --dbhost=iroh
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;POSTGRES_NEW_VERSION_PG CRITICAL:  Please upgrade to version 9.2.4 of Postgres. You are running 9.2.2&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Postgres version numbers come in three sections. The first two indicate the “major version”
of Postgres that you are running. The third number indicates the revision. You always want
to be using the highest revision available for your version. In the example above, Postgres
version 9.2 is being used, and it should be upgraded from revision 2 to revision 4. A change
in the revision number is known as a minor release; these are only done for important reasons,
such as security or important bug fixes. Read
&lt;a href=&#34;https://www.postgresql.org/support/versioning/&#34;&gt;the versioning policy page&lt;/a&gt; for more information.&lt;/p&gt;
&lt;p&gt;When a new version of PostgreSQL is made, there are two general ways of communicating this
fact: the pgsql-announce mailing list, and
&lt;a href=&#34;https://postgresql.org/versions.rss&#34;&gt;the versions.rss file&lt;/a&gt; on the postgresql.org
web site. While the mailing list is
&lt;a href=&#34;https://www.postgresql.org/list/pgsql-announce/2013-06/&#34;&gt;low volume&lt;/a&gt;, it is not ideal as it contains posts about
conferences, and about other Postgres-related software. A better solution is to track
the versions.rss file. You could simply subscribe to it, but this will only tell you when the
file has been changed. The check_postgres program parses this file and compares the latest
revision to the version of Postgres that you are using.&lt;/p&gt;
&lt;p&gt;To use it, simply call check_postgres and pass &lt;strong&gt;new_version_pg&lt;/strong&gt;
as the &lt;strong&gt;action&lt;/strong&gt; argument, as well as telling check_postgres which PostgreSQL
instance you are checking. For example, to check that the Postgres running on
your internal host “zuko” is up to date, just run:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;check_postgres.pl --action=new_version_pg --dbhost=zuko&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Here is what the default output looks like, for both a matching and
a non-matching version:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ check_postgres.pl --action=new_version_pg --dbhost=appa
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;POSTGRES_NEW_VERSION_PG CRITICAL:  Please upgrade to version 9.2.4 of Postgres. You are running 9.2.2
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ check_postgres.pl --action=new_version_pg --dbhost=toph
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;POSTGRES_NEW_VERSION_PG OK:  Version 9.2.4 is the latest &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; Postgres&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Those examples are very Nagios specific, of course, as evidenced by those uppercase strings at the beginning
of the output. If you are using Nagios, it’s a good idea to run this, perhaps once a day or more often. If
you are not using Nagios, you can make the output a little cleaner with the &lt;strong&gt;&amp;ndash;simple&lt;/strong&gt; argument:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ check_postgres.pl --action=new_version_pg --dbhost=azula
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Please upgrade to version 9.2.4 of Postgres. You are running 9.2.2
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ check_postgres.pl --action=new_version_pg --dbhost=sokka
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Version 9.2.4 is the latest &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;for&lt;/span&gt; Postgres&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;One quick and simple trick is to make this into a cron job and add the &lt;strong&gt;&amp;ndash;quiet&lt;/strong&gt; argument, which
prevents all output if the check was “OK”. In this way, cron will only send outout (e.g. mail
someone) when a new revision has been released. A cron example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-plain&#34; data-lang=&#34;plain&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;## Twice a day, check that we are running the latest Postgres:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;0 7,18 * * * check_postgres.pl --action=new_version_pg --dbhost=cabbage --quiet&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Once this alarm goes off, you should strive to update your clusters as soon as possible.
If you are using a packaging system, then it may be as simple as relying on it to
do the right thing, e.g. “yum update postgresql”. If you are installing from source,
you will need the new tarball and can simply “make install” onto the existing
Postgres, and then restart it. Always check the release notes for the new revision—​once in a blue
moon the update requires some other action, such as a reindex of certain types of indexes.&lt;/p&gt;
&lt;p&gt;The check_postgres program can verify versions of some
&lt;a href=&#34;https://bucardo.org/check_postgres/check_postgres.pl.html#new_version_bc&#34;&gt;other programs&lt;/a&gt; as well, including
&lt;a href=&#34;https://bucardo.org/Bucardo/&#34;&gt;Bucardo&lt;/a&gt;,
&lt;a href=&#34;https://bucardo.org/tail_n_mail/&#34;&gt;tail_n_mail&lt;/a&gt;, and check_postgres itself.&lt;/p&gt;

      </content>
    </entry>
  
    <entry>
      <title>check_postgres meets pgbouncer</title>
      <link rel="alternate" href="https://www.endpointdev.com/blog/2010/10/checkpostgres-meets-pgbouncer/"/>
      <id>https://www.endpointdev.com/blog/2010/10/checkpostgres-meets-pgbouncer/</id>
      <published>2010-10-22T00:00:00+00:00</published>
      <author>
        <name>Josh Tolley</name>
      </author>
      <content type="html">
        &lt;p&gt;Recently the already well-known PostgreSQL monitoring tool &lt;a href=&#34;https://bucardo.org/wiki/Check_postgres&#34;&gt;check_postgres&lt;/a&gt; gained an ability to monitor &lt;a href=&#34;http://pgfoundry.org/projects/pgbouncer/&#34;&gt;pgbouncer&lt;/a&gt;, the PostgreSQL connection pooling daemon more closely. Previously check_postgres could verify pgbouncer was correctly proxying connections, and make sure its settings hadn’t been modified. The pgbouncer &lt;a href=&#34;https://pgbouncer.github.io/usage.html&#34;&gt;administrative console&lt;/a&gt;, reports many useful pgbouncer statistics and metrics; now check_postgres can monitor some of those as well.&lt;/p&gt;
&lt;p&gt;pgbouncer’s description of its pools consists of “client” elements and “server” elements. “Client” refers to connections coming from clients, and “server” to connections to the PostgreSQL server. The new check_postgres actions pay attention only to the pgbouncer “SHOW POOLS” command, which provides the following metrics:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;cl_active&lt;/strong&gt;: Connections from clients which are associated with a PostgreSQL connection. Use the &lt;em&gt;pgb_pool_cl_active&lt;/em&gt; action.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;cl_waiting&lt;/strong&gt;: Connections from clients that are waiting for a PostgreSQL connection to service them. Use the &lt;em&gt;pgb_pool_cl_waiting&lt;/em&gt; action.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;sv_active&lt;/strong&gt;: Connections to PostgreSQL that are in use by a client connection. Use the &lt;em&gt;pgb_pool_sv_active&lt;/em&gt; action.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;sv_idle&lt;/strong&gt;: Connections to PostgreSQL that are idle, ready to service a new client connection. Use the &lt;em&gt;pgb_pool_sv_idle&lt;/em&gt; action.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;sv_used&lt;/strong&gt;: PostgreSQL connections recently released from a client session. Use the &lt;em&gt;pgb_pool_sv_used&lt;/em&gt; action.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;sv_tested&lt;/strong&gt;: PostgreSQL connections in process of being tested. Use the &lt;em&gt;pgb_pool_sv_tested&lt;/em&gt; action.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;sv_login&lt;/strong&gt;: PostgreSQL connections currently logging in. Use the &lt;em&gt;pgb_pool_sv_login&lt;/em&gt; action.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;maxwait&lt;/strong&gt;: The length of time the oldest waiting client has been waiting for a connection. Use the &lt;em&gt;pgb_pool_maxwait&lt;/em&gt; action.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Most installations probably don’t want any client connections stuck waiting for PostgreSQL connections to service them, meaning the cl_waiting and maxwait metrics ought to be zero. This example will check those two metrics and complain when they’re nonzero, for a pgbouncer installation on port 5433 with pools “pgbouncer” and “maindb”:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-plain&#34; data-lang=&#34;plain&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;postgres@db:~$ ./check_postgres.pl --action=pgb_pool_cl_waiting -p 5433 -w 3 -c 8
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;POSTGRES_PGB_POOL_CL_WAITING OK: (port=5433) pgbouncer=0 * maindb=0 | time=0.01 time=0.01
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;postgres@db:~$ ./check_postgres.pl --action=pgb_pool_maxwait -p 5433 -w 5 -c 15 
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;POSTGRES_PGB_POOL_MAXWAIT OK: (port=5433) pgbouncer=0 * maindb=0 | time=0.01 time=0.01&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The typical check_postgres filtering rules will work; to filter out a pool called “ignore_this_pool”, for instance, add &amp;ndash;exclude ignore_this_pool to the command line. Other connection options mean exactly what they would when connection to PostgreSQL directly.&lt;/p&gt;
&lt;p&gt;These new actions are available in the &lt;a href=&#34;https://github.com/bucardo/check_postgres/blob/master/check_postgres.pl&#34;&gt;latest version from git&lt;/a&gt;.&lt;/p&gt;

      </content>
    </entry>
  
</feed>
