<p>I have applications running in different cluster, like below (say as example)</p>
<pre><code> cluster1 - for scratch work
 cluster2 - as staging env (pods running application )
 cluster3 - as testing env (pods running application )
 cluster4 - monitor app
</code></pre>
<p>All the AKS cluster are connected in the network, a monitoring app is running on <code>cluster4</code>, which has custom monitoring dashboard. I am trying to add the container/pod status of app running on <code>cluster2</code> and <code>cluster3</code> to that dashboard.</p>
<p>Is there a way to fetch the container/pod status from the app running in <code>cluster4</code> either using java/REST API/shell.</p>
<p>I came across Kubernetes java client <a href="https://github.com/kubernetes-client/java/blob/master/examples/examples-release-12/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java" rel="nofollow noreferrer">InclusterClientExample</a>.</p>
<p>Is there any better approach for this situation to fetch the container/pod status of the application running on different cluster.</p>

Tim
<p>Another options was to enable Log Analytics API.</p>
<ul>
<li><p>create a workspace and use REST API to fire query. below is at a high level of how to do it.</p>
<ul>
<li>If AAD is setup, get the TENENT ID info.</li>
<li>Register App, create a Service principal.  (provides application (client) id)
<ul>
<li>Within the SP, add a secret key. (note this down, since it won't be viewable later)</li>
<li>Add API Permission, select Log Analytics
<ul>
<li>Grant Delegate permission (Data.Read) and Application Permissiong (Data.Read) which was in my case.</li>
</ul>
</li>
</ul>
</li>
<li>In Log Analytics workspace, Access Control (IAM), add the Service principal and provide Reader access. ( workspace-name, resourceGroup-name, workspace-id, subscription-id to be noted)</li>
</ul>
</li>
</ul>
<p>Per the <a href="https://dev.loganalytics.io/documentation/1-Tutorials/ARM-API" rel="nofollow noreferrer">link</a>.
First we need to fetch the access_token using the SP and Tenet id. Few of the screenshot in this link is old.</p>
<p>Using curl command:</p>
<ol>
<li>Fetch token</li>
</ol>
<pre><code>curl -vX POST -d 'grant_type=client_credentials&amp;client_id=[SP application(client) id]&amp;client_secret=[Client secret created in SP]&amp;resource=https://management.azure.com/' https://login.microsoftonline.com/[TENENT_ID]/oauth2/token
</code></pre>
<ol start="2">
<li>Fetch log info</li>
</ol>
<pre><code>curl -vX post -H &quot;Authorization: Bearer [TOKEN-FROM-ABOVE]&quot; -H &quot;Content-Type: application/json&quot; -H &quot;Prefer: response-v1=true&quot;-d @samplequery.json https://api/loganalytics.io/v1/subscriptions/[subscription-id-of-workspace]/resourceGroups/[Resource-group-name-of-workspace]/providers/Microsoft.OperationalInsights/workspaces/&lt;workspace-name&gt;/api/query?api-version=2020-08-01
</code></pre>
<p>Sample query file</p>
<pre class="lang-json prettyprint-override"><code>{ 
 &quot;query&quot;: &quot;Perf | where CounterName == 'Available MBytes' | summarize avg(CounterValue) by bin(TimeGenerated, 1h)&quot;,
  &quot;timespan&quot;: &quot;PT12H&quot;
}
}
</code></pre>
<p>output would be the result of the query.</p>
