Deployment Architecture

How to calculate the tota runtime from different logs?

tchintam
Path Finder

I have 100+ logs in my path say /abv/xyz/(All my logs). Each of the logs has the line: The total runtime is "zy" sec. (Example). How do I calculate the sum of all the runtime from different logs?

0 Karma
1 Solution

FrankVl
Ultra Champion

Step 1: extract the runtime value into a field (e.g. the field runtime)
Step 2: run a search that sums the values of that field:

...your base search...
| stats sum(runtime) as TotalRuntime

If you need help with step 1, please provide an actual data sample, so we can provide suggestions for how to extract that.

View solution in original post

FrankVl
Ultra Champion

Step 1: extract the runtime value into a field (e.g. the field runtime)
Step 2: run a search that sums the values of that field:

...your base search...
| stats sum(runtime) as TotalRuntime

If you need help with step 1, please provide an actual data sample, so we can provide suggestions for how to extract that.

tchintam
Path Finder

Hi Frank,

Each log has this line: The total runtime is 120 seconds.

Time varies from log to log though.

So, I would need to extract the time from there and sum the total. How do I do that?

Also, adding on, my doubt is, how do I go inside the log each time? There are 100+ logs. Only inside the log do I get the runtime.

0 Karma

FrankVl
Ultra Champion

You have those logs available in Splunk, right? Or is that also still something you need to accomplish first?

Assuming the logs are in splunk, with let's say index=foo and sourcetype=bar, you can run the following search.

index=foo sourcetype=bar
| rex "runtime\s+is\s+(?<runtime>\d+)"
| stats sum(runtime) as TotalRuntime

If you have this working, you can think about storing that field extraction permanently, such that it gets applied automatically to these logs and you don't have add that rex command any longer.

Get Updates on the Splunk Community!

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

Splunk Decoded: Business Transactions vs Business IQ

It’s the morning of Black Friday, and your e-commerce site is handling 10x normal traffic. Orders are flowing, ...

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...