0
votes

I am new to Splunk. My goal is to optimize the API call, since that particular API method is taking more than 5 minutes to execute.

In Splunk I searched using context ID, I got all the functions and sub functions call by main API call function for that particular execution. Now I want to figure what which sub function took the maximum time. In Splunk in left side, in the list of fields, I see field name CallStartUtcTime (e.g. "2021-02-12T20:17:42.3308285Z") and CallEndUtcTime (e.g. "2021-02-12T20:18:02.3702937Z"). In search how can I write a function which will give me difference between these two times. I google and found we can use eval() function but for me its returning null value.

Additional Info:

search: context id and eval in search

clicked on "create table view" and checked start, end and diff fields in the left side fields list. but all three are coming as null

enter image description here

not sure what wrong I am doing. I want to find out the time taken by each function.

1

1 Answers

0
votes

Splunk cannot compare timestamps in string form. They must be converted to epoch (integer) form, first. Use the strptime() function for that.

...
| eval start = strptime(CallStartUtcTime, "%Y-%m-%dT%H:%M:%S.%7N%Z")
| eval end = strptime(CallEndUtcTime, "%Y-%m-%dT%H:%M:%S.%7N%Z")
| eval diff = end - start
...