<?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: FileSize to human readable in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106549#M27708</link>
    <description>&lt;P&gt;Found the issue, the definition needs to be:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;eval kilobytes=($fs$/1024) | eval megabytes=kilobytes/1024 |eval gigabytes=megabytes/1024&lt;CODE&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jul 2013 16:58:45 GMT</pubDate>
    <dc:creator>tb5821</dc:creator>
    <dc:date>2013-07-25T16:58:45Z</dc:date>
    <item>
      <title>Does Splunk have an easier way to get FileSize to human readable format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106542#M27701</link>
      <description>&lt;P&gt;I'm surprised splunk doesn't have an easier way to get a human readable format by passing it the field you want it to work its magic on al-la du -h&lt;/P&gt;
&lt;P&gt;So here's my question, I have a field called fs which is file size but its in bytes. I want to convert that to the proper Kb,Mb,Gb format... whats the best way to do this?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Feb 2023 23:17:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106542#M27701</guid>
      <dc:creator>tb5821</dc:creator>
      <dc:date>2023-02-05T23:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: FileSize to human readable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106543#M27702</link>
      <description>&lt;P&gt;I have this setup. You can put it into &lt;CODE&gt;$SPLUNK_HOME/etc/system/local/props.conf&lt;/CODE&gt; and it should work. You may want to have your field called "b" or "bytes" for it to work, or change the config to match your fields. This will auto-calculate kilos, megas and gigas automatically.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;[host::*]&lt;BR /&gt;
priority = 100&lt;BR /&gt;
EVAL-kilobytes = if(isnotnull(kilobytes),kilobytes,bytes/1024)&lt;BR /&gt;
EVAL-megabytes = if(isnotnull(megabytes),megabytes,bytes/1024/1024)&lt;BR /&gt;
EVAL-gigabytes = if(isnotnull(gigabytes),gigabytes,bytes/1024/1024/1024)&lt;BR /&gt;
EVAL-kb = if(isnotnull(kb),kb,b/1024)&lt;BR /&gt;
EVAL-mb = if(isnotnull(mb),mb,b/1024/1024)&lt;BR /&gt;
EVAL-gb = if(isnotnull(gb),gb,b/1024/1024/1024)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;You can also use a macro (in the Search UI):&lt;BR /&gt;
 Manager -&amp;gt; Advanced Search -&amp;gt; Search Macros&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;Name: resize(1)&lt;BR /&gt;
