Splunk Search

Why is TimeChart assigning values from spanned table?

michaelhaedt
Explorer

Hello All,

I have a really simple search, while it works, I'd like to do some operations on that data:

 

 

index=xxxx

earliest=-2w@w0 latest=@w6@d+24h

| timechart span=7d count(response_time)

 

 

Output is 

2022-03-13                          3,xxx,xxx

2022-03-20                            3,xxx.xxx

The deal is, I'd really like to have those seperate outputs as variables like Week1 and Week2. This way I could do some operations to see my sites volume week to week change so I can normalize error data. Hopefully this makes sense.

Labels (1)
Tags (1)
0 Karma
1 Solution

VatsalJagani
SplunkTrust
SplunkTrust

Try this query:

index=xxx earliest=-2w@w0 latest=@w6@d+24h
| timechart span=7d count(response_time)
| streamstats count as week_num
| eval Week="Week".week_num | fields - week_num, _time, _span
| transpose header_field="Week"

 

transpose command should be able to do what you are looking for.

View solution in original post

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

Try this:

index=xxx earliest=-2w@w0 latest=@w6@d+24h
| timechart span=7d count(response_time)
| streamstats count as week_num
| eval Week="Week ".week_num | fields - week_num, _time

 

Kindly accept the answer if it gives resolution.

0 Karma

michaelhaedt
Explorer

So that gives me a very similar output to what I have, which I need to have variables assigned the count(response_time) of each of the weeks. I like how this solution put it into one search and not an appended search though, very clever, I'd love to know how it works.

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

With streamstats you can assign the numbers to your results and then with eval I'm just appending that number to "Week ".

This works because proper ordering and missing values of _time series will already be handled by timechart command.

0 Karma

michaelhaedt
Explorer

Thanks for the explanation! I still need a way to assign the counts of Week 1 and 2 to  variables so I can start to manipulate the data.

Tags (1)
0 Karma

VatsalJagani
SplunkTrust
SplunkTrust
Can you please explain by posting your current output and explain what change you are looking for?
0 Karma

michaelhaedt
Explorer

Below is my data: I need to be able to assign the data to a variable like Week1Data = 1160516 and Week2Data = 3488119

This seems really easy, but I don't know how to logically address the data in the table to do an Eval 

11160516Week 1
23488119Week 2
Tags (1)
0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

Try this query:

index=xxx earliest=-2w@w0 latest=@w6@d+24h
| timechart span=7d count(response_time)
| streamstats count as week_num
| eval Week="Week".week_num | fields - week_num, _time, _span
| transpose header_field="Week"

 

transpose command should be able to do what you are looking for.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Supercharging Windows Security Detection Performance: Introducing Hybrid Field ...

Windows event logs—from Security auditing and Sysmon to PowerShell script blocks—form the operational backbone ...

Ditch the Manual Grind: Building AI Agents with Splunk

Ditch the Manual Grind: Building AI Agents with Splunk Let’s be real: your team’s time is being eaten alive. ...

Cisco Data Fabric from Architecture to Investigation, Better SOC Visibility, and More ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...