更新页面链接
大石头 authored at 2022-02-04 02:57:55
3.19 KiB
Stardust
@model IList<SampleData>
@using Stardust.Data.Monitors
@using NewLife;
@using NewLife.Web;
@using XCode;
@using XCode.Configuration;
@using XCode.Membership;
@using NewLife.Cube;
@using System.Web;
@{
    var page = ViewBag.Page as Pager;
}
<table class="table table-bordered table-hover table-striped table-condensed">
    <thead>
        <tr>
            <th class="text-center">应用</th>
            <th class="text-center" title="操作名。接口名或埋点名">操作名</th>
            <th style="width:80%">时间轴</th>
        </tr>
    </thead>
    <tbody>
        @{
            //var sd = Model.OrderByDescending(e => e.EndTime - e.StartTime).FirstOrDefault();
            var min = Model.Min(e => e.StartTime);
            var max = Model.Max(e => e.EndTime);
            var length = max - min;
        }
        @foreach (var entity in Model)
        {
            var ti = entity.TraceItem;
            var msg = entity.Error ?? entity.Tag;

            var ms = entity.EndTime - entity.StartTime;
            var left = (Double)(entity.StartTime - min) / length;
            if (left < 0) left = 0;
            var w = (Double)ms / length;
            if (w > 0.01) w -= 0.01;

            var color = "lightgreen";
            if (!entity.Success)
            {
                color = "palevioletred";
            }
            else if (ti.Kind.EqualIgnoreCase("db"))
            {
                color = "orange";
            }
            else if (ti.Kind.EqualIgnoreCase("net", "rpc", "mq", "redismq", "mqtt", "mns", "emq"))
            {
                color = "mediumpurple";
            }
            var color2 = "";
            if (ti.Kind.EqualIgnoreCase("db"))
            {
                color2 = "orange";
            }
            else if (ti.Kind.EqualIgnoreCase("mq", "redismq", "mqtt", "mns", "emq"))
            {
                color2 = "mediumpurple";
            }
            else if (ti.Kind.EqualIgnoreCase("redis"))
            {
                color2 = "palevioletred";
            }
            var url1 = $"appDayStat?appId={entity.AppId}";
            var url2 = $"traceDayStat?appid={entity.AppId}&itemId={entity.ItemId}";
            <tr>
                <td class="text-center"><a href="@url1" title="应用最近的监控图表">@entity.AppName</a></td>
                <td title="@entity.Tag" style="max-width:400px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;"><a href="@url2" style="color: @color2">@entity.Name</a></td>
                <td title="@msg">
                    @if (left < 0.96)
                    {
                        <div style="float:left;width:@left.ToString("p")">&nbsp;</div>
                        <div style="background-color: @color;float:left;width:@w.ToString("p")">@ms.ToString("n0")ms</div>
                    }
                    else
                    {
                        <div style="float:left;width:@((left-0.04).ToString("p"))">&nbsp;</div>
                        <div style="float:left;width:4%">@ms.ToString("n0")ms</div>
                        <div style="background-color: @color;float:left;width:@w.ToString("p")">&nbsp;</div>
                    }
                </td>
            </tr>
        }
    </tbody>
</table>