<p>I try to implement a HPA based on phpfpm's active process count. I installed prometheus, the prometheus-adapter and the exporter as sidecar to my PHP-Application. At the prometheus' UI get the correct metrics.</p>
<p>Here is my prometheus-adapter-config:</p>
<pre><code>  - seriesQuery: 'phpfpm_active_processes{kubernetes_namespace!=&quot;&quot;,kubernetes_pod_name!=&quot;&quot;}'
    resources:
      overrides:
        kubernetes_namespace:
          resource: &quot;namespace&quot;
        kubernetes_pod_name:
          resource: &quot;pod&quot;
    name:
      matches: &quot;phpfpm_active_processes&quot;
      as: &quot;phpfpm_avg_processes&quot;
    metricsQuery: 'avg(avg_over_time(phpfpm_active_processes[30s])) by (kubernetes_pod_name,kubernetes_namespace))'
</code></pre>
<p>If i call the k8s-api, i see the metrics are available:</p>
<pre><code>$ kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1 | jq .
{
  &quot;kind&quot;: &quot;APIResourceList&quot;,
  &quot;apiVersion&quot;: &quot;v1&quot;,
  &quot;groupVersion&quot;: &quot;custom.metrics.k8s.io/v1beta1&quot;,
  &quot;resources&quot;: [
    {
      &quot;name&quot;: &quot;namespaces/phpfpm_avg_processes&quot;,
      &quot;singularName&quot;: &quot;&quot;,
      &quot;namespaced&quot;: false,
      &quot;kind&quot;: &quot;MetricValueList&quot;,
      &quot;verbs&quot;: [
        &quot;get&quot;
      ]
    },
    {
      &quot;name&quot;: &quot;pods/phpfpm_avg_processes&quot;,
      &quot;singularName&quot;: &quot;&quot;,
      &quot;namespaced&quot;: true,
      &quot;kind&quot;: &quot;MetricValueList&quot;,
      &quot;verbs&quot;: [
        &quot;get&quot;
      ]
    }
  ]
}
</code></pre>
<p>But the HPA fails with an error:
<code>unable to get metric phpfpm_avg_processes: unable to fetch metrics from custom metrics API: Internal error occurred: unable to fetch metrics</code></p>
<p>If i try to fetch the metrics via kubectl, i'll get the error:</p>
<pre><code>$ kubectl get --raw '/apis/custom.metrics.k8s.io/v1beta1/namespaces/default/pods/*/phpfpm_avg_processes' | jq
Error from server (InternalError): Internal error occurred: unable to fetch metrics
</code></pre>
<p>The logs of the prometheus-adapter includes following messages:</p>
<pre><code>2020-11-03T08:27:07.7920803Z I1103 08:27:07.791793       1 httplog.go:90] GET /apis/custom.metrics.k8s.io/v1beta1/namespaces/mynamespace/pods/%2A/phpfpm_avg_processes?labelSelector=myapp.service%3Dtestapp: (13.6381ms) 500
</code></pre>
<p>I also tried adding <code>--kubelet-insecure-tls</code> and <code>--kubelet-preferred-address-types=InternalIP</code> to the metrics-server with no luck.</p>
<p>Info: for testing i use docker-for-mac</p>
<p>Can anybody help? I don't know how to debug or where to look at?!</p>

RockKeeper
<p>I've modified my Adapter-Config and now it works. I changed the line regarding metricsQuery to <code>metricsQuery: 'avg(avg_over_time(phpfpm_listen_queue{&lt;&lt;.LabelMatchers&gt;&gt;}[30s])) by (&lt;&lt;.GroupBy&gt;&gt;)'</code></p>
