<p>Hi everyone,</p>

<p>I have a cluster based on <strong>kubeadm</strong> having 1 master and 2 workers. I have already implemented built-in horizontalPodAutoscaling (based on cpu_utilization and memory) and now i want to perform autoscaling on the basis of custom metrics (<strong>response time</strong> in my case). </p>

<p>I am using <strong>Prometheus Adapter</strong> for custom metrics.And, I could not find any metrics with the name of response_time in prometheus.</p>

<ol>
<li><p>Is there any metric available in prometheus which scales the application based on response time and what is its name?</p></li>
<li><p>Whether i will need to edit the default horizontal autoscaling algorithm or i will have to make an algorithm for autoscaling from scratch which could scale my application on the basis of response time?</p></li>
</ol>

zain ul abedin
<p>Prometheus has only 4 <a href="https://prometheus.io/docs/concepts/metric_types/" rel="nofollow noreferrer">metric types</a>: <strong>Counter</strong>, <strong>Gauge</strong>, <strong>Histogram</strong> and <strong>Summary</strong>.</p>

<p>I guess <strong>Histogram</strong> is that what you need</p>

<blockquote>
  <p>A  <em>histogram</em>  samples observations (usually things like request durations or response sizes) and counts them in configurable buckets. It also provides a sum of all observed values.</p>
  
  <p>A histogram with a base metric name of  <code>&lt;basename&gt;</code>  exposes multiple time series during a scrape:</p>
  
  <ul>
  <li>cumulative counters for the observation buckets, exposed as  <code>&lt;basename&gt;_bucket{le="&lt;upper inclusive bound&gt;"}</code></li>
  <li>the  <strong>total sum</strong>  of all observed values, exposed as  <code>&lt;basename&gt;_sum</code></li>
  <li>the  <strong>count</strong>  of events that have been observed, exposed as  <code>&lt;basename&gt;_count</code>  (identical to  <code>&lt;basename&gt;_bucket{le="+Inf"}</code>  above)</li>
  </ul>
</blockquote>

<h2>1.</h2>

<p>There is a <a href="https://stackoverflow.com/questions/47305424/measure-service-latency-with-prometheus">stackoverflow question</a>, where you can get a query for latency (response time), so I think this might be useful for you. </p>

<h2>2.</h2>

<p>I dont know if I understand you correctly, but if you want to edit <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">HPA</a>, you can edit the yaml file, delete previous HPA and create new one instead.</p>

<pre><code>kubectl delete hpa &lt;name.yaml&gt;
kubectl apply -f &lt;name.yaml&gt;
</code></pre>

<p>There is <a href="https://itnext.io/horizontal-pod-autoscale-with-custom-metrics-8cb13e9d475" rel="nofollow noreferrer">good article</a> about <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-multiple-metrics-and-custom-metrics" rel="nofollow noreferrer">Autoscaling on custom metrics</a> with custom Prometheus Metrics.</p>
