0

I am new to aws and I have to publish the application service logs to cloud watch. I tried the steps mentioned in AWS documentation and its working. I configured the same steps via jenkins pipeline. Here i am facing an issue. Logs are not getting published i.e. I could not see the logs from AWS console. I logged on to the ec2 instance and check the cloudwatch service status and it shows

{
  "status": "running",
  "starttime": "2021-03-25T07:40:21+0000",
  "configstatus": "configured",
  "cwoc_status": "stopped",
  "cwoc_starttime": "",
  "cwoc_configstatus": "not configured",
  "version": "1.247347.3b250378"
}

Don't understand what is wrong here :(.

Any help would be helpful.

Thanks in advance.

Priyanka
  • 45
  • 1
  • 10
  • Does your IAM role bound to EC2 have permission to write to CloudWatch? – Praneeth Peiris Mar 25 '21 at 08:55
  • Yes IAM role bound to EC2 have permission to write to CloudWatch – Priyanka Mar 25 '21 at 09:09
  • can you share more information which doc you followed for setting. I followed this [Quick Start: Install and Configure the CloudWatch Logs Agent on a Running EC2 Linux Instance](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/QuickStartEC2Instance.html) and it worked without any trouble. – samtoddler Mar 25 '21 at 12:24
  • @samtoddler I have followed the steps mentioned here [link](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-commandline-fleet.html) – Priyanka Mar 26 '21 at 08:26

1 Answers1

1

I followed the link mentioned by you Installing and Running the CloudWatch Agent on Your Servers.

Below is my configuration for pushing the logs and few other metrics, which is generated by this command

Run the CloudWatch Agent Configuration Wizard

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
{
        "agent": {
                "metrics_collection_interval": 60,
                "run_as_user": "root"
        },
        "logs": {
                "logs_collected": {
                        "files": {
                                "collect_list": [
                                        {
                                                "file_path": "/var/log/messages",
                                                "log_group_name": "messages",
                                                "log_stream_name": "{instance_id}"
                                        }
                                ]
                        }
                }
        },
        "metrics": {
... # metrics configuration here
        }
}

Started the client as described in the doc

/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a \
fetch-config -m ec2 -s -c file:///opt/aws/amazon-cloudwatch-agent/bin/config.json

Start the CloudWatch Agent Using the Command Line

# /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a status
{
  "status": "running",
  "starttime": "2021-03-26T11:46:14+0000",
  "version": "1.247345.35"
}

enter image description here

You can look for troubles inside the logs directory if there are any

[root@ip-xx amazon-cloudwatch-agent]# ls
amazon-cloudwatch-agent.log  configuration-validation.log  state
[root@ip-xx amazon-cloudwatch-agent]# pwd
/var/log/amazon/amazon-cloudwatch-agent

On the side note if I just want to push the logs to cloudwatch, I would use this one

Quick Start: Install and Configure the CloudWatch Logs Agent on a Running EC2 Linux Instance

samtoddler
  • 8,463
  • 2
  • 26
  • 21
  • My configuration and steps are same. The only difference that I could see is the user. "run_as_user": "cwagent" – Priyanka Mar 27 '21 at 11:40
  • can this be the reason?? – Priyanka Mar 27 '21 at 11:40
  • 1
    @Priyanka yes if the user `cwagent` doesnt has t he permissions to read the logs, which you are trying to push, then this creates the trouble. [Running the CloudWatch Agent as a Different User](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-common-scenarios.html#CloudWatch-Agent-run-as-user). Try chaning the user to `root`. Should work if not you can follow the guide linked to run the agent as different user. – samtoddler Mar 27 '21 at 12:05
  • that was the issue.. run_as_user : cwagent was not having permissions. Changed it to the root.. and now its working fine.. Thanks :) – Priyanka Mar 30 '21 at 08:07