<form script="autodiscover.js" stylesheet="ui_simple.css" isVisible="true" version="1.1" theme="dark">
    <label>Dashboard TOP Hosts, Higher CPU Load Hosts for All OS</label>
    <description>Easily visualize hosts with high level of resources utilization using Bubble charts</description>

    <fieldset autoRun="false" submitButton="false">

        <input type="time" token="timerange" searchWhenChanged="true">
            <label>Time Range:</label>
            <default>
                <earliest>-24h</earliest>
                <latest>now</latest>
            </default>
        </input>

        <input type="dropdown" token="timefilter" searchWhenChanged="true">
            <label>Time Filtering:</label>
            <choice value="No_Filter">No Filter (24/24, 7/7)</choice>
            <choice value="Day_BusinessDays_8h-19h">Day Business (08h-19h)</choice>
            <choice value="Day_WeekEnd_8h-19h">Day WE (08h-19h)</choice>
            <choice value="Day_AllDays_8h-19h">Day Week (08h-19h)</choice>
            <choice value="Night_BusinessDays_19h-8h">Night Business (19h-08h)</choice>
            <choice value="Night_WeekEnd_19h-8h">Night WE (19h-08h)</choice>
            <choice value="Night_AllDays_19h-8h">Night All Days (19h-08h)</choice>
            <default>No_Filter</default>
        </input>

        <input type="dropdown" token="osfilter" searchWhenChanged="true">
            <label>Filter OS Type:</label>
            <default>*</default>
            <prefix>OStype=</prefix>
            <choice value="*">Any OS</choice>
            <choice value="AIX">AIX</choice>
            <choice value="Linux">Linux</choice>
            <choice value="Solaris">Solaris</choice>
        </input>

        <input id="frameID" type="multiselect" token="frameID" searchWhenChanged="true">
            <label>Frame IDs:</label>
            <!-- Populating Data Model Search -->
            <search base="populate">
                <query>stats count by frameID | dedup frameID | sort 0 frameID</query>
            </search>
            <valuePrefix>frameID="</valuePrefix>
            <valueSuffix>"</valueSuffix>
            <delimiter> OR </delimiter>
            <choice value="*">Any</choice>
            <initialValue>*</initialValue>
            <fieldForLabel>frameID</fieldForLabel>
            <fieldForValue>frameID</fieldForValue>
        </input>

        <input type="text" token="host-prefilter" searchWhenChanged="true">
            <label>Optional: Filter hosts populating</label>
            <default>*</default>
        </input>

		<input id="host" type="multiselect" token="host" searchWhenChanged="true">
		    <label>Hosts Selection:</label>
		    <!-- Populating Data Model Search -->
		    <search base="populate">
		        <query>search $frameID$ host=$host-prefilter$
	| stats count by host | dedup host | sort 0 host</query>
		    </search>
		    <valuePrefix>host="</valuePrefix>
		    <valueSuffix>"</valueSuffix>
		    <delimiter> OR </delimiter>
		    <choice value="*">ALL Hosts</choice>
		    <fieldForLabel>host</fieldForLabel>
		    <fieldForValue>host</fieldForValue>
		    <change>
		        <condition>
		            <unset token="form.host_query_input"></unset>
		        </condition>
		    </change>
		</input>

		<!-- hidden form that handles the advanced definition of hosts selection -->

		<input id="host_query_input" type="dropdown" token="host_query" searchWhenChanged="true" depends="$hidden_form$">
		    <label>Hosts Selection:</label>
		    <search base="populate">
		        <query>search $host$ $frameID$
	| stats values(host) as host
	| format | fields - host | rename search as host</query>
		    </search>
		    <selectFirstChoice>true</selectFirstChoice>
		    <fieldForLabel>host</fieldForLabel>
		    <fieldForValue>host</fieldForValue>
		</input>

        <input type="dropdown" token="statsmode" searchWhenChanged="true">
            <label>Stats mode:</label>
            <default>avg</default>
            <choice value="max">Max</choice>
            <choice value="avg">Avg</choice>
            <choice value="min">Min</choice>
            <choice value="median">Median</choice>
            <choice value="mode">Mode</choice>
            <choice value="range">Range</choice>
        </input>

    </fieldset>

    <!-- Search based for post processing -->

    <search id="populate">
        <query>| mcatalog values(metric_name) where `nmon_metrics_index` metric_name="os.unix.nmon.cpu.cpu_all.*" $osfilter$ by host
