<p>I have set up container insights as described in the <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Container-Insights-setup-metrics.html" rel="nofollow noreferrer">Documentation</a></p>

<p>Is there a way to remove some of the metrics sent over to CloudWatch ?</p>

<p>Details :</p>

<p>I have a small cluster ( 3 client facing namespaces, ~ 8 services per namespace ) with some custom monitoring, logging, etc in their own separate namespaces, and I just want to use CloudWatch for critical client facing metrics.</p>

<p>The problem I am having is that the Agent sends over 500 metrics to CloudWatch, where I am really only interested in a few of the important ones, especially as AWS bills per metric.</p>

<p>Is there any way to limit which metrics get sent to CloudWatch?</p>

<p>It would be especially helpful if I could only sent metrics from certain namespaces, for example, exclude the kube-system namespace </p>

<p>My configmap is:</p>

<pre><code>  cwagentconfig.json: |
    {
      "logs": {
        "metrics_collected": {
          "kubernetes": {
            "cluster_name": "*****",
            "metrics_collection_interval": 60
          }
        },
        "force_flush_interval": 5
      }
    }

</code></pre>

<p>I have searched for a while now, but clouldn't really find anything on:</p>

<pre><code>        "metrics_collected": {
          "kubernetes": {
</code></pre>

<p>I've looked as best I can and you're right, there's little or nothing to find on this topic. Before I make the obvious-but-unhelpful suggestions of either using Prometheus or asking on the AWS forums, a quick look at what the CloudWatch agent actually does.</p>

<p>The Cloudwatch agent gets container metrics either from from cAdvisor, which runs as part of kubelet on each node, or from the kubernetes metrics-server API (which also gets it's metrics from kubelet and cAdvisor). cAdvisor is well documented, and it's likely that the Cloudwatch agent uses the <a href="https://github.com/google/cadvisor/blob/master/docs/storage/prometheus.md" rel="nofollow noreferrer">Prometheus format metrics cAdvisor produces</a> to construct it's own list of metrics. </p>

<p>That's just a guess though unfortunately, since the Cloudwatch agent doesn't seem to be open source. That also means it <em>may</em> be possible to just set a 'measurement' option within the kubernetes section and select metrics based on Prometheus metric names, but probably that's not supported. <em>(if you do ask AWS, the Premium Support team should keep an eye on the forums, so you might get lucky and get an answer without paying for support)</em></p>

<p>So, if you can't cut down metrics created by Container Insights, what are your other options? Prometheus is <a href="https://www.metricfire.com/prometheus-tutorials/how-to-deploy-prometheus-on-kubernetes?utm_source=sof&amp;utm_medium=organic&amp;utm_campaign=prometheus" rel="nofollow noreferrer">easy to deploy</a>, and you can set up recording rules to cut down on the number of metrics it actually saves. It doesn't push to Cloudwatch by default, but you can keep the metrics locally if you have some space on your node for it, or use a <a href="https://www.metricfire.com/prometheus-tutorials/prometheus-storage?utm_source=sof&amp;utm_medium=organic&amp;utm_campaign=prometheus" rel="nofollow noreferrer">remote storage</a> service like MetricFire (the company I work for, to be clear!) which provides Grafana to go along with it. You can also <a href="https://github.com/prometheus/cloudwatch_exporter" rel="nofollow noreferrer">export metrics from Cloudwatch</a> and use Prometheus as your single source of truth, but that means more storage on your cluster.</p>

<p>If you prefer to view your metrics in Cloudwatch, there are tools like <a href="https://github.com/cloudposse/prometheus-to-cloudwatch" rel="nofollow noreferrer">Prometheus-to-cloudwatch</a> which actually scrape Prometheus endpoints and send data to Cloudwatch, much like (I'm guessing) the Cloudwatch Agent does. This service actually has include and exclude settings for deciding which metrics are sent to Cloudwatch.</p>

<p>I've written a blog post on <a href="https://www.metricfire.com/prometheus-tutorials/aws-kubernetes?utm_source=sof&amp;utm_medium=organic&amp;utm_campaign=prometheus" rel="nofollow noreferrer">EKS Architecture and Monitoring</a> in case that's of any help to you. Good luck, and let us know which option you go for!</p>
