Saturday, 10 August 2024

miss

 cloudwatch to send data from systemctl directly



nohup bash -c 'while true; do journalctl -u redpanda -f -o cat | aws logs put-log-events --log-group-name "redpanda-logs" --log-stream-name "$(hostname)-redpanda" --region <your-region> --log-events "[{\"timestamp\":$(date +%s000),\"message\":\"$(journalctl -u redpanda -n 1 -o cat)\"}]" ; sleep 5; done' >/dev/null 2>&1 &

aws ssm put-parameter --name "/cloudwatch/nohup_redpanda" \
  --type "String" \
  --value 'nohup bash -c "
    aws logs create-log-group --log-group-name redpanda-logs --region <your-region> 2>/dev/null;
    aws logs create-log-stream --log-group-name redpanda-logs --log-stream-name $(hostname)-redpanda --region <your-region> 2>/dev/null;
    while true; do 
      journalctl -u redpanda -f -o cat | aws logs put-log-events --log-group-name redpanda-logs --log-stream-name $(hostname)-redpanda --region <your-region> --log-events [{\"timestamp\":$(date +%s000),\"message\":\"$(journalctl -u redpanda -n 1 -o cat)\"}]; 
      sleep 5; 
    done
  " >/dev/null 2>&1 &' \
  --overwrite


nohup $(aws ssm get-parameter --name "/cloudwatch/nohup_redpanda" --query "Parameter.Value" --output text) &


nohup bash -c '
AWS_REGION="<your-region>"
LOG_GROUP="redpanda-logs"
LOG_STREAM="$(hostname)-redpanda"

aws logs create-log-group --log-group-name "$LOG_GROUP" --region "$AWS_REGION" 2>/dev/null
aws logs create-log-stream --log-group-name "$LOG_GROUP" --log-stream-name "$LOG_STREAM" --region "$AWS_REGION" 2>/dev/null

while true; do
  LOG_MESSAGE=$(journalctl -u redpanda -n 1 -o cat)
  TIMESTAMP=$(date +%s000)
  aws logs put-log-events --log-group-name "$LOG_GROUP" --log-stream-name "$LOG_STREAM" --region "$AWS_REGION" --log-events "[{\"timestamp\":$TIMESTAMP,\"message\":\"$LOG_MESSAGE\"}]"
  sleep 5
done
' >/dev/null 2>&1 &

No comments:

Post a Comment