Splunk Search

Overcome truncated result for timeseries chart

anujtripathi_04
Explorer

Hi guys,

I'm currently facing an issue. I have csv logs being ingested every 1 min with the status of some services - either "Running" or "Stopped".
What I want is to show the trend on timeseries chart.

The query I am using is:

index="main" host="xyz_hostname" | where(Service_Name="xyz") | sort by Timestamp desc | dedup Timestamp | dedup Service_Status |reverse | table Timestamp, Service_Status | eval Service_Status=if(Service_Status=="Running", 1, Service_Status), Service_Status=if(Service_Status=="Stopped", 0, Service_Status)

Timeseries visualization works fine when I select a short time range but when I select a range like "last 30 days", I get "These results may be truncated. This visualization is configured to display a maximum of 10000 results per series, and that limit has been reached"

I know I can modify the chart config to accomodate the output put I want to modify my search so that it doesn't takes the points where the status is "Stopped" repeatedly for hours. Inspite if it can only take the timestamp when the status changed from "Running" to "Stopped" or vice-versa.

Can someone help me write such search query?

Tags (1)
0 Karma

nickhills
Ultra Champion

If you set '_time' as your timestamp, you can then use the timechart which allows you to use span, (or you could use 'bin _time span' but try this first)

index="main" host="xyz_hostname" | where(Service_Name="xyz") | dedup Timestamp |eval _time=strptime(Timestamp, "%Y-%m-%d %H:%M:%S") | eval Service_Status=if(Service_Status=="Running", 1, 0)|timechart count by Service_Status span=5m

You also don't need two if statements. If there are more options than running/stopped then use 'case'

index="main" host="xyz_hostname" | where(Service_Name="xyz") | dedup Timestamp |eval _time=strptime(Timestamp, "%Y-%m-%d %H:%M:%S") | eval Service_Status=case(Service_Status=="Running",1,Service_Status=="Stopped",0, Service_Status="SOMETHINGELSE",3)|timechart count by Service_Status span=5m
If my comment helps, please give it a thumbs up!

anujtripathi_04
Explorer

Thanks, this does help me but I wanted to have a graph showing just 0 or 1, meaning if the service was running or not. May be I wasn't clear enough in the original question.

Anyway your search query led me to refine more and I am now able to achieve it with:

index="main" host="abc" | where(Service_Name="$clickedServiceName$") | dedup Timestamp 
| reverse |eval _time=strptime(Timestamp, "%Y-%m-%d %H:%M:%S") | eval run=if(Service_Status=="Running", 1, 0)
| timechart span=5m min(run) as Min max(run) as Max | eval serviceRunning=(Min+Max)/2 | filldown serviceRunning | fields _time serviceRunning| where serviceRunning != 0.5

alt text

0 Karma

nickhills
Ultra Champion

is 'Timestamp' an Epoch time? If not, can you post the time format it uses?

If my comment helps, please give it a thumbs up!
0 Karma

anujtripathi_04
Explorer

The format is "2019-03-26 15:14:02"

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!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...