mirror of
https://github.com/jambonz/jambonz-infrastructure.git
synced 2026-01-25 02:08:27 +00:00
add cloudwatch option to jambonz-mini
This commit is contained in:
@@ -55,12 +55,35 @@ Parameters:
|
||||
ConstraintDescription: must be a valid network CIDR
|
||||
AllowedPattern: \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}
|
||||
Default: 10.0.0.0/16
|
||||
Cloudwatch:
|
||||
Description: Send jambonz logs to cloudwatch
|
||||
Type: String
|
||||
Default: true
|
||||
AllowedValues: [true, false]
|
||||
CloudwatchLogRetention:
|
||||
Description: "Number of days to retain cloudwatch logs"
|
||||
Type: Number
|
||||
Default: 3
|
||||
AllowedValues:
|
||||
- 1
|
||||
- 3
|
||||
- 5
|
||||
- 7
|
||||
- 14
|
||||
- 30
|
||||
- 60
|
||||
- 90
|
||||
- 120
|
||||
- 150
|
||||
URLPortal:
|
||||
Type: String
|
||||
Description: "(Optional) A DNS name that you will point to the jambonz webserver(s)"
|
||||
Default: ""
|
||||
|
||||
Conditions:
|
||||
ShouldEnableCloudWatch: !Equals
|
||||
- true
|
||||
- !Ref Cloudwatch
|
||||
DontCreateDNS: !Equals
|
||||
- !Ref URLPortal
|
||||
- ""
|
||||
@@ -72,10 +95,43 @@ Conditions:
|
||||
Mappings:
|
||||
AWSRegion2AMI:
|
||||
us-east-1:
|
||||
Ami: ami-0cb7fff2c5966e90a
|
||||
Ami: ami-05a5422837d6014b2
|
||||
eu-west-2:
|
||||
Ami: ami-0db9fabb096af3c1a
|
||||
Ami: ami-010c13544ceeb7270
|
||||
Resources:
|
||||
IamCloudwatchRole:
|
||||
Type: AWS::IAM::Role
|
||||
Condition: ShouldEnableCloudWatch
|
||||
Properties:
|
||||
Description: jambonz mini IAM role
|
||||
RoleName: !Sub 'jambonz-mini-iam-role'
|
||||
AssumeRolePolicyDocument:
|
||||
Statement:
|
||||
- Effect: Allow
|
||||
Principal:
|
||||
Service: [ec2.amazonaws.com]
|
||||
Action: ['sts:AssumeRole']
|
||||
Path: /
|
||||
Policies:
|
||||
- PolicyName: root
|
||||
PolicyDocument:
|
||||
Version: "2012-10-17"
|
||||
Statement:
|
||||
- Effect: Allow
|
||||
Action:
|
||||
- 'cloudwatch:PutMetricData'
|
||||
- 'ec2:DescribeVolumes'
|
||||
- 'ec2:DescribeTags'
|
||||
- 'logs:PutLogEvents'
|
||||
- 'logs:DescribeLogStreams'
|
||||
- 'logs:DescribeLogGroups'
|
||||
- 'logs:CreateLogStream'
|
||||
- 'logs:CreateLogGroup'
|
||||
Resource: '*'
|
||||
- Effect: Allow
|
||||
Action:
|
||||
- 'ssm:GetParameter'
|
||||
Resource: 'arn:aws:ssm:*:*:parameter/AmazonCloudWatch-*'
|
||||
VPC:
|
||||
Type: 'AWS::EC2::VPC'
|
||||
Properties:
|
||||
@@ -87,10 +143,19 @@ Resources:
|
||||
Properties:
|
||||
VpcId: !Ref VPC
|
||||
CidrBlock: !Ref VpcCidr
|
||||
jambonzInstanceProfile:
|
||||
Type: 'AWS::IAM::InstanceProfile'
|
||||
Condition: ShouldEnableCloudWatch
|
||||
Properties:
|
||||
Path: /
|
||||
Roles:
|
||||
- !Ref IamCloudwatchRole
|
||||
jambonzInstance:
|
||||
Type: 'AWS::EC2::Instance'
|
||||
Properties:
|
||||
InstanceType: !Ref InstanceType
|
||||
IamInstanceProfile:
|
||||
!If [ShouldEnableCloudWatch, !Ref jambonzInstanceProfile, !Ref "AWS::NoValue"]
|
||||
ImageId: !FindInMap [ "AWSRegion2AMI", !Ref AWS::Region, "Ami"]
|
||||
KeyName: !Ref KeyName
|
||||
NetworkInterfaces:
|
||||
@@ -207,13 +272,26 @@ Resources:
|
||||
|
||||
sudo systemctl restart nginx
|
||||
fi
|
||||
sudo -u admin bash -c "pm2 restart /home/admin/apps/ecosystem.config.js"
|
||||
sudo -u admin bash -c "pm2 save"
|
||||
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u admin --hp /home/admin
|
||||
|
||||
# restart heplify-server
|
||||
sudo systemctl restart heplify-server
|
||||
|
||||
# enable cloudwatch
|
||||
if [[ "${Cloudwatch}" == "true" ]]; then
|
||||
echo "Enabling Cloudwatch for jambonz logs"
|
||||
sudo sed -i -e "s/retention_in_days\": 3/retention_in_days\": ${CloudwatchLogRetention}/g" /opt/aws/amazon-cloudwatch-agent/bin/config.json
|
||||
sudo /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
|
||||
else
|
||||
echo "Cloudwatch is not enabled for jambonz logs"
|
||||
sudo sed -i -e "s/combine_logs: true/combine_logs: false/g" /home/admin/apps/ecosystem.config.js
|
||||
fi
|
||||
sudo -u admin bash -c "pm2 restart /home/admin/apps/ecosystem.config.js"
|
||||
sudo -u admin bash -c "pm2 save"
|
||||
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u admin --hp /home/admin
|
||||
|
||||
- URLPortal: !Ref URLPortal
|
||||
Cloudwatch: !Ref Cloudwatch
|
||||
CloudwatchLogRetention: !Ref CloudwatchLogRetention
|
||||
|
||||
jambonzSecurityGroup:
|
||||
Type: 'AWS::EC2::SecurityGroup'
|
||||
@@ -221,11 +299,26 @@ Resources:
|
||||
VpcId: !Ref VPC
|
||||
GroupDescription: 'Allow sip, rtp, http and ssh access'
|
||||
SecurityGroupIngress:
|
||||
- Description: sip
|
||||
- Description: sip over udp
|
||||
IpProtocol: udp
|
||||
FromPort: 5060
|
||||
ToPort: 5060
|
||||
CidrIp: !Ref AllowedSipCidr
|
||||
- Description: sip over tcp
|
||||
IpProtocol: tcp
|
||||
FromPort: 5060
|
||||
ToPort: 5060
|
||||
CidrIp: !Ref AllowedSipCidr
|
||||
- Description: sip over tls
|
||||
IpProtocol: tcp
|
||||
FromPort: 5061
|
||||
ToPort: 5061
|
||||
CidrIp: !Ref AllowedSipCidr
|
||||
- Description: sip over wss
|
||||
IpProtocol: tcp
|
||||
FromPort: 8443
|
||||
ToPort: 8443
|
||||
CidrIp: !Ref AllowedSipCidr
|
||||
- Description: rtp
|
||||
IpProtocol: udp
|
||||
FromPort: 40000
|
||||
|
||||
49
packer/jambonz-mini/files/cloudwatch-config.json
Normal file
49
packer/jambonz-mini/files/cloudwatch-config.json
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"agent": {
|
||||
"run_as_user": "root"
|
||||
},
|
||||
"logs": {
|
||||
"logs_collected": {
|
||||
"files": {
|
||||
"collect_list": [
|
||||
{
|
||||
"file_path": "/home/admin/.pm2/logs/jambonz-feature-server.log",
|
||||
"log_group_name": "jambonz-feature_server",
|
||||
"log_stream_name": "feature-server {ip_address} {instance_id}",
|
||||
"retention_in_days": 3
|
||||
},
|
||||
{
|
||||
"file_path": "/home/admin/.pm2/logs/jambonz-sbc-inbound.log",
|
||||
"log_group_name": "jambonz-sbc-sip-inbound",
|
||||
"log_stream_name": "sbc-inbound {ip_address} {instance_id}",
|
||||
"retention_in_days": 3
|
||||
},
|
||||
{
|
||||
"file_path": "/home/admin/.pm2/logs/jambonz-sbc-outbound.log",
|
||||
"log_group_name": "jambonz-sbc-sip",
|
||||
"log_stream_name": "sbc-outbound {ip_address} {instance_id}",
|
||||
"retention_in_days": 3
|
||||
},
|
||||
{
|
||||
"file_path": "/home/admin/.pm2/logs/jambonz-sbc-sip-sidecar.log",
|
||||
"log_group_name": "jambonz-sbc-sip-sidecar",
|
||||
"log_stream_name": "sbc-sip-sidecar {ip_address} {instance_id}",
|
||||
"retention_in_days": 3
|
||||
},
|
||||
{
|
||||
"file_path": "/home/admin/.pm2/logs/jambonz-api-server.log",
|
||||
"log_group_name": "jambonz-api-server",
|
||||
"log_stream_name": "jambonz-api-server-{ip_address} {instance_id}",
|
||||
"retention_in_days": 3
|
||||
},
|
||||
{
|
||||
"file_path": "/var/log/syslog",
|
||||
"log_group_name": "/var/log/syslog",
|
||||
"log_stream_name": "syslog-{ip_address} {instance_id}",
|
||||
"retention_in_days": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,7 @@ module.exports = {
|
||||
cwd: '/home/admin/apps/sbc-call-router',
|
||||
script: 'app.js',
|
||||
instance_var: 'INSTANCE_ID',
|
||||
combine_logs: true,
|
||||
out_file: '/home/admin/.pm2/logs/jambonz-sbc-call-router.log',
|
||||
err_file: '/home/admin/.pm2/logs/jambonz-sbc-call-router.log',
|
||||
exec_mode: 'fork',
|
||||
@@ -102,6 +103,7 @@ module.exports = {
|
||||
instance_var: 'INSTANCE_ID',
|
||||
out_file: '/home/admin/.pm2/logs/jambonz-sbc-sip-sidecar.log',
|
||||
err_file: '/home/admin/.pm2/logs/jambonz-sbc-sip-sidecar.log',
|
||||
combine_logs: true,
|
||||
exec_mode: 'fork',
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
@@ -137,6 +139,7 @@ module.exports = {
|
||||
instance_var: 'INSTANCE_ID',
|
||||
out_file: '/home/admin/.pm2/logs/jambonz-sbc-outbound.log',
|
||||
err_file: '/home/admin/.pm2/logs/jambonz-sbc-outbound.log',
|
||||
combine_logs: true,
|
||||
exec_mode: 'fork',
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
@@ -177,6 +180,7 @@ module.exports = {
|
||||
instance_var: 'INSTANCE_ID',
|
||||
out_file: '/home/admin/.pm2/logs/jambonz-sbc-inbound.log',
|
||||
err_file: '/home/admin/.pm2/logs/jambonz-sbc-inbound.log',
|
||||
combine_logs: true,
|
||||
exec_mode: 'fork',
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
@@ -215,6 +219,7 @@ module.exports = {
|
||||
instance_var: 'INSTANCE_ID',
|
||||
out_file: '/home/admin/.pm2/logs/jambonz-sbc-rtpengine-sidecar.log',
|
||||
err_file: '/home/admin/.pm2/logs/jambonz-sbc-rtpengine-sidecar.log',
|
||||
combine_logs: true,
|
||||
exec_mode: 'fork',
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
@@ -239,6 +244,7 @@ module.exports = {
|
||||
instance_var: 'INSTANCE_ID',
|
||||
out_file: '/home/admin/.pm2/logs/jambonz-feature-server.log',
|
||||
err_file: '/home/admin/.pm2/logs/jambonz-feature-server.log',
|
||||
combine_logs: true,
|
||||
exec_mode: 'fork',
|
||||
instances: 1,
|
||||
autorestart: true,
|
||||
|
||||
18
packer/jambonz-mini/scripts/install_cloudwatch.sh
Normal file
18
packer/jambonz-mini/scripts/install_cloudwatch.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$1" == "yes" ]; then
|
||||
|
||||
#install cloudwatch
|
||||
sudo wget https://s3.amazonaws.com/amazoncloudwatch-agent/debian/amd64/latest/amazon-cloudwatch-agent.deb -O /home/admin/amazon-cloudwatch-agent.deb
|
||||
sudo dpkg -i -E /home/admin/amazon-cloudwatch-agent.deb
|
||||
sudo rm -rf /home/admin/amazon-cloudwatch-agent.deb
|
||||
|
||||
# install config file for jambonz
|
||||
sudo cp -r /tmp/cloudwatch-config.json /opt/aws/amazon-cloudwatch-agent/bin/config.json
|
||||
|
||||
|
||||
# start cloudwatch
|
||||
# should I do this in CF?
|
||||
#sudo /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
|
||||
|
||||
fi
|
||||
@@ -14,6 +14,7 @@
|
||||
"install_influxdb": "yes",
|
||||
"install_homer": "yes",
|
||||
"install_jaeger": "yes",
|
||||
"install_cloudwatch": "yes",
|
||||
"install_nodered": "no",
|
||||
"influxdb_ip": "127.0.0.1",
|
||||
"rtp_engine_version": "mr11.1.1.2",
|
||||
@@ -92,6 +93,11 @@
|
||||
"type": "shell",
|
||||
"script": "scripts/install_os_tuning.sh"
|
||||
},
|
||||
{
|
||||
"type": "shell",
|
||||
"execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `install_cloudwatch`}}",
|
||||
"script": "scripts/install_cloudwatch.sh"
|
||||
},
|
||||
{
|
||||
"type": "shell",
|
||||
"script": "scripts/install_freeswitch.sh"
|
||||
|
||||
@@ -73,6 +73,11 @@ whether or not to install influxdb and grafana.
|
||||
```
|
||||
whether or not to install homer, postgresql and telegraf.
|
||||
|
||||
```
|
||||
"install_cloudwatch": "yes"
|
||||
```
|
||||
whether or not to install cloudwatch logging for jambonz logs.
|
||||
|
||||
```
|
||||
"influxdb_ip" : "127.0.0.1"
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user