Reputation: 951
Alright, so I'm having some trouble finding any clear resources on what I'm trying to do.
Currently I am using the AWS CLI to send custom log events to Cloudwatch, and I have the log groups subscribed to ElasticSearch, for monitoring in Kibana. I'm using a bash script, and sending a JSON string to Cloudwatch. Simple use case, end up making a call like this :
aws logs put-log-events --log-group-name "${groupname}" --log-stream-name "${streamname}" --log-events "[{\"timestamp\":${logtimestamp},\"message\":\"${timestamp} {\\\"metric1\\\":\\\"${value1}\\\",\\\"metric2\\\":\\\"${value2}\\\"}]"
For readability, I'm sending JSON like this :
[
{
"timestamp":${logtimestamp},
"message":"${timestamp {\"metric1\":\"${value1}\",\"metric2\":\"${value2}\"}"
}
]
The serialized JSON in the "message" field is what's picked up by the ElasticSearch subscription and used to create graphs in Kibana. This is clearly not a clean solution, so I want to move to the AWS Java SDK.
I'm having a rough time finding a definitive resource on how to use the AWS Java SDK to send logs to Cloudwatch. I'm also confused when in the Cloudwatch docs it's all about "alarms" - I just want to send some JSON to Cloudwatch like I'm doing with the CLI.
Any pointers to some resources for similar use cases?
Upvotes: 1
Views: 3934
Reputation: 26031
CloudWatch Metrics and Alarms and CloudWatch Logs are effectively two separate sets of services that are both branded as CloudWatch. As you've probably noticed, in the AWS CLI the commands for CloudWatch Logs are grouped under the logs
service, rather than the cloudwatch
service.
This distinction is also true in the AWS Java SDK -- the java client to access CloudWatch Logs APIs is AWSLogsClient instead of the CloudWatch client.
To create a new log group, use createLogGroup.
To create a new log stream for a log group, use createLogStream.
To write a new log to a log group, use putLogEvents.
Upvotes: 5