title: Can not take jstat metrics using bash as Sensu plugin
body: <p>I have created bash scirpt that takes jstat metrics of my jvm instances!</p>
  
  <p>Here is the output example :</p>
  
  <pre><code>demo.server1.sms.jstat.eden 24.34   0
  demo.server1.lcms.jstat.eden    54.92   0
  demo.server1.lms.jstat.eden 89.49   0
  demo.server1.tms.jstat.eden 86.05   0
  </code></pre>
  
  <p>But when the Sensu-client runs this script it returns </p>
  
  <pre><code>Could not attach to 8584
  Could not attach to 8588
  Could not attach to 17141
  Could not attach to 8628
  demo.server1.sms.jstat.eden     0
  demo.server1.lcms.jstat.eden    0
  demo.server1.lms.jstat.eden     0
  demo.server1.tms.jstat.eden     0
  </code></pre>
  
  <p>Here is the example of check_cron.json</p>
  
  <pre><code>{
    "checks": {
      "jstat_metrics": {
        "type": "metric",
        "handlers": ["graphite"],
        "command": "/etc/sensu/plugins/jstat-metrics.sh",
        "interval": 5,
            "subscribers": [ "webservers" ]
      }
    }
  }
  </code></pre>
  
  <p>And piece of my bash script</p>
  
  <pre><code>jvm_list=("sms:$sms" "lcms:$lcms" "lms:$lms" "tms:$tms" "ums:$ums")
  for jvm_instance in ${jvm_list[@]}; do
      project=${jvm_instance%%:*}
      pid=${jvm_instance#*:}
          if [ "$pid" ]; then
            metric=`jstat -gc $pid|tail -n 1`
            output=$output$'\n'"demo.server1.$project.jstat.eden"$'\t'`echo $metric |awk '{ print $3}'`$'\t0'
          fi
  done
  echo "$output"
  </code></pre>
  
  <p>I find out that problem is with jstat and i tried to write full jstat  path like <code>/usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/jstat -gc $pid|tail -n 1</code> but it didn't help! </p>
  
  <p>By the way if i will comment this row the output like "<strong>Could not attach to 8584</strong>" disappears!</p>