2022-06-22 11:20:57 +02:00
|
|
|
<script>
|
2024-03-09 10:30:40 +01:00
|
|
|
import { Icon } from "@sveltestrap/sveltestrap";
|
2022-06-22 11:20:57 +02:00
|
|
|
|
2024-03-09 10:30:40 +01:00
|
|
|
export let host;
|
|
|
|
export let metric;
|
|
|
|
export let scope;
|
|
|
|
export let jobMetrics;
|
2023-08-09 17:24:01 +02:00
|
|
|
|
2024-03-09 10:30:40 +01:00
|
|
|
function compareNumbers(a, b) {
|
|
|
|
return a.id - b.id;
|
|
|
|
}
|
2023-08-09 17:24:01 +02:00
|
|
|
|
2024-03-09 10:30:40 +01:00
|
|
|
function sortByField(field) {
|
|
|
|
let s = sorting[field];
|
|
|
|
if (s.active) {
|
|
|
|
s.dir = s.dir == "up" ? "down" : "up";
|
|
|
|
} else {
|
|
|
|
for (let field in sorting) sorting[field].active = false;
|
|
|
|
s.active = true;
|
2023-08-09 17:24:01 +02:00
|
|
|
}
|
|
|
|
|
2024-03-09 10:30:40 +01:00
|
|
|
sorting = { ...sorting };
|
|
|
|
series = series.sort((a, b) => {
|
|
|
|
if (a == null || b == null) return -1;
|
|
|
|
|
|
|
|
if (field === "id") {
|
|
|
|
return s.dir != "up" ? a[field] - b[field] : b[field] - a[field];
|
|
|
|
} else {
|
|
|
|
return s.dir != "up"
|
|
|
|
? a.statistics[field] - b.statistics[field]
|
|
|
|
: b.statistics[field] - a.statistics[field];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let sorting = {
|
|
|
|
id: { dir: "down", active: true },
|
|
|
|
min: { dir: "up", active: false },
|
|
|
|
avg: { dir: "up", active: false },
|
|
|
|
max: { dir: "up", active: false },
|
|
|
|
};
|
2023-08-09 17:24:01 +02:00
|
|
|
|
2024-03-09 10:30:40 +01:00
|
|
|
$: series = jobMetrics
|
|
|
|
.find((jm) => jm.name == metric && jm.scope == scope)
|
|
|
|
?.metric.series.filter((s) => s.hostname == host && s.statistics != null)
|
|
|
|
?.sort(compareNumbers);
|
2022-06-22 11:20:57 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if series == null || series.length == 0}
|
2024-03-09 10:30:40 +01:00
|
|
|
<td colspan={scope == "node" ? 3 : 4}><i>No data</i></td>
|
|
|
|
{:else if series.length == 1 && scope == "node"}
|
|
|
|
<td>
|
|
|
|
{series[0].statistics.min}
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
{series[0].statistics.avg}
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
{series[0].statistics.max}
|
|
|
|
</td>
|
2022-06-22 11:20:57 +02:00
|
|
|
{:else}
|
2024-03-09 10:30:40 +01:00
|
|
|
<td colspan="4">
|
|
|
|
<table style="width: 100%;">
|
|
|
|
<tr>
|
|
|
|
{#each ["id", "min", "avg", "max"] as field}
|
|
|
|
<th on:click={() => sortByField(field)}>
|
|
|
|
Sort
|
|
|
|
<Icon
|
|
|
|
name="caret-{sorting[field].dir}{sorting[field].active
|
|
|
|
? '-fill'
|
|
|
|
: ''}"
|
|
|
|
/>
|
|
|
|
</th>
|
|
|
|
{/each}
|
|
|
|
</tr>
|
|
|
|
{#each series as s, i}
|
|
|
|
<tr>
|
|
|
|
<th>{s.id ?? i}</th>
|
|
|
|
<td>{s.statistics.min}</td>
|
|
|
|
<td>{s.statistics.avg}</td>
|
|
|
|
<td>{s.statistics.max}</td>
|
|
|
|
</tr>
|
|
|
|
{/each}
|
|
|
|
</table>
|
|
|
|
</td>
|
2022-06-22 11:20:57 +02:00
|
|
|
{/if}
|