Need help with AWS cloudwatch log insight query

0

I am storing a message in a log stream of aws. For a particular time interval these are the 2 logs on which I need to write a query which I will run on log insight.

logs on which the query will run

I want to write a query which will return the differnce of time stamps(in minutes) between (finished at field from pipeline_2) & (started at field from pipeline_1)

Note: time stamps are in this format (2023-04-14T19:10:47.494-05:00), in order to make the logs compact I removed micro seconds and the timezone

I have tried to calculate both these values individually by running 2 different scripts but unable to achieve that, I see a very limited options with aws log insight and also I am not an expert at it, please help

1개 답변
0

You could write a python or other script in Lambda or off platform to query the cloud watch logs and then do the calculation between the two timestaps.

def lambda_handler(event, context):
    client = boto3.client('logs')

    # Specify your log groups
    log_group1 = '/aws/lambda/your_lambda_function1'
    log_group2 = '/aws/lambda/your_lambda_function2'

....... other code


response1 = client.start_query(
        logGroupName=log_group1,
        startTime=start_timestamp,
        endTime=end_timestamp,
        queryString='fields @timestamp, @message | sort @timestamp desc',
    )

.... query other log....

calculate difference in time stamps
profile picture
JFoxUK
답변함 일 년 전
  • Thankyou for the suggestion, sure I will try that. I guess doing it from the query will be easier, if you have a way to do it from query itself please let me know

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