<p>Below are the setup details:
keda installed,
prometheus deployed,
through application using below scaled object template for hpa:</p>
<pre><code>keda:
  triggers:
    - metadata:
        metricName: container_memory_usage
        query: avg(floor((container_memory_usage_bytes{pod=~&quot;pythonb-.*&quot;,container=~&quot;proxy&quot;} / container_spec_memory_limit_bytes != +Inf)  * 100))
        serverAddress: &lt;serveraddress&gt;
        threshold: '70'
      type: prometheus
</code></pre>
<p>basically we want to scale the deployment based on the given prom query.(based on container memory utilisation of particular pods..if it exceeds 70% then hpa will scale the pods. )
when we try the above query on Prometheus it returns the results as 8.<em>, 10.</em>. , 25.3. Basically single element response
But though keda it gives the result as below:</p>
<pre><code>kubectl get hpa -n integration keda-pythonb 
NAME                       REFERENCE                    TARGETS                               MINPODS   MAXPODS   REPLICAS   AGE
keda-pythonb   Deployment/pythonb   3500m/70 (avg), 34%/87% + 1 more...   2         10        2          14m
</code></pre>
<p>Instead of single value it gives 3500m as current value.
does keda convert the data returned from prom query? Any pointers would be helpful.
I hope the prom query is correct.</p>

<p>We just solved this one after a lot of off-and-on hunting. Turns out KEDA has an option called <code>metricType</code> that you can specify under <code>triggers</code>. TLDR you need to set that to <code>&quot;Value&quot;</code>.</p>
<p>To understand why you need to dive into how HPA works in Kubernetes. When you define a <code>kind: HorizontalPodAutoscaler</code> you specify the metrics that are used for scaling. KEDA does this for you and creates an external metric like this:</p>
<pre class="lang-yaml prettyprint-override"><code>  metrics:
  - external:
      metric:
        name: ...
        selector:
          matchLabels:
            scaledobject.keda.sh/name: ...
      target:
        type: AverageValue
        averageValue: ...
    type: External
</code></pre>
<p>There are <code>Value</code> and <code>AverageValue</code> metric types. <code>AverageValue</code> is the default, meant for metrics like <code>http-requests-per-second</code>, which would need to be divided by the number of replicas before compared to the target. <code>Value</code>, on the other hand, takes the direct value from your metric without averaging it.</p>
<p>Since your Prometheus query is returning an average across pods already, you need to use <code>Value</code>. The clue is in your <code>kubectl get hpa</code> output: <code>3500m/70 (avg)</code>.</p>
<p>See <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-metrics-not-related-to-kubernetes-objects" rel="nofollow noreferrer">docs on HPA with external metrics</a>.</p>
<p>In KEDA that is specified using the <code>metricType</code> option under the <code>triggers</code> field.</p>
<p>See <a href="https://keda.sh/docs/2.9/concepts/scaling-deployments/#triggers" rel="nofollow noreferrer">KEDA: Scaling Deployments</a></p>
