<?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: Converting a field from a string to a number in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Converting-a-field-from-a-string-to-a-number/m-p/559648#M158987</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/226579"&gt;@jason_hotchkiss&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After your initial search,&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count as events where index=wineventlog sourcetype=* by _time host custom_field source
| search custom_field=unit1 OR custom_field=unit_2 OR custom_field=unit_3&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like you to try with &lt;A href="https://docs.splunk.com/Documentation/SplunkCloud/latest/SearchReference/Eventstats" target="_self"&gt;eventstats&lt;/A&gt; command, &amp;nbsp;using this search you will have sum of events by source and custom_field.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eventstats sum(events) as event_counts by source,custom_field&lt;/LI-CODE&gt;&lt;P&gt;You can change it as your requirement,&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eventstats sum(events) as event_counts by host,source&lt;/LI-CODE&gt;&lt;P&gt;Another reason using eventstats, in case you want to use timechart then it requires _time files but after stats command you mentioned in question _time won't be there. with event stats you will have _time with you.&lt;/P&gt;&lt;P&gt;Then you can try&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| chart sum(events) as event_counts over custom_field by host&lt;/LI-CODE&gt;&lt;P&gt;OR&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| timechart sum(events) as event_counts by custom_field&lt;/LI-CODE&gt;&lt;BLOCKQUOTE&gt;&lt;BR /&gt;From timechart I am trying to determine the total count of events for each host by custom_field&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Timechart allow only single by clause so may be you can try above one&lt;/P&gt;&lt;P&gt;I hope this will help you. Just try it and let me know if you need any help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Jul 2021 16:38:44 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2021-07-15T16:38:44Z</dc:date>
    <item>
      <title>Converting a field from a string to a number</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-a-field-from-a-string-to-a-number/m-p/559614#M158978</link>
      <description>&lt;P&gt;So, long story short...&lt;BR /&gt;&lt;BR /&gt;I am trying to determine the event count by source, which host is producing the most events in that source, and who owns the host (custom_field).&lt;BR /&gt;&lt;BR /&gt;Any suggestions on how to accomplish this would be helpful.&amp;nbsp; Thank you.&lt;BR /&gt;&lt;BR /&gt;This is what I have tried so far:&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;| tstats count as events where index=wineventlog sourcetype=* by _time host custom_field source&lt;BR /&gt;| search custom_field=unit1 OR custom_field=unit_2 OR custom_field=unit_3&lt;BR /&gt;&lt;BR /&gt;Then I run a stats command to collect the event count, then list the event count by the custom_field&lt;BR /&gt;&lt;BR /&gt;| stats&lt;BR /&gt;&amp;nbsp; sum(events) as total_events&lt;BR /&gt;&amp;nbsp; list(events) as event_counts&lt;BR /&gt;&amp;nbsp; list(source) as source&lt;BR /&gt;&amp;nbsp; list(host) as host&lt;BR /&gt;&amp;nbsp; by custom_field&lt;BR /&gt;&lt;BR /&gt;I understand that event_counts is now a string.&amp;nbsp; However, I would like to be able to use these numbers to determine which source is producing the most events by each custom_field.&lt;BR /&gt;&lt;BR /&gt;I have tried:&lt;BR /&gt;&lt;BR /&gt;| convert num(event_counts)&lt;BR /&gt;&lt;SPAN&gt;| eval num_events = tonumber(event_counts)&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;But these don't work unless I use&lt;BR /&gt;&lt;BR /&gt;| mvexpand event_counts&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;This then skews the results to where they don't make any sense.&amp;nbsp; I want to convert the event_count field to a number so I can make a chart or a timechart from it as well to analyze the growth over time.&lt;BR /&gt;&lt;BR /&gt;Thanks in advanced.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jul 2021 15:07:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-a-field-from-a-string-to-a-number/m-p/559614#M158978</guid>
      <dc:creator>jason_hotchkiss</dc:creator>
      <dc:date>2021-07-15T15:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a field from a string to a number</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-a-field-from-a-string-to-a-number/m-p/559617#M158979</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/226579"&gt;@jason_hotchkiss&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please share your requirement what you want to achieve from tstats , stats and then timechart commands? If you share more details then we can suggest optimised solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jul 2021 15:33:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-a-field-from-a-string-to-a-number/m-p/559617#M158979</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2021-07-15T15:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a field from a string to a number</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-a-field-from-a-string-to-a-number/m-p/559637#M158984</link>
      <description>&lt;P&gt;From tstats I am trying to count events by source host custom_field _time&lt;BR /&gt;&lt;BR /&gt;From stats I am trying to determine total events for each source and the host using that source.&lt;BR /&gt;&lt;BR /&gt;From timechart I am trying to determine the total count of events for each host by custom_field&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jul 2021 16:13:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-a-field-from-a-string-to-a-number/m-p/559637#M158984</guid>
      <dc:creator>jason_hotchkiss</dc:creator>
      <dc:date>2021-07-15T16:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a field from a string to a number</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-a-field-from-a-string-to-a-number/m-p/559648#M158987</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/226579"&gt;@jason_hotchkiss&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After your initial search,&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count as events where index=wineventlog sourcetype=* by _time host custom_field source
| search custom_field=unit1 OR custom_field=unit_2 OR custom_field=unit_3&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like you to try with &lt;A href="https://docs.splunk.com/Documentation/SplunkCloud/latest/SearchReference/Eventstats" target="_self"&gt;eventstats&lt;/A&gt; command, &amp;nbsp;using this search you will have sum of events by source and custom_field.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eventstats sum(events) as event_counts by source,custom_field&lt;/LI-CODE&gt;&lt;P&gt;You can change it as your requirement,&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eventstats sum(events) as event_counts by host,source&lt;/LI-CODE&gt;&lt;P&gt;Another reason using eventstats, in case you want to use timechart then it requires _time files but after stats command you mentioned in question _time won't be there. with event stats you will have _time with you.&lt;/P&gt;&lt;P&gt;Then you can try&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| chart sum(events) as event_counts over custom_field by host&lt;/LI-CODE&gt;&lt;P&gt;OR&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| timechart sum(events) as event_counts by custom_field&lt;/LI-CODE&gt;&lt;BLOCKQUOTE&gt;&lt;BR /&gt;From timechart I am trying to determine the total count of events for each host by custom_field&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Timechart allow only single by clause so may be you can try above one&lt;/P&gt;&lt;P&gt;I hope this will help you. Just try it and let me know if you need any help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jul 2021 16:38:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-a-field-from-a-string-to-a-number/m-p/559648#M158987</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2021-07-15T16:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a field from a string to a number</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-a-field-from-a-string-to-a-number/m-p/560215#M159206</link>
      <description>&lt;P&gt;This has been most helpful.&amp;nbsp; I was able to use your examples to create my dashboard.&amp;nbsp; Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 14:18:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-a-field-from-a-string-to-a-number/m-p/560215#M159206</guid>
      <dc:creator>jason_hotchkiss</dc:creator>
      <dc:date>2021-07-20T14:18:36Z</dc:date>
    </item>
  </channel>
</rss>

