awslabs / collectd-cloudwatch

A collectd plugin for sending data to Amazon CloudWatch
MIT License
200 stars 132 forks source link

Any way to do an unattended install? #5

Closed bunchjesse closed 7 years ago

bunchjesse commented 8 years ago

I want to add this to my user data script that is run when an EC2 instance boots but I'm not seeing a way to do an unattended install. It is asking me to choose an AWS region:

root@ip-10-0-0-157:~# curl -L https://github.com/awslabs/collectd-cloudwatch/raw/master/src/setup.py | python
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   147  100   147    0     0   3461      0 --:--:-- --:--:-- --:--:--  3500
100 25246  100 25246    0     0   281k      0 --:--:-- --:--:-- --:--:--  281k
Installing dependencies ... OK
Installing python dependencies ... OK
Downloading plugin ... OK
Extracting plugin ... OK
Moving to collectd plugins directory ... OK
Copying CloudWatch plugin include file ... OK

Choose AWS region for published metrics:
  1. Automatic [us-east-1]
  2. Custom
Enter choice [1]: Traceback (most recent call last):
  File "<stdin>", line 586, in <module>
  File "<stdin>", line 579, in main
  File "<stdin>", line 504, in install_plugin
  File "<stdin>", line 520, in supply_config
  File "<stdin>", line 534, in _prepare_plugin_config
  File "<stdin>", line 304, in run
  File "<stdin>", line 313, in _configure_region
  File "<stdin>", line 404, in run
  File "<stdin>", line 407, in _get_answer
EOFError: EOF when reading a line
rilindo commented 8 years ago

Not sure why there is some confusion. Manually running the script is a big pain, as makes automation extremely difficult (whether by invoking directly through automation tools or via baked images). I second the motion for unattended installation.

JadyLiu commented 8 years ago

same request to install unattended. Also, getting error when running ./setup.py

Traceback (most recent call last): File "", line 26, in ImportError: cannot import name check_output

extraordinaire commented 8 years ago

Might help someone:

(echo "1"; echo "1"; echo "1"; echo "3"; cat) | sudo ./setup.py
den-is commented 7 years ago

+1 command line options or external config file supplied in cmd might help a lot. especially for nodes deployed via auto scaling groups, and if not asg then hosts provisioned by either configuration management system

stacyhorton commented 7 years ago

+1 for unattended support please.

ghost commented 7 years ago

Hey guys,

For those of you wanting to automate this on AWS, here is a sample bootstrap script I have built for my Amazon Linux instance launches and it is working great:

------- Once Off Preparations -------

1.) Rather not fetch the file from Github via your script, instead copy the setup.py raw text into a new text document called setup.py, and upload this to an AWS S3 bucket; Then set this file to be PUBLIC and fetch from there going forward inside your automation scripts. This gives you more ability to control versions of your setup.py file as well as avoiding the "Traceback" error bunchjesse and JadyLiu experienced when downloading and executing straight from Github.

2.) Once the file is in your personal bucket, for example the path to this file may be https://s3-eu-west-1.amazonaws.com/my-bucket-name/setup.py , edit the bash script line 5 and replace the URL there next to wget.

3.) Add the below script to your AWS Autoscaling Launch Configurations, Advanced options (user data).

Notes: Region will be automatically detected, host-name will be set to the instance ID, and IAM Role will be automatically used. For demonstration purposes, only the memory--memory-used OS metric will be pushed to CloudWatch.

------- Bash Script Example -------

!/bin/bash

yum update -y yum install collectd -y cd /tmp wget https://s3-eu-west-1.amazonaws.com/my-bucket-name/setup.py sudo chmod a+x setup.py (echo "1"; echo "1"; echo "1"; echo "2"; cat) | python setup.py echo "memory--memory-used" > /tmp/whitelist.conf cp -vrf /tmp/whitelist.conf /opt/collectd-plugins/cloudwatch/config/whitelist.conf chown root:root /opt/collectd-plugins/cloudwatch/config/whitelist.conf chmod 644 /opt/collectd-plugins/cloudwatch/config/whitelist.conf service collectd restart


Use at your own risk

yimuniao commented 7 years ago

Refer to https://github.com/awslabs/collectd-cloudwatch/pull/52