通过 Prometheus 到 cloudwatch 的 Apache 指标
Apache metrics to cloudwatch via Prometheus
我正在尝试使用 apache prometheus exporter 将 apache 指标发送到 cloudwatch。 https://github.com/Lusitaniae/apache_exporter#collectors
我能够获得一些指标到 cloudwatch,但是有些指标没有填充到 cloudwatch 中。
下面是用于获取数据的 Cloudwatch json 文件。
{"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"]]}}
根据上面的 json ,我不能低于指标。
"apache_workers{状态=/"忙/"}":"计数"
"^apache_workers{state=/"忙/"}$"
我能够使用 shell 脚本将 apache 指标推送到 cloudwatch。
下面是我使用的脚本。
#!/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 }'`
echo $busywrokers
idlewrokers=`wget -q -O - http://localhost/mod_status?auto | grep IdleWorkers | awk '{ print }'`
echo $idlewrokers
totalrequest=`wget -q -O - http://localhost/mod_status?auto | grep 'Total Accesses' | awk '{ print }'`
echo $totalrequest
totalKbytes=`wget -q -O - http://localhost/mod_status?auto | grep 'Total kBytes' | awk '{ print }'`
echo $totalKbytes
cpusystem=`wget -q -O - http://localhost/mod_status?auto | grep 'CPUSystem' | awk '{ print }'`
echo $cpusystem
cpuload=`wget -q -O - http://localhost/mod_status?auto | grep 'CPULoad' | awk '{ print }'`
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
我正在尝试使用 apache prometheus exporter 将 apache 指标发送到 cloudwatch。 https://github.com/Lusitaniae/apache_exporter#collectors
我能够获得一些指标到 cloudwatch,但是有些指标没有填充到 cloudwatch 中。
下面是用于获取数据的 Cloudwatch json 文件。
{"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"]]}}
根据上面的 json ,我不能低于指标。
"apache_workers{状态=/"忙/"}":"计数" "^apache_workers{state=/"忙/"}$"
我能够使用 shell 脚本将 apache 指标推送到 cloudwatch。
下面是我使用的脚本。
#!/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 }'`
echo $busywrokers
idlewrokers=`wget -q -O - http://localhost/mod_status?auto | grep IdleWorkers | awk '{ print }'`
echo $idlewrokers
totalrequest=`wget -q -O - http://localhost/mod_status?auto | grep 'Total Accesses' | awk '{ print }'`
echo $totalrequest
totalKbytes=`wget -q -O - http://localhost/mod_status?auto | grep 'Total kBytes' | awk '{ print }'`
echo $totalKbytes
cpusystem=`wget -q -O - http://localhost/mod_status?auto | grep 'CPUSystem' | awk '{ print }'`
echo $cpusystem
cpuload=`wget -q -O - http://localhost/mod_status?auto | grep 'CPULoad' | awk '{ print }'`
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