Splunk Search

How do I timechart the percentage of a total?

jrnastase
Explorer

Hello all,

Currently I have acquired a timechart in the format:

Field_A / Field_B / Field_C / Field_D / Total
//// 10 ///////// 20 ///////// 15 ////////// 5 //////// 50
etc. using the | addtotals command.

I would like to somehow change each column to represent a percentage of the total to wind up with something like:
Field_A / Field_B / Field_C / Field_D
//// 0.2 //////// 0.4 //////// 0.3 ///////// 0.1

Thanks very much. Any help would be greatly appreciated!

Tags (1)
0 Karma

adonio
Ultra Champion

hello there,

there are many ways to achieve, if you keep naming convention, maybe try the foreach command. here is one example with eval to create desired values. run this search anywhere:

| gentimes start="10/15/2018:00:00:00" end="10/15/2018:10:00:00" increment=15min
| eval _time = starttime 
| eval field_a = random()%100
| eval field_b = random()%100
| eval field_c = random()%100
| eval field_d = random()%100
| eval total = field_a + field_b + field_c + field_d
| table _time field* total
| rename COMMENT as "the above creates data, below is the solution"
| eval field_a_perc = round(field_a/total*100, 2)
| eval field_b_perc = round(field_b/total*100, 2)
| eval field_c_perc = round(field_c/total*100, 2)
| eval field_d_perc = round(field_d/total*100, 2)
| timechart span=15m max(field_a_perc) as field_a_perc max(field_b_perc) as field_b_perc max(field_c_perc) as field_c_perc max(field_d_perc) as field_d_perc

screenshot:

alt text

hope it helps

0 Karma
Get Updates on the Splunk Community!

Starting With Observability: OpenTelemetry Best Practices

Tech Talk Starting With Observability: OpenTelemetry Best Practices Tuesday, October 17, 2023   |  11AM PST / ...

.conf23 | Get Your Cybersecurity Defense Analyst Certification in Vegas

We’re excited to announce a new Splunk certification exam being released at .conf23! If you’re going to Las ...

Streamline Data Ingestion With Deployment Server Essentials

REGISTER NOW! Every day the list of sources Admins are responsible for gets bigger and bigger, often making ...