<p>I'm wondering about an approach one has to take for our server setup.  We have pods that are short lived.  They are started up with 3 pods at a minimum and each server is waiting on a single request that it handles - then the pod is destroyed. I'm not sure of the mechanism that this pod is destroyed, but my question is not about this part anyway.</p>
<p>There is an &quot;active session count&quot; metric that I am envisioning.  Each of these pod resources could make a rest call to some &quot;metrics&quot; pod that we would create for our cluster.  The metrics pod would expose a <code>sessionStarted</code> and <code>sessionEnded</code> endpoint - which would increment/decrement the kubernetes <code>activeSessions</code> metric. That metric would be what is used for horizontal autoscaling of the number of pods needed.</p>
<p>Since having a pod as &quot;up&quot; counts as zero active sessions, the custom event that increments the session count would update the metric server session count with a rest call and then decrement again on session end (the pod being up does not indicate whether or not it has an active session).</p>
<p>Is it correct to think that I need this metric server (and write it myself)? Or is there something that Prometheus exposes where this type of metric is supported already - rest clients and all (for various languages), that could modify this metric?</p>
<p>Looking for guidance and confirmation that I'm on the right track.  Thanks!</p>

Mike
<p>It's impossible to give only one way to solve this and your question is more &quot;opinion-based&quot;. However there is an useful <a href="https://stackoverflow.com/questions/68176705/how-to-get-active-connections-count-of-a-kubernetes-pod">similar question on StackOverFlow</a>, please check the comments that can give you some tips. If nothing works, probably you should write the script. There is no exact solution from Kubernetes's side.</p>
<p>Please also take into the consideration of <a href="https://flink.apache.org/flink-architecture.html" rel="nofollow noreferrer">Apache Flink</a>. It has <a href="https://nightlies.apache.org/flink/flink-docs-release-1.13/docs/deployment/resource-providers/standalone/kubernetes/#using-standalone-kubernetes-with-reactive-mode" rel="nofollow noreferrer">Reactive Mode</a> in combination of Kubernetes:</p>
<blockquote>
<p><a href="https://nightlies.apache.org/flink/flink-docs-release-1.13/docs/deployment/elastic_scaling/#reactive-mode" rel="nofollow noreferrer">Reactive Mode</a> allows to run Flink in a mode, where the Application Cluster is always adjusting the job parallelism to the available resources. In combination with Kubernetes, the replica count of the TaskManager deployment determines the available resources. Increasing the replica count will scale up the job, reducing it will trigger a scale down. This can also be done automatically by using a <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">Horizontal Pod Autoscaler</a>.</p>
</blockquote>
