Each onpremise server needs to have their own namespace - How to do it?

0

Hello everyone!

I am new in AWS so sorry if the question can sound so simple or stupid. But I am blocked with that. I'm trying with cloudwatch get all the possible metrics from our on-premise linux servers. With wizard tool we can do that (https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-cloudwatch-agent-configuration-file-wizard.html). The problem is that I need to split the metrics of each server in different namespaces (each server needs to have their own namespace). And here is the issue. I did not find the form of do it.

I read the documentation of AWS Cloudwatch, and I found this solution for create namespaces (adding this code line in the json config file - /opt/aws/amazon-cloudwatch-agent/bin/config.json):

{
  "metrics": {
    "namespace": "Development/Product1Metrics",
   ......
   },
} 

https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html (Refeering to CloudWatch agent configuration file: Metrics section).

The complete json config file is the next one:

{
  "agent": {
    "metrics_collection_interval": 60,
    "run_as_user": "root",
    "region": "eu-central-1"
  },
  "logs": {
    "logs_collected": {
      "files": {
        "collect_list": [
          {
            "file_path": "",
            "log_group_name": ".",
            "log_stream_name": "{hostname}",
            "retention_in_days": -1
          },
          {
            "file_path": "",
            "log_group_name": ".",
            "log_stream_name": "{hostname}",
            "retention_in_days": -1
          }
        ]
      }
    }
  },
  "metrics": {
    "namespace": "DEV/ONPREMISE",
    "metrics_collected": {
      "collectd": {
        "metrics_aggregation_interval": 60
      },
      "cpu": {
        "measurement": [
          "cpu_usage_idle",
          "cpu_usage_iowait",
          "cpu_usage_steal",
          "cpu_usage_guest",
          "cpu_usage_user",
          "cpu_usage_system"
        ],
        "metrics_collection_interval": 60,
        "resources": ["*"],
        "totalcpu": true
      },
      "disk": {
        "measurement": ["used_percent"],
        "metrics_collection_interval": 60,
        "resources": ["*"]
      },
      "diskio": {
        "measurement": [
          "io_time",
          "write_bytes",
          "read_bytes",
          "writes",
          "reads"
        ],
        "metrics_collection_interval": 60,
        "resources": ["*"]
      },
      "mem": {
        "measurement": ["mem_used_percent"],
        "metrics_collection_interval": 60
      },
      "net": {
        "measurement": [
          "bytes_sent",
          "bytes_recv",
          "packets_sent",
          "packets_recv"
        ],
        "metrics_collection_interval": 60,
        "resources": ["*"]
      },
      "netstat": {
        "measurement": ["tcp_established", "tcp_time_wait"],
        "metrics_collection_interval": 60
      },
      "statsd": {
        "metrics_aggregation_interval": 60,
        "metrics_collection_interval": 10,
        "service_address": ":8125"
      },
      "swap": {
        "measurement": ["swap_used_percent"],
        "metrics_collection_interval": 60
      }
    }
  }
}

And after that, I used the command: sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a append-config -m onPremise -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json.

This is the output of the command:

****** processing amazon-cloudwatch-agent ******
Got Home directory: /root I! Set home dir Linux: /root I! SDKRegionWithCredsMap region: eu-central-1 Successfully fetched the config and saved in /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json.tmp
Start configuration validation...
2023/06/01 09:37:38 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json ...
2023/06/01 09:37:38 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json ...
2023/06/01 09:37:38 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json.tmp ...
2023/06/01 09:37:38 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/ssm_AmazonCloudWatch-linux ...
2023/06/01 09:37:38 I! Valid Json input schema.
I! Detecting run_as_user...
Got Home directory: /root
No csm configuration found.
Under path : /logs/ | Info : Got hostname mdk02 as log_stream_name
Configuration validation first phase succeeded
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent -schematest -config /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml
Configuration validation second phase succeeded
Configuration validation succeeded

Seems that does not exist any error

But when I update cloudswatch in the eu-central-1 region, I can not see nothing with the namespace name "DEV/ONPREMISE": https://imgur.com/a/qeepamK

Thanks in advance to everyone can help! :)

1 Antwort
0

Looking at the startup log, it appears that the configuration file being read is "/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json".
Try to create a configuration in "/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json".
Then try starting it with the following command.

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a append-config -m onPremise -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
profile picture
EXPERTE
beantwortet vor einem Jahr
  • Hi! I tried it, but didn't work. It's really strange

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen