Commit 4b1e3dce authored by Alex Tayts's avatar Alex Tayts
Browse files

Initial commit

parents
CloudWatch Module
=================
Installs Amazon CloudWatch Agent. Relies on the availability of the package in some
available repo, does not download it from Amazon.
Configuration file is generated from hiera directly converting hiera YAML to
configuration file's JSON. The default is to return the information only about memory.
The default configuration in hiera:
```yaml
cloudwatch::settings:
agent:
metrics_collection_interval: 60
run_as_user: root
metrics:
append_dimensions:
AutoScalingGroupName: '${aws:AutoScalingGroupName}'
ImageId: '${aws:ImageId}'
InstanceId: '${aws:InstanceId}'
InstanceType: '${aws:InstanceType}'
metrics_collected:
mem:
measurement:
- 'mem_used_percent'
metrics_collection_interval: 60
```
is converted to JSON in `/opt/aws/amazon-cloud-agent/bin/config.json`:
```json
{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "root"
},
"metrics": {
"append_dimensions": {
"AutoScalingGroupName": "${aws:AutoScalingGroupName}",
"ImageId": "${aws:ImageId}",
"InstanceId": "${aws:InstanceId}",
"InstanceType": "${aws:InstanceType}"
},
"metrics_collected": {
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 60
}
}
}
}
```
---
cloudwatch::settings:
agent:
metrics_collection_interval: 60
run_as_user: root
metrics:
append_dimensions:
AutoScalingGroupName: '${aws:AutoScalingGroupName}'
ImageId: '${aws:ImageId}'
InstanceId: '${aws:InstanceId}'
InstanceType: '${aws:InstanceType}'
metrics_collected:
mem:
measurement:
- 'mem_used_percent'
metrics_collection_interval: 60
---
version: 5
defaults: # Used for any hierarchy level that omits these keys.
datadir: data # This path is relative to hiera.yaml's directory.
data_hash: yaml_data # Use the built-in YAML backend.
hierarchy:
- name: "Common data"
path: "common.yaml"
# simple module to deploy CloudWatch agent
#
class cloudwatch (
Enum['absent', 'present', 'installed', 'latest', 'held'] $ensure = 'present',
Hash $settings = {},
){
# define paths
$agent_dir = '/opt/aws/amazon-cloudwatch-agent'
$agent_svc = 'amazon-cloudwatch-agent'
$agent_pkg = 'amazon-cloudwatch-agent'
if ($ensure == 'absent') {
$service_ensure = 'stopped'
$service_enable = false
$directory_ensure = 'absent'
$resource_ensure = 'absent'
if $::osfamily == 'Debian' {
$pkg_ensure = 'purged'
} else {
$pkg_ensure = 'absent'
}
} else {
$service_ensure = 'running'
$service_enable = true
$directory_ensure = 'directory'
$pkg_ensure = $ensure
$resource_ensure = 'present'
}
# install package
package { 'amazon-cloudwatch-agent': ensure => $pkg_ensure }
# source json config file generated from puppet hiera
$config_file = "${agent_dir}/bin/config.json"
file { $config_file:
ensure => $resource_ensure,
content => to_json($settings),
require => Package[$agent_pkg],
notify => Exec['fetch-config'],
}
# create a toml configuration file from the default json config generated by the module
exec { 'fetch-config':
command => "${agent_dir}/bin/amazon-cloudwatch-agent-ctl -s -a fetch-config -c file:${config_file}",
onlyif => [ "/usr/bin/test -f ${config_file}" ],
refreshonly => true,
}
systemd::service { $agent_svc:
ensure => $resource_ensure,
description => 'Amazon CloudWatch Agent',
after => 'network.target',
execstart => "${agent_dir}/bin/start-amazon-cloudwatch-agent",
type => 'simple',
killmode => 'process',
restart => 'on-failure',
restart_sec => '60s',
require => Package[$agent_pkg],
notify => Service[$agent_svc]
}
service { $agent_svc:
ensure => $service_ensure,
enable => $service_enable,
require => [ File[$config_file], Systemd::Service[$agent_svc] ],
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment