<form stylesheet="ui_simple.css,panel_decoration.css" isVisible="true" version="1.1" theme="dark">
    <label>UPTIME evolution over time</label>
    <description>Uptime evolution over time, evaluated in days</description>
    <row>
        <panel>
            <input type="time" token="timerange" searchWhenChanged="true">
                <label>Time Range:</label>
                <default>
                    <earliest>-1y@d</earliest>
                    <latest>now</latest>
                </default>
            </input>
            <input type="dropdown" token="osfilter" searchWhenChanged="true">
                <label>Filter OS Type:</label>
                <default>Linux</default>
                <prefix>OStype="</prefix>
                <suffix>"</suffix>
                <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="dropdown" 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>
                <prefix>host="</prefix>
                <suffix>"</suffix>
                <fieldForLabel>host</fieldForLabel>
                <fieldForValue>host</fieldForValue>
            </input>
        </panel>
    </row>

    <!-- Base Searches for PostProcessing -->

    <search id="populate">
        <query>| tstats count as count where `nmon_events_index` type=UPTIME $osfilter$ by host
| `mapping_frameID`
| stats count by frameID, host | sort 0 host</query>
        <earliest>$timerange.earliest$</earliest>
        <latest>$timerange.latest$</latest>
    </search>

    <!-- Help the user -->

    <row rejects="$host$">
        <panel>
            <html>
                <div class="red_help_user">
                    <p>- - - - - - - - - - ACTION REQUIRED: please select your server name(s) in the host selector above - - - - - - - - - -</p>
                </div>
            </html>
        </panel>
    </row>

    <search id="GlobalSearch">
        <query>| tstats latest("metricator-nmon-config.uptime") AS uptime_seconds, latest("metricator-nmon-config.event_epoch") AS last_report from datamodel=metricator-nmon-config where (nodename = metricator-nmon-config) (sourcetype=nmon_config) $host$ by host prestats=true
| tstats latest("Uptime.uptime") AS external_uptime_seconds latest(Uptime.event_epoch) as external_last_report from datamodel=metricator-nmon-config.Uptime where (nodename = Uptime) (Uptime.OStype = "Linux") (Uptime.uptime = "*") $host$ by host append=true prestats=true
| stats dedup_splitvals=t
latest("metricator-nmon-config.uptime") AS uptime_seconds, latest("metricator-nmon-config.event_epoch") AS last_report, latest("Uptime.uptime") AS external_uptime_seconds latest(Uptime.event_epoch) as external_last_report by host
| eval last_known_uptime=if(isnotnull(external_uptime_seconds), external_uptime_seconds, uptime_seconds)
| eval epoch=if(isnotnull(external_last_report), external_last_report, last_report)
| eval reporting_date=strftime(epoch, "%m/%d/%Y %H:%M")
| eval now=now()
| eval last_known_uptime=(last_known_uptime+(now-epoch))
| sort host
| eval "Date of last system startup (mm/dd/Y HH:MM)"=strftime((now()-last_known_uptime), "%m/%d/%Y %H:%M")
| eval "uptime (human duration)"=tostring(last_known_uptime, "duration")
| fields host,last_known_uptime,"uptime (human duration)","Date of last system startup (mm/dd/Y HH:MM)",reporting_date | fields - _time
| rename last_known_uptime AS "uptime (in seconds)", reporting_date AS "Last reporting date (mm/dd/Y HH:MM)"</query>
        <earliest>-7d@h</earliest>
        <latest>now</latest>
    </search>
    <row>
        <panel>
            <single>
                <search base="GlobalSearch">
                    <query>fields "Date of last system startup (mm/dd/Y HH:MM)"</query>
                </search>
                <option name="drilldown">none</option>
                <option name="colorBy">value</option>
                <option name="colorMode">none</option>
                <option name="numberPrecision">0</option>
                <option name="rangeColors">["0x65a637","0x006d9c","0xf2aa0a","0xf58f39","0xd93f3c"]</option>
                <option name="rangeValues">[0,30,70,100]</option>
                <option name="showSparkline">1</option>
                <option name="showTrendIndicator">1</option>
                <option name="trendColorInterpretation">standard</option>
                <option name="trendDisplayMode">absolute</option>
                <option name="trendInterval">auto</option>
                <option name="underLabel">LAST SYSTEM STARTUP DATE</option>
                <option name="useColors">0</option>
                <option name="useThousandSeparators">1</option>
            </single>
            <single>
                <search base="GlobalSearch">
                    <query>fields "uptime (human duration)"</query>
                </search>
                <option name="drilldown">none</option>
                <option name="colorBy">value</option>
                <option name="colorMode">none</option>
                <option name="numberPrecision">0</option>
                <option name="rangeColors">["0x65a637","0x006d9c","0xf2aa0a","0xf58f39","0xd93f3c"]</option>
                <option name="rangeValues">[0,30,70,100]</option>
                <option name="showSparkline">1</option>
                <option name="showTrendIndicator">1</option>
                <option name="trendColorInterpretation">standard</option>
                <option name="trendDisplayMode">absolute</option>
                <option name="trendInterval">auto</option>
                <option name="underLabel">LAST UPTIME DURATION (dd:HH:MM:SS)</option>
                <option name="useColors">0</option>
                <option name="useThousandSeparators">1</option>
            </single>
            <chart>
                <search>
                    <query>| tstats latest("metricator-nmon-config.uptime") AS uptime_seconds from datamodel=metricator-nmon-config where (nodename = metricator-nmon-config) (sourcetype=nmon_config) (metricator-nmon-config.OStype = "Linux") ($host$) by _time, host prestats=true span=1d