| `mapping_frameID`
| stats count by frameID, host | sort 0 host</query>
        <earliest>$timerange.earliest$</earliest>
        <latest>$timerange.latest$</latest>
    </search>

    <search id="baseSearch">
        <query>| mstats avg(_value) as value where `nmon_metrics_index` (metric_name=os.unix.nmon.cpu.cpu_all.Sys_PCT OR metric_name=os.unix.nmon.cpu.cpu_all.User_PCT OR metric_name=os.unix.nmon.cpu.cpu_all.Wait_PCT OR metric_name=os.unix.nmon.cpu.lpar.VP_User_PCT OR metric_name=os.unix.nmon.cpu.lpar.VP_Sys_PCT OR metric_name=os.unix.nmon.cpu.lpar.VP_Wait_PCT OR metric_name=os.unix.nmon.cpu.lpar.VP_Idle_PCT OR metric_name=os.unix.nmon.cpu.lpar.PhysicalCPU OR metric_name=os.unix.nmon.cpu.lpar.virtualCPUs OR metric_name=os.unix.nmon.cpu.lpar.partition_active_processors) host=$host-prefilter$ $host_query$ by metric_name, OStype, host span=1m
| `def_all_os_cpu_load_percent`
| stats $statsmode$(cpu_load_percent) AS cpu_load_percent by host
| eval cpu_load_percent=round(cpu_load_percent, 2)
| fields frameID,host,cpu_load_percent,*</query>
        <earliest>$timerange.earliest$</earliest>
        <latest>$timerange.latest$</latest>
    </search>

    <row>
        <panel>
            <title>TOP 100: Graphical Representation of Hosts (ordered by CPU Usage)</title>
            <html>
                <div id="bubbleSearch"
                     class="splunk-manager"
                     data-require="splunkjs/mvc/searchmanager"
                     data-options='{
                    "search": {
								"type": "token_safe",
                    		"value": "| mstats avg(_value) as value where `nmon_metrics_index` (metric_name=os.unix.nmon.cpu.cpu_all.Sys_PCT OR metric_name=os.unix.nmon.cpu.cpu_all.User_PCT OR metric_name=os.unix.nmon.cpu.cpu_all.Wait_PCT OR metric_name=os.unix.nmon.cpu.lpar.VP_User_PCT OR metric_name=os.unix.nmon.cpu.lpar.VP_Sys_PCT OR metric_name=os.unix.nmon.cpu.lpar.VP_Wait_PCT OR metric_name=os.unix.nmon.cpu.lpar.VP_Idle_PCT OR metric_name=os.unix.nmon.cpu.lpar.PhysicalCPU OR metric_name=os.unix.nmon.cpu.lpar.virtualCPUs OR metric_name=os.unix.nmon.cpu.lpar.partition_active_processors) host=$$host-prefilter$$ $$host_query$$ by metric_name, OStype, host span=1m
| `def_all_os_cpu_load_percent`
| stats $$statsmode$$(cpu_load_percent) AS usage by host
| eval usage=round(usage, 2) | sort - usage | head 100"
						  },
          			  "earliest_time": {
            				"type": "token_safe",
            				"value": "$$timerange.earliest$$"
          				},
          				"latest_time": {
            				"type": "token_safe",
            				"value": "$$timerange.latest$$"
          				},
                    "auto_cancel": 90,
                    "preview": true
                 }'>
                </div>
                <div id="bubbleChart"
                     class="splunk-view"
                     data-require="app/metricator-for-nmon/components/bubblechart/bubblechart"
                     data-options='{
                    "managerid": "bubbleSearch",
                    "nameField": "host",
                    "categoryField": "host",
                    "valueField": "usage",
                    "height": 600
                 }'>
                </div>
            </html>
        </panel>
    </row>

    <row>
        <panel>
            <title>TOP 50 CPU Usage Hosts (ordered by CPU Usage percentage of capacity)</title>
            <chart>
                <search base="baseSearch">
                    <query>sort - 0 cpu_load_percent | head 50
| eval xlabel=""| chart max(cpu_load_percent) AS cpu_load_percent useother=f limit=0 by xlabel,host
| rename xlabel AS "CPU % usage"</query>
                </search>
                <option name="charting.chart.columnSpacing">5</option>
                <option name="charting.axisTitleX.visibility">collapsed</option>
                <option name="charting.axisTitleY.visibility">visible</option>
                <option name="charting.axisX.scale">linear</option>
                <option name="charting.axisY.scale">linear</option>
                <option name="charting.chart">column</option>
                <option name="charting.chart.sliceCollapsingThreshold">0.01</option>
                <option name="charting.chart.stackMode">default</option>
                <option name="charting.chart.style">shiny</option>
                <option name="charting.drilldown">all</option>
                <option name="charting.layout.splitSeries">0</option>
                <option name="charting.legend.labelStyle.overflowMode">ellipsisMiddle</option>
                <option name="charting.legend.placement">bottom</option>
                <option name="charting.chart.nullValueMode">gaps</option>
                <option name="height">680</option>
                <option name="charting.axisTitleY.text">% CPU usage</option>
                <option name="charting.axisY.minimumNumber">0</option>
                <option name="charting.axisY.maximumNumber">100</option>
                <option name="charting.axisLabelsX.majorLabelStyle.overflowMode">ellipsisNone</option>
                <option name="charting.axisLabelsX.majorLabelStyle.rotation">0</option>
                <option name="charting.axisTitleY2.visibility">visible</option>
                <option name="charting.axisY2.enabled">false</option>
                <option name="charting.axisY2.scale">inherit</option>
            </chart>
        </panel>
    </row>

    <row>
        <panel>
            <title>Hosts CPU Usage Table Stats (ordered by host)</title>

            <table>
                <search>
                    <query>| mstats avg(_value) as value where `nmon_metrics_index` (metric_name=os.unix.nmon.cpu.cpu_all.Sys_PCT OR metric_name=os.unix.nmon.cpu.cpu_all.User_PCT OR metric_name=os.unix.nmon.cpu.cpu_all.Wait_PCT OR metric_name=os.unix.nmon.cpu.lpar.VP_User_PCT OR metric_name=os.unix.nmon.cpu.lpar.VP_Sys_PCT OR metric_name=os.unix.nmon.cpu.lpar.VP_Wait_PCT OR metric_name=os.unix.nmon.cpu.lpar.VP_Idle_PCT OR metric_name=os.unix.nmon.cpu.lpar.PhysicalCPU OR metric_name=os.unix.nmon.cpu.lpar.virtualCPUs OR metric_name=os.unix.nmon.cpu.lpar.partition_active_processors) host=$host-prefilter$ $host_query$ by metric_name, OStype, host span=1m
| `def_all_os_cpu_load_percent`
| stats min(cpu_load_percent) AS min_cpu_load_percent avg(cpu_load_percent) AS avg_cpu_load_percent median(cpu_load_percent) AS median_cpu_load_percent max(cpu_load_percent) AS max_cpu_load_percent sparkline(avg(cpu_load_percent),) As sparkline by host
| eval cpu_load_percent=round(cpu_load_percent, 2)
| foreach *_percent [ eval &lt;&lt;FIELD&gt;&gt; = round('&lt;&lt;FIELD&gt;&gt;', 3) ]
| `mapping_frameID`
| fields frameID, host, min_cpu_load_percent, avg_cpu_load_percent, median_cpu_load_percent, max_cpu_load_percent, sparkline</query>
                    <earliest>$timerange.earliest$</earliest>
                    <latest>$timerange.latest$</latest>
                </search>
                <option name="wrap">true</option>
                <option name="rowNumbers">false</option>
                <option name="dataOverlayMode">none</option>
                <option name="drilldown">row</option>
                <option name="count">50</option>
                <format type="sparkline" field="sparkline">
                    <option name="lineColor">#5379af</option>
                    <option name="fillColor">#CCDDFF</option>
                    <option name="lineWidth">1</option>
                    <option name="height">25</option>
                </format>
                <format type="color" field="min_cpu_load_percent">
                    <colorPalette type="minMidMax" maxColor="#31A35F" minColor="#353535"></colorPalette>
                    <scale type="minMidMax"></scale>
                </format>
                <format type="color" field="avg_cpu_load_percent">
                    <colorPalette type="minMidMax" maxColor="#31A35F" minColor="#353535"></colorPalette>
                    <scale type="minMidMax"></scale>
                </format>
                <format type="color" field="median_cpu_load_percent">
                    <colorPalette type="minMidMax" maxColor="#31A35F" minColor="#353535"></colorPalette>
                    <scale type="minMidMax"></scale>
                </format>
                <format type="color" field="max_cpu_load_percent">
                    <colorPalette type="minMidMax" maxColor="#31A35F" minColor="#353535"></colorPalette>
                    <scale type="minMidMax"></scale>
                </format>
            </table>
        </panel>
    </row>

</form>
