【问题标题】:how to extract time difference between two requests using KUSTO如何使用 KUSTO 提取两个请求之间的时间差
【发布时间】:2019-08-14 14:21:32
【问题描述】:

我有两个 Rawdata 事件,其中一个是具有一个时间戳的请求,另一个是具有不同时间跨度的响应,是否有一个 kusto 函数可以从 rawdata 中提取这两个日期并在两者之间进行时间差

【问题讨论】:

    标签: azure-data-explorer kql


    【解决方案1】:

    是的,有。 在不查看输入数据样本的情况下为您提供最佳选择有点挑战性,但您可能想查看parse 运算符:https://docs.microsoft.com/en-us/azure/kusto/query/parseoperator,或extract() 函数:https://docs.microsoft.com/en-us/azure/kusto/query/extractfunction

    或者,在您的问题中包含一个示例输入,例如:

    print request = "this<>is!!!my-request from 2019-08-14 17:54:36.8892211, the end",
          response = "this is the matching 2019-08-14 17:55:36.0000033 response"
    | parse request with * "from " request_datetime:datetime "," *
    | parse response with * "matching " response_datetime:datetime " response"
    | project diff = response_datetime - request_datetime
    // this returns a single table with a single column named 'diff', whose value is '00:00:59.1107822'
    

    datatable(event_text:string, correlation_id:long) [
        "this<>is!!!my-request from 2019-08-14 17:54:36.8892211, the end", 1,
        "this is the matching 2019-08-14 17:55:36.0000033 response", 1,
    ]
    | extend dt = extract(@"(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{7})", 1, event_text, typeof(datetime))
    | summarize diff = max(dt) - min(dt) by correlation_id
    // this returns a single table with 2 columns named 'correlation_id' and 'diff', whose values are are '1' and '00:00:59.1107822'
    

    【讨论】:

    • 我的日期格式是这样的“ERROR 2019-08-14 10:14:18,599 4648303ms MessageInspector”
    • 以下将返回“2019-08-14 10:14:18.5990000”:print value = 'ERROR 2019-08-14 10:14:18,599 4648303ms MessageInspector' | parse value with * " " timestamp:datetime "," ms:int " " * | project timestamp + ms * 1ms
    【解决方案2】:

    Yoni 的回答向您展示了如何提取时间戳。拥有它们后,您可以使用datetime_diff 函数。假设您想知道 2 个时间戳之间有多少秒的差异:

    | extend TimeDiff = datetime_diff('second', SigninTime, EventTime)

    您可以使用此信息进行过滤。假设您只想保留这些时间戳在 20 秒内的行:

    | filter TimeDiff &lt; 20

    https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datetime-difffunction

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-08
      • 1970-01-01
      • 1970-01-01
      • 2021-07-31
      • 1970-01-01
      • 2014-10-29
      • 1970-01-01
      相关资源
      最近更新 更多