Splunk Search

timechart - add some columns and values are 0

TSamon
Engager

Hello, 

Based on this Splunk Query:

 

index=* AND appid=127881 AND message="*|NGINX|*"

AND cluster != null AND namespace != null | eval server = (namespace + "@" + cluster)

| timechart span=1d count by server

Because the logs are only kept for 1 month, and in recent month, logs are only in server 127881-p@23p. So in the splunk query result, we only can see 1 column: 127881-p@23p

 

May I ask how to make the result has 3 columns: 127881-p@23p127881-p@24p, 127881-p@25p

And since there is no logs in 24p and 25p rencently, the values for 24p and 25p are 0.

 

Thanks a lot!

 

Labels (2)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

By "make the result has 3 columns," do you mean that when logs only come from less than 3 servers, you still want to display the one with no logs (with value 0)?

In that case, you must know the exact name of the three servers.  Then, use foreach to fill the values.

index=* AND appid=127881 AND message="*|NGINX|*"
  AND cluster != null AND namespace != null
| eval server = (namespace + "@" + cluster)
| timechart span=1d count by server
| foreach "127881-p@23p", "127881-p@24p", "127881-p@25p"
    [eval <<FIELD>> = if(isnull('<<FIELD>>'), 0, '<<FIELD>>')]

 

View solution in original post

Tags (1)

yuanliu
SplunkTrust
SplunkTrust

By "make the result has 3 columns," do you mean that when logs only come from less than 3 servers, you still want to display the one with no logs (with value 0)?

In that case, you must know the exact name of the three servers.  Then, use foreach to fill the values.

index=* AND appid=127881 AND message="*|NGINX|*"
  AND cluster != null AND namespace != null
| eval server = (namespace + "@" + cluster)
| timechart span=1d count by server
| foreach "127881-p@23p", "127881-p@24p", "127881-p@25p"
    [eval <<FIELD>> = if(isnull('<<FIELD>>'), 0, '<<FIELD>>')]

 

Tags (1)

TSamon
Engager

Many thanks! Yes, it is what I want, your answer is very helpful! Many thanks!

0 Karma
Get Updates on the Splunk Community!

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Your Voice Matters! Help Us Shape the New Splunk Lantern Experience

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Building Momentum: Splunk Developer Program at .conf25

At Splunk, developers are at the heart of innovation. That’s why this year at .conf25, we officially launched ...