Arguments: bytes&lt;BR /&gt;
definition = eval kilobytes = $bytes$/1024| eval megabytes=kilobytes/1024|eval gigabytes/1024&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Then you can do &lt;CODE&gt;your_search | &lt;CODE&gt;resize(fs)&lt;/CODE&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2013 15:38:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106543#M27702</guid>
      <dc:creator>alacercogitatus</dc:creator>
      <dc:date>2013-07-25T15:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: FileSize to human readable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106544#M27703</link>
      <description>&lt;P&gt;Can I do it in search? I don't have access to anything but the search UI&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2013 15:43:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106544#M27703</guid>
      <dc:creator>tb5821</dc:creator>
      <dc:date>2013-07-25T15:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: FileSize to human readable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106545#M27704</link>
      <description>&lt;P&gt;See my edit. You will need backticks around "resize(fs)". The answer system stripped them for me.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2013 15:49:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106545#M27704</guid>
      <dc:creator>alacercogitatus</dc:creator>
      <dc:date>2013-07-25T15:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: FileSize to human readable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106546#M27705</link>
      <description>&lt;P&gt;Error in 'SearchParser': Missing a search command before '''.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;...| 'resize(fs)'&lt;CODE&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2013 15:57:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106546#M27705</guid>
      <dc:creator>tb5821</dc:creator>
      <dc:date>2013-07-25T15:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: FileSize to human readable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106547#M27706</link>
      <description>&lt;P&gt;you need the "backticks". They are the key under Esc on the keyboard.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2013 15:58:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106547#M27706</guid>
      <dc:creator>alacercogitatus</dc:creator>
      <dc:date>2013-07-25T15:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: FileSize to human readable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106548#M27707</link>
      <description>&lt;P&gt;now getting:&lt;BR /&gt;
&lt;CODE&gt;Error in 'eval' command: Failed to parse the provided arguments. Usage: eval dest_key = expression&lt;CODE&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2013 16:23:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106548#M27707</guid>
      <dc:creator>tb5821</dc:creator>
      <dc:date>2013-07-25T16:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: FileSize to human readable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106549#M27708</link>
      <description>&lt;P&gt;Found the issue, the definition needs to be:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;eval kilobytes=($fs$/1024) | eval megabytes=kilobytes/1024 |eval gigabytes=megabytes/1024&lt;CODE&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2013 16:58:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106549#M27708</guid>
      <dc:creator>tb5821</dc:creator>
      <dc:date>2013-07-25T16:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: FileSize to human readable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106550#M27709</link>
      <description>&lt;P&gt;weird. anyway, glad that worked for you!&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2013 17:04:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106550#M27709</guid>
      <dc:creator>alacercogitatus</dc:creator>
      <dc:date>2013-07-25T17:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: FileSize to human readable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106551#M27710</link>
      <description>&lt;P&gt;Ancient thread necropsy, but here's a better macro (IMO).  It's ugly but it works just like the -h option on many GNU tools.&lt;BR /&gt;
Usage:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval readable_size=`readable(size)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Definition: (as seen in Settings -&amp;gt; Adv Search -&amp;gt; Search macros -&amp;gt; new:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if( $num$ &amp;lt; 1024, tostring($num$), if ( (floor($num$/pow(1024,floor(log($num$,1024))))) &amp;lt; 10
     , ( (tostring((floor($num$/pow(1024,floor(log($num$,1024)))))) + ".") + tostring(round((($num$/pow(1024,floor(log($num$,1024))))-(floor($num$/pow(1024,floor(log($num$,1024))))))*10))) + (substr("KMGTPEZY",floor(log($num$,1024)),1))
     , ( tostring((floor($num$/pow(1024,floor(log($num$,1024)))))) + (substr("KMGTPEZY",floor(log($num$,1024)),1)) )
   ) )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Not an eval-based definition (unchecked)&lt;BR /&gt;
Arguments: num&lt;BR /&gt;
Validation Expression: !isnum($num$)&lt;BR /&gt;
Validation Error Message: Numeric value required&lt;/P&gt;

&lt;P&gt;My key observation for the algorithm is that the log base 1024 will give you the "scale"-- KB or PB or whatever, by dropping the fractional part (i.e. log_10(5.6MB) = 2 -&amp;gt; M).&lt;/P&gt;

&lt;P&gt;In working on this, I used meaningful names and replace-all'd them to fundamental eval functions.  Here's the pseudocode:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if $num$ &amp;lt; 1024:
  printf("%4d", $num$)
else
  if $num$ reduces to a single digit
    # print in the form x.yS
    printf( "%d.%d%c", whole_part(reduction), 1st digit of frac_part(reduction), KMGTPEZY suffix appropriate for this scale
  else # This is actually the most common case.  The result is just the whole part of the reduction and the suffix
    printf("%3d%s", whole_part(reduction), suffix)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps somebody&lt;BR /&gt;
--Joe&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2017 14:48:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106551#M27710</guid>
      <dc:creator>jpvlsmv</dc:creator>
      <dc:date>2017-07-21T14:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: FileSize to human readable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106552#M27711</link>
      <description>&lt;P&gt;How about just installing Humanize?   &lt;/P&gt;

&lt;P&gt;Convert numbers, bytes, and timestamps into fuzzy, human-friendly units! Using the humanize library from &lt;A href="https://github.com/jmoiron/humanize" target="_blank"&gt;https://github.com/jmoiron/humanize&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Here are some example searches:&lt;BR /&gt;
index=_internal | head | eval foo=random() | humanize command=naturalsize foo&lt;BR /&gt;
index=_internal earliest=-7h | bin _time span=10m | eval foo=_time | stats first(foo) as foo by _time | humanize command=naturaltime foo&lt;/P&gt;

&lt;P&gt;&lt;A href="https://splunkbase.splunk.com/app/3104/" target="_blank"&gt;https://splunkbase.splunk.com/app/3104/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:00:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/106552#M27711</guid>
      <dc:creator>jameswatts</dc:creator>
      <dc:date>2020-09-29T15:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: FileSize to human readable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/629602#M218718</link>
      <description>&lt;P&gt;This could be solution for you.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.splunk.com/t5/Dashboards-Visualizations/Smart-conversion-of-large-numbers-to-human-readable-for-use-on/m-p/629593/highlight/true#M51640" target="_blank" rel="noopener"&gt;https://community.splunk.com/t5/Dashboards-Visualizations/Smart-conversion-of-large-numbers-to-human-readable-for-use-on/m-p/629593/highlight/true#M51640&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;| makeresults count=35&lt;BR /&gt;```THIS SECTION IS JUST CREATING SAMPLE VALUES.```&lt;BR /&gt;| streamstats count as digit&lt;BR /&gt;| eval val=pow(10,digit-1), val=val+random()%val&lt;BR /&gt;| foreach bytes [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=val]&lt;BR /&gt;| table digit val bytes&lt;BR /&gt;| fieldformat val=tostring(val,"commas")&lt;BR /&gt;&lt;BR /&gt;```THE FOLLOWING LINES MAY BE WHAT ACHIEVES THE FORMAT YOU ARE LOOKING FOR.```&lt;BR /&gt;| fieldformat bytes=printf("% 10s",printf("%.2f",round(bytes/pow(1024,if(bytes=0,0,floor(min(log(bytes,1024),10)))),2)).case(bytes=0 OR log(bytes,1024)&amp;lt;1,"B ", log(bytes,1024)&amp;lt;2,"KiB", log(bytes,1024)&amp;lt;3,"MiB", log(bytes,1024)&amp;lt;4,"GiB", log(bytes,1024)&amp;lt;5,"TiB", log(bytes,1024)&amp;lt;6,"PiB", log(bytes,1024)&amp;lt;7,"EiB", log(bytes,1024)&amp;lt;8,"ZiB", log(bytes,1024)&amp;lt;9,"YiB", log(bytes,1024)&amp;lt;10,"RiB", log(bytes,1024)&amp;lt;11,"QiB", 1=1, "QiB"))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you can install app or ask admin on your to install app,&lt;/P&gt;&lt;P&gt;installing&amp;nbsp;add-on&amp;nbsp;&lt;A title="Numeral system macros for Splunk" href="https://splunkbase.splunk.com/app/6595" target="_blank" rel="nofollow noopener noreferrer"&gt;Numeral system macros for Splunk&lt;/A&gt;&amp;nbsp;enables you to&lt;SPAN&gt;&amp;nbsp;use macros numeral_binary_symbol(1) or numeral_binary_symbol(2).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Example&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;| makeresults count=35&lt;BR /&gt;```THIS SECTION IS JUST CREATING SAMPLE VALUES.```&lt;BR /&gt;| streamstats count as digit&lt;BR /&gt;| eval val=pow(10,digit-1), val=val+random()%val&lt;BR /&gt;| foreach bytes [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=val]&lt;BR /&gt;| table digit val bytes&lt;BR /&gt;| fieldformat val=tostring(val,"commas")&lt;BR /&gt;&lt;BR /&gt;```THE FOLLOWING LINES MAY BE WHAT ACHIEVES THE FORMAT YOU ARE LOOKING FOR.```&lt;BR /&gt;| fieldformat bytes=printf("% 10s",`numeral_binary_symbol(bytes,2)`)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Numeral system macros for Splunk&lt;/P&gt;&lt;P&gt;&lt;A href="https://splunkbase.splunk.com/app/6595" target="_blank" rel="noopener"&gt;https://splunkbase.splunk.com/app/6595&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Usage:&lt;/P&gt;&lt;P&gt;How to convert a large number to string with expressions of long and short scales, or neither.&lt;/P&gt;&lt;P&gt;&lt;A class="" href="https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-large-number-to-string-with-expressions-of-long/m-p/629383" target="_blank" rel="noopener noreferrer"&gt;https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-large-number-to-string-with-expressions-of-long/m-p/629383&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 12:35:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Does-Splunk-have-an-easier-way-to-get-FileSize-to-human-readable/m-p/629602#M218718</guid>
      <dc:creator>tfujita_splunk</dc:creator>
      <dc:date>2023-02-04T12:35:10Z</dc:date>
    </item>
  </channel>
</rss>