| tstats latest("Uptime.uptime") AS external_uptime_seconds from datamodel=metricator-nmon-config.Uptime where (nodename = Uptime) (Uptime.OStype = "Linux") (Uptime.uptime = "*") ($host$) by _time, host append=true prestats=true span=1d
| stats dedup_splitvals=t
latest("metricator-nmon-config.uptime") AS uptime_seconds, latest("Uptime.uptime") AS external_uptime_seconds by _time, host
| eval last_known_uptime=if(isnotnull(external_uptime_seconds), external_uptime_seconds, uptime_seconds)
| eval uptime=if(isnotnull(external_uptime_seconds), external_uptime_seconds, uptime_seconds)
| eval uptime=(uptime/86400)
| timechart span=1d limit=0 useother=f values(uptime) AS uptime by host</query>
                    <earliest>$timerange.earliest$</earliest>
                    <latest>$timerange.latest$</latest>
                </search>
                <option name="charting.axisLabelsX.majorLabelStyle.overflowMode">ellipsisNone</option>
                <option name="charting.axisLabelsX.majorLabelStyle.rotation">0</option>
                <option name="charting.axisTitleX.text">Days</option>
                <option name="charting.axisTitleX.visibility">visible</option>
                <option name="charting.axisTitleY.text">uptime in days</option>
                <option name="charting.axisTitleY.visibility">visible</option>
                <option name="charting.axisTitleY2.visibility">visible</option>
                <option name="charting.axisX.scale">linear</option>
                <option name="charting.axisY.scale">linear</option>
                <option name="charting.axisY2.enabled">0</option>
                <option name="charting.axisY2.scale">inherit</option>
                <option name="charting.chart">line</option>
                <option name="charting.chart.bubbleMaximumSize">50</option>
                <option name="charting.chart.bubbleMinimumSize">10</option>
                <option name="charting.chart.bubbleSizeBy">area</option>
                <option name="charting.chart.nullValueMode">connect</option>
                <option name="charting.chart.showDataLabels">none</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.layout.splitSeries.allowIndependentYRanges">0</option>
                <option name="charting.legend.labelStyle.overflowMode">ellipsisMiddle</option>
                <option name="charting.legend.placement">bottom</option>
                <option name="height">400</option>
            </chart>
        </panel>
    </row>
</form>
