<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to find percentage? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-to-find-percentage/m-p/543962#M154083</link>
    <description>&lt;P&gt;Hi, can you post a data sample. I still think the previous lines with that stats and dedup are causing the problem. Just run something like this and post a few lines if possible:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;((index=71412-cli sourcetype=show_interface) OR (index=71412-np sourcetype=device_details)) deviceName ="BLV2-TI-SW_WAS18-01"
| table deviceId interface deviceName adminStatus&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Mar 2021 08:54:21 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2021-03-16T08:54:21Z</dc:date>
    <item>
      <title>how to find percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-find-percentage/m-p/543952#M154079</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/215385"&gt;@dmarling&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I Have a doubt in calculating the percentage.&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;First query:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;(index=71412-cli sourcetype=show_interface) OR (index=71412-np sourcetype=device_details)&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;| stats values(*) as * by deviceId&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;|search deviceName ="BLV2-TI-SW_WAS18-01" &lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;|dedup interface&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;| table deviceId interface deviceName adminStatus&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;| sort interface | stats count(interface) as "Total no of ports"&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from the first query I'm fetching the total no of interface&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;second query&lt;/U&gt;&lt;BR /&gt;&lt;EM&gt;(index=71412-cli sourcetype=show_interface adminStatus="down") OR (index=71412-np sourcetype=device_details)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| stats values(*) as * by deviceId&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;|search deviceName ="BLV2-TI-SW_WAS18-01" &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;|search adminStatus=down&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;|dedup interface&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| table deviceId interface deviceName adminStatus&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;| sort interface | stats count(interface) as "Down ports"&lt;/EM&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;from the second query I'm fetching only the interfaces which are admin down&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;I want to find the percentage of (Down ports/Total no of ports) * 100.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;please help me in finding the percentage by appending these two queries&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;thanks,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;priya&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 07:53:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-find-percentage/m-p/543952#M154079</guid>
      <dc:creator>priyastalin</dc:creator>
      <dc:date>2021-03-16T07:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to find percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-find-percentage/m-p/543954#M154080</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/229747"&gt;@priyastalin&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;You could do something like this (not tested by the way):&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(index=71412-cli sourcetype=show_interface) OR (index=71412-np sourcetype=device_details)
| stats values(*) as * by deviceId
| search deviceName ="BLV2-TI-SW_WAS18-01"
| dedup interface
| table deviceId interface deviceName adminStatus
| sort interface
| stats
    count(interface) as "Total no of ports"
    count(eval(if(adminStatus="down", interface, null()))) as "Down ports"
| eval percDownPorts = ('Down ports' /' Total no of ports' )* 100&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Keep an eye on that previous stats and dedup you are performing though and ensure that is not removing valid events for your totals calculations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;J&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 08:11:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-find-percentage/m-p/543954#M154080</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2021-03-16T08:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to find percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-find-percentage/m-p/543955#M154081</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for you input&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Total no of ports&amp;nbsp; &amp;nbsp; &amp;nbsp;Down ports&amp;nbsp; &amp;nbsp; percDownPorts&lt;/P&gt;&lt;P&gt;599&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;599&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&lt;/P&gt;&lt;P&gt;its giving the correct total no of ports but down ports count is 234 is giving wrong value for down ports..&lt;BR /&gt;is there any other way to fetch the output&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 08:18:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-find-percentage/m-p/543955#M154081</guid>
      <dc:creator>priyastalin</dc:creator>
      <dc:date>2021-03-16T08:18:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to find percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-find-percentage/m-p/543958#M154082</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/113132"&gt;@javiergn&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for you input&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Total no of ports&amp;nbsp; &amp;nbsp; &amp;nbsp;Down ports&amp;nbsp; &amp;nbsp; percDownPorts&lt;/P&gt;&lt;P&gt;599&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;599&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&lt;/P&gt;&lt;P&gt;its giving the correct total no of ports but down ports count is 234 is giving wrong value for down ports..&lt;BR /&gt;is there any other way to fetch the output&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 08:26:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-find-percentage/m-p/543958#M154082</guid>
      <dc:creator>priyastalin</dc:creator>
      <dc:date>2021-03-16T08:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to find percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-find-percentage/m-p/543962#M154083</link>
      <description>&lt;P&gt;Hi, can you post a data sample. I still think the previous lines with that stats and dedup are causing the problem. Just run something like this and post a few lines if possible:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;((index=71412-cli sourcetype=show_interface) OR (index=71412-np sourcetype=device_details)) deviceName ="BLV2-TI-SW_WAS18-01"
| table deviceId interface deviceName adminStatus&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 08:54:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-find-percentage/m-p/543962#M154083</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2021-03-16T08:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to find percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-find-percentage/m-p/543983#M154087</link>
      <description>&lt;P&gt;In order to know the amount of down ports as compared to the total ports and assuming the show_interface sourcetype is a streaming input of the interface's status, you will need to obtain the latest status of each interface before you calculate a rate.&amp;nbsp; Your current query is passing in the values of all fields and then deduping, but values returns it in lexicographical order, not time order.&amp;nbsp; This will produce inaccurate results.&amp;nbsp; This is my suggestion to accomplish what you are looking for in a single query:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;(index=71412-cli sourcetype=show_interface) OR (index=71412-np sourcetype=device_details) 
| eventstats values(deviceName) as deviceName by deviceId 
| stats latest(adminStatus) as adminStatus values(deviceName) as deviceName by deviceId interface 
| search deviceName ="BLV2-TI-SW_WAS18-01" 
| eval rate=if(adminStatus="down", 1, 0) 
| stats avg(rate) as "Down Rate" count(eval(adminStatus="down")) as "Down ports" count as "Total no of ports" by deviceName deviceId
| eval "Down Rate"='Down Rate'*100&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Line 2 is just appending in the deviceName from the device_details sourcetype to the show_interface sourcetype events so we can have that information when we use stats on line 3 to provide the latest adminStatus of each interface.&amp;nbsp; This could also be accomplished with a join after the stats line instead, but I tend to avoid joins if at all possible.&amp;nbsp; Once the latest adminStatus is obtained from line three you can apply your deviceName filter and create a "rate" field that is assigning a 1 or a 0 depending on if the latest adminStatus that returns is down or not.&amp;nbsp; Finally on line 6 you can average the "rate" field we crated on line 5 and also count the down and total ports on each device.&amp;nbsp; Line 7 is unnecessary but makes the percentage a bit easier to consume in my opinion.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 12:22:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-find-percentage/m-p/543983#M154087</guid>
      <dc:creator>dmarling</dc:creator>
      <dc:date>2021-03-16T12:22:49Z</dc:date>
    </item>
  </channel>
</rss>

