Browse Source

Adds a very mad-katz metrics dashboard

pull/288/head
Ryan Nowak 6 years ago
parent
commit
e710c4b757
  1. 2
      src/Microsoft.Tye.Hosting/Dashboard/Pages/Index.razor
  2. 4
      src/Microsoft.Tye.Hosting/Dashboard/Pages/ServiceDetails.razor
  3. 74
      src/Microsoft.Tye.Hosting/Dashboard/Shared/MetricsDisplay.razor
  4. 55
      src/Microsoft.Tye.Hosting/Dashboard/Shared/ReplicaSelector.razor
  5. 3
      src/Microsoft.Tye.Hosting/Model/ReplicaStatus.cs

2
src/Microsoft.Tye.Hosting/Dashboard/Pages/Index.razor

@ -88,8 +88,6 @@
{
_subscriptions.Add(a.ReplicaEvents.Subscribe(OnReplicaChanged));
}
base.OnInitialized();
}
private void OnReplicaChanged(ReplicaEvent replicaEvent)

4
src/Microsoft.Tye.Hosting/Dashboard/Pages/ServiceDetails.razor

@ -18,6 +18,10 @@ else
case ServiceType.Project:
break;
}
<hr />
<MetricsDisplay Service="_service" />
}
@code {

74
src/Microsoft.Tye.Hosting/Dashboard/Shared/MetricsDisplay.razor

@ -0,0 +1,74 @@
@implements IDisposable
@using System.Threading;
<h4>Metrics</h4>
<ReplicaSelector Service="@Service" ReplicaChanged="OnReplicaChanged" />
<div class="px-4 py-2">
<table class="table table-striped table-bordered">
<colgroup>
<col span="1" style="width: 75%;">
<col span="1" style="width: 25%;">
</colgroup>
<thead class="thead-light">
<tr>
<th scope="col">Metric</th>
<th scope="col">Value</th>
</tr>
</thead>
@if (replica is object)
{
<tbody>
@foreach (var metric in replica.Metrics.OrderBy(kvp => kvp.Key))
{
<tr>
<td>@metric.Key</td>
<td>@metric.Value</td>
</tr>
}
</tbody>
}
else
{
<tbody></tbody>
}
</table>
</div>
@code {
ReplicaStatus? replica;
Timer? timer;
[Parameter] public Service Service { get; set; } = default!;
protected override void OnParametersSet()
{
replica = Service?.Replicas.FirstOrDefault().Value;
OnReplicaChanged(replica);
}
void OnReplicaChanged(ReplicaStatus? replica)
{
this.replica = replica;
if (this.replica == null && timer is object)
{
timer.Dispose();
timer = null;
}
if (this.replica != null)
{
timer ??= new Timer(Timer_Tick, state: null, 1000, 1000);
}
}
void Timer_Tick(object? _)
{
_ = InvokeAsync(() => StateHasChanged());
}
void IDisposable.Dispose()
{
timer?.Dispose();
}
}

55
src/Microsoft.Tye.Hosting/Dashboard/Shared/ReplicaSelector.razor

@ -0,0 +1,55 @@
@implements IDisposable
<label>Replica:</label>
<select value="@selected" @onchange="ReplicaSelected">
@foreach (var replica in Service.Replicas)
{
<option value="@replica.Key">@replica.Key</option>
}
</select>
@code {
IDisposable? subscription;
string? selected;
[Parameter] public Service Service { get; set; } = default!;
[Parameter] public EventCallback<ReplicaStatus?> ReplicaChanged { get; set; }
protected override void OnParametersSet()
{
subscription?.Dispose();
subscription = Service.ReplicaEvents.Subscribe(OnReplicasChanged);
}
void OnReplicasChanged(ReplicaEvent @event)
{
_ = InvokeAsync(() =>
{
if (@event.State == ReplicaState.Stopped && @event.Replica.Name == selected)
{
selected = null;
}
StateHasChanged();
});
}
async Task ReplicaSelected(ChangeEventArgs e)
{
selected = (string?)e.Value;
ReplicaStatus? replica = null;
if (selected is string)
{
Service.Replicas.TryGetValue(selected, out replica);
}
await ReplicaChanged.InvokeAsync(replica);
}
void IDisposable.Dispose()
{
subscription?.Dispose();
}
}

3
src/Microsoft.Tye.Hosting/Model/ReplicaStatus.cs

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Concurrent;
using System.Collections.Generic;
namespace Microsoft.Tye.Hosting.Model
@ -22,7 +23,7 @@ namespace Microsoft.Tye.Hosting.Model
public Dictionary<object, object> Items { get; } = new Dictionary<object, object>();
public Dictionary<string, string> Metrics { get; set; } = new Dictionary<string, string>();
public ConcurrentDictionary<string, string> Metrics { get; set; } = new ConcurrentDictionary<string, string>();
public IDictionary<string, string>? Environment { get; set; }
}

Loading…
Cancel
Save