<p>I need to monitoring a lot of legacy containers in my eks cluster that having a nfs mountpath. To map nfs directory in container i using nfs-client helm chart.</p>
<p>I need to monitor when my mountpath for some reason is lost, and the only way that i find to do that is exec a command in container.</p>
<pre><code>#!/bin/bash

df -h | grep ip_of_my_nfs_server | wc -l
</code></pre>
<p>if the output above returns 1 i know that my nfs mountpath is ok.</p>
<p>Anybody knows some whay that monitoring an output script exec in container with prometheus?</p>
<p>Thanks!</p>

mzibit
<p>As Matt has pointed out in the comments: first order of business should be to see if you can simply facilitate your monitoring requirement from node_exporter.</p>
<p>Below is a more generic answer on collecting metrics from arbitrary shell commands.</p>
<hr />
<p>Prometheus is a pull-based monitoring system. You configure it with &quot;scrape targets&quot;: these are effectively just HTTP endpoints that expose metrics in a specific format. <em>Some</em> target needs to be alive for long enough to allow it to be scraped.</p>
<p>The two most obvious options you have are:</p>
<ul>
<li>Wrap your logic in a long-running process that exposes this metric on an HTTP endpoint, and configure it as a scrape target</li>
<li>Spin up an instance of <a href="https://github.com/prometheus/pushgateway" rel="nofollow noreferrer">pushgateway</a>, and configure it as a scrape target , and have your command push its metrics there</li>
</ul>
<p>Based on the little information you provided, the latter option seems like the most sane one. Important and relevant note from the README:</p>
<blockquote>
<p>The Prometheus Pushgateway exists to allow ephemeral and batch jobs to expose their metrics to Prometheus. Since these kinds of jobs may not exist long enough to be scraped, they can instead push their metrics to a Pushgateway. The Pushgateway then exposes these metrics to Prometheus.</p>
</blockquote>
<p>Your command would look something like:</p>
<pre><code>#!/bin/bash

printf &quot;mount_path_up %d&quot; $(df -h | grep ip_of_my_nfs_server | wc -l) | curl --data-binary @- http://pushgateway.example.org:9091/metrics/job/some_job_name
</code></pre>
