问题
I had already created 7 other metrics based on some log files I send to CloudWatch with no problems.
Some time ago we had a problem with MongoDB connection, and I identified that through logs, so I'd like to create a Metric, so that I can create an Alarm based on it. I did create the Metric, but (of course) there are no data being fed into that Metic, because no more "MongoError" messages exists.
But does that also mean that I can't even access the Metric to create the Alarm? Because this is what is happening right now. The Metric cannot be seen anywhere, only in the "Filters" section of the Logs, which won't allow me to create Alarms or create graphics or anything.
I have already posted this on AWS forums but that usually doesn't help.
回答1:
An Amazon CloudWatch custom metric is only created when data is stored against the custom metric. Therefore, you'll need to push a data value to make appear and then you will be able to create an alarm.
You can push some data to CloudWatch with the AWS Command-Line Interface (CLI), eg:
aws cloudwatch put-metric-data --namespace MongoDB --metric-name errors --value 0
来源:https://stackoverflow.com/questions/44951213/cloudwatch-custom-metrics-not-working-as-expected