Splunk Search

Get Percentage of Network bandwidth

tysonjhayes
Explorer

I'm looking to define a query that allows me to query the Network Interface for all my machines and create a percentage utilization for each interface. I'm having a bit of trouble with it though.

What I'm ultimately looking for is to take the TotalBytes being used on my Network Interface and divide by my current bandwidth. Basically: ((totalBytes*8)/CurrentBandwidth) * 100

I've come up with the following query but CurrentBandwidth doesn't come back with anything and I get an error that I'm interpreting to me an I'm dividing by zero.

index=index host=host object="Network Interface" counter="Bytes Total/sec"
    | bucket _time span=1m
    | stats avg(Value) as bytesByHost by _time,host
    | stats sum(bytesByHost) as totalBytes by _time
    | append [search index=index host=host object="Network Interface" counter="Current Bandwidth" instance!="isatap.*"
        | bucket _time span=1m 
        | stats avg(Value) as connsByHost by _time | stats sum(connsByHost) as CurrentBandwidth by _time ]
    | stats exact(((totalBytes*8)/CurrentBandwidth) * 100)

Error: Error in 'stats' command: The argument 'exact(((totalBytes*8)/CurrentBandwidth) * 100)' is invalid.

Any assistance would be greatly appreciated.

0 Karma
1 Solution

stephanefotso
Motivator

Exact(X) is a function for Eval and Where

Try

 index=index host=host object="Network Interface" counter="Bytes Total/sec"
     | bucket _time span=1m
     | stats avg(Value) as bytesByHost by _time,host
     | stats sum(bytesByHost) as totalBytes by _time
     | append [search index=index host=host object="Network Interface" counter="Current Bandwidth" instance!="isatap.*"
         | bucket _time span=1m 
         | stats avg(Value) as connsByHost by _time | stats sum(connsByHost) as CurrentBandwidth by _time ]
     | eval total= exact(totalBytes*8/CurrentBandwidth * 100)
 | stats  values(total)
SGF

View solution in original post

woodcock
Esteemed Legend
0 Karma

tysonjhayes
Explorer

Thanks! That's been corrected.

0 Karma

stephanefotso
Motivator

Exact(X) is a function for Eval and Where

Try

 index=index host=host object="Network Interface" counter="Bytes Total/sec"
     | bucket _time span=1m
     | stats avg(Value) as bytesByHost by _time,host
     | stats sum(bytesByHost) as totalBytes by _time
     | append [search index=index host=host object="Network Interface" counter="Current Bandwidth" instance!="isatap.*"
         | bucket _time span=1m 
         | stats avg(Value) as connsByHost by _time | stats sum(connsByHost) as CurrentBandwidth by _time ]
     | eval total= exact(totalBytes*8/CurrentBandwidth * 100)
 | stats  values(total)
SGF

tysonjhayes
Explorer

Tried your function and while I'm not getting the error anymore (thanks!) I'm not getting any data for total. It still looks like CurrentBandwidth is null.

When I run the appended search by itself I'm getting results but put it in the append I'm getting nothing...

0 Karma

stephanefotso
Motivator

Try this

  index=index host=host object="Network Interface" counter="Bytes Total/sec"
          | bucket _time span=1m
          | stats avg(Value) as bytesByHost by _time,host
          | stats sum(bytesByHost) as totalBytes by _time
          | append [search index=index host=host object="Network Interface" counter="Current Bandwidth" instance!="isatap.*"
              | bucket _time span=1m 
              | eventstats avg(Value) as connsByHost by _time | stats sum(connsByHost) as CurrentBandwidth by _time ]
          | eval total= exact(totalBytes*8/CurrentBandwidth * 100)
      | stats  values(total)
SGF

tysonjhayes
Explorer

Still getting null or 0 on CurrentBandwidth. The query by itself is producing results though. I'm checking it by running the query in the brackets by itself (seeing the results), then I tried taking everything before the eval and doing a | table CurrentBandwidth (seeing rows with no data). Thanks for your assistance thus far!

0 Karma

stephanefotso
Motivator

I now understand. I thing the problem should be the appen command. Change appen and try use apppencols or join. Something like this, with appendcols:

 index=index host=host object="Network Interface" counter="Bytes Total/sec"
      | bucket _time span=1m
      | stats avg(Value) as bytesByHost by _time,host
      | stats sum(bytesByHost) as totalBytes by _time
      | appendcols [search index=index host=host object="Network Interface" counter="Current Bandwidth" instance!="isatap.*"
          | bucket _time span=1m 
          | stats avg(Value) as connsByHost by _time | stats sum(connsByHost) as CurrentBandwidth by _time ]
      | eval total= exact(totalBytes*8/CurrentBandwidth * 100)
  | stats  values(total)
SGF

tysonjhayes
Explorer

Brilliant! That works! Now, what is apppencols? I'm not seeing any documentation on it, or I'm missing something super obivous.

0 Karma

stephanefotso
Motivator
0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...