<p>I have a simple spring boot application deployed on Kubernetes on GCP. The service is exposed to an external IP address. I am load testing this application using JMeter. It is just a http <code>GET</code> request which returns <code>True</code> or <code>False</code>.</p>

<p>I want to get the latency metrics with time to feed it to HorizontalPodAutoscaler to implement custom auto-scaler. How do I implement this?</p>

anushiya-thevapalan
<p>Since you mentioned Custom Auto Scaler. I would suggest this simple solution which makes use of some of tools which you already might have.</p>

<p><strong>First Part:</strong> Is to Create a service or cron or any time-based trigger which will on a regular interval make requests to your deployed application. This application will then store the resultant metrics to persistence storage or file or Database etc.</p>

<p>For example, if you use a simple Apache Benchmark CLI tool(you can also use Jmeter or any other load testing tool which generates structured o/p), You will get a detailed result for a single query. Use <a href="https://serverfault.com/questions/378310/how-do-i-analyze-an-apache-bench-result">this link</a> to get around the result for your reference.</p>

<p><strong>Second Part</strong> Is that this same script can also trigger another event which will check for the latency or response time limit configured as per your requirement. If the response time is above the configured value scale if it is below scale down. </p>

<p>The logic for scaling down can be more trivial, But I will leave that to you.</p>

<p>Now for actually scaling the deployment, you can use the Kubernetes API. You can refer to the official doc or <a href="https://stackoverflow.com/a/41795286/5617140">this answer</a> for details. Here's a simple flow diagram.</p>

<p><a href="https://i.stack.imgur.com/noe71.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/noe71.jpg" alt="enter image description here"></a></p>
