Issue
i am trying to send apache metrics to cloudwatch using apache prometheus exporter. https://github.com/Lusitaniae/apache_exporter#collectors
i am able to get some metrics to cloudwatch however some metrics are not populating in cloudwatch.
below is the Cloudwatch json file used to get the data.
{"logs":{"logs_collected":null,"metrics_collected":{"prometheus":{"cluster_name":"prometheus-apache","log_group_name":"Prometheus-apache","prometheus_config_path":"/opt/aws/amazon-cloudwatch-agent/apache_prometheus_config.yaml","emf_processor":{"metric_declaration_dedup":true,"metric_namespace":"Apache","metric_unit":{"apache_accesses_total":"Count","apache_cpuload":"Percent","apache_up":"Count","apache_sent_kilobytes_total":"Bytes","apache_workers{state=/"busy/"}":"Count"},"metric_declaration":[{"source_labels":["job"],"label_matcher":"^httpd$","dimensions":[["InstanceId","ComponentName"],["ComponentName"]],"metric_selectors":["^apache_accesses_total$","^apache_cpuload$","^apache_up$","^apache_sent_kilobytes_total$","^apache_workers{state=/"busy/"}$"]}]}}}},"metrics":{"append_dimensions":{"InstanceId":"${aws:InstanceId}","AutoScalingGroupName":"${aws:AutoScalingGroupName}"},"metrics_collected":{"disk":{"measurement":[{"name":"used_percent","unit":"Percent"}],"metrics_collection_interval":60,"resources":["*"]},"mem":{"measurement":[{"name":"used_percent","unit":"Percent"}],"metrics_collection_interval":60,"resources":["*"]}},"aggregation_dimensions":[["AutoScalingGroupName"]]}}
from the above json , i am not able to get below metric.
"apache_workers{state=/"busy/"}":"Count" "^apache_workers{state=/"busy/"}$"
Solution
I was able to push the apache metrics to cloudwatch using shell scripts.
below is the script i used.
#!/bin/bash
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`
instanceid=`curl --write-out "\n" --request GET "http://169.254.169.254/latest/meta-data/instance-id" --header "X-aws-ec2-metadata-token: $TOKEN"`
azone=`curl --write-out "\n" --request GET "http://169.254.169.254/latest/meta-data/placement/availability-zone" --header "X-aws-ec2-metadata-token: $TOKEN"`
ipaddress=`curl --write-out "\n" --request GET "http://169.254.169.254/latest/meta-data/local-ipv4" --header "X-aws-ec2-metadata-token: $TOKEN"`
region=${azone/%?/}
export AWS_DEFAULT_REGION=$region
echo $azone
echo $instanceid
echo $region
#echo $ipaddress
busywrokers=`wget -q -O - http://localhost/mod_status?auto | grep BusyWorkers | awk '{ print $2 }'`
echo $busywrokers
idlewrokers=`wget -q -O - http://localhost/mod_status?auto | grep IdleWorkers | awk '{ print $2 }'`
echo $idlewrokers
totalrequest=`wget -q -O - http://localhost/mod_status?auto | grep 'Total Accesses' | awk '{ print $3 }'`
echo $totalrequest
totalKbytes=`wget -q -O - http://localhost/mod_status?auto | grep 'Total kBytes' | awk '{ print $3 }'`
echo $totalKbytes
cpusystem=`wget -q -O - http://localhost/mod_status?auto | grep 'CPUSystem' | awk '{ print $2 }'`
echo $cpusystem
cpuload=`wget -q -O - http://localhost/mod_status?auto | grep 'CPULoad' | awk '{ print $2 }'`
echo $cpuload
/usr/local/bin/aws cloudwatch put-metric-data --metric-name "apache-BusyWorkers" --unit Count --value $busywrokers --dimensions InstanceId=$instanceid --namespace Apache
/usr/local/bin/aws cloudwatch put-metric-data --metric-name "apache-IdleWorker" --unit Count --value $idlewrokers --dimensions InstanceId=$instanceid --namespace Apache
/usr/local/bin/aws cloudwatch put-metric-data --metric-name "apache-TotalRequest" --unit Count --value $totalrequest --dimensions InstanceId=$instanceid --namespace Apache
/usr/local/bin/aws cloudwatch put-metric-data --metric-name "apache-TotalKbytes" --unit Kilobytes --value $totalKbytes --dimensions InstanceId=$instanceid --namespace Apache
/usr/local/bin/aws cloudwatch put-metric-data --metric-name "apache-CPUSystem" --unit Percent --value $cpusystem --dimensions InstanceId=$instanceid --namespace Apache
/usr/local/bin/aws cloudwatch put-metric-data --metric-name "apache-CPULoad" --unit Percent --value $cpuload --dimensions InstanceId=$instanceid --namespace Apache
Answered By - Jijo John Answer Checked By - Terry (WPSolving Volunteer)