-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ingest rate graph for admin panel (#4)
* Add ingest rate graph for admin panel. * Update for bundler changes. * Move ingest rate behind feature flag.
- Loading branch information
Showing
9 changed files
with
330 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,88 @@ | ||
import * as echarts from "echarts"; | ||
|
||
document.getElementById("inject-job")?.addEventListener("click", (ev) => { | ||
if (!confirm("Are you sure you want to inject this job?")) { | ||
ev.preventDefault(); | ||
} | ||
}); | ||
|
||
interface IngestStatUpdate { | ||
timestamp: number; | ||
counts: Record<string, number>; | ||
} | ||
|
||
const ingestStatElement = document.getElementById("ingest-stats"); | ||
|
||
function ingestStatsGraph(elem: HTMLElement) { | ||
let pointDates: Array<Date> = []; | ||
let series: Record<string, any> = {}; | ||
let previousValues: Record<string, number> = {}; | ||
let addedPoints = -1; | ||
|
||
const chart = echarts.init(elem); | ||
|
||
const opts = { | ||
title: { | ||
left: "center", | ||
text: "Ingested Media", | ||
}, | ||
tooltip: { | ||
trigger: "axis", | ||
}, | ||
toolbox: { | ||
feature: { | ||
dataZoom: { | ||
yAxisIndex: "none", | ||
}, | ||
restore: {}, | ||
saveAsImage: {}, | ||
}, | ||
}, | ||
xAxis: { | ||
type: "category", | ||
boundaryGap: false, | ||
data: pointDates, | ||
}, | ||
yAxis: { | ||
name: "Additions", | ||
type: "value", | ||
boundaryGap: [0, "100%"], | ||
}, | ||
series: [], | ||
}; | ||
|
||
chart.setOption(opts); | ||
|
||
const evtSource = new EventSource("/api/ingest/stats"); | ||
|
||
evtSource.onmessage = (e) => { | ||
const data: IngestStatUpdate = JSON.parse(e.data); | ||
|
||
for (let [key, value] of Object.entries(data["counts"])) { | ||
if (series[key] === undefined) { | ||
series[key] = { | ||
name: key, | ||
type: "line", | ||
data: Array(addedPoints + 1).fill(0), | ||
}; | ||
} | ||
|
||
series[key]["data"].push(value - (previousValues[key] || 0)); | ||
previousValues[key] = value; | ||
} | ||
|
||
pointDates.push(new Date(data["timestamp"] * 1000)); | ||
addedPoints += 1; | ||
|
||
chart.setOption({ | ||
xAxis: { | ||
data: pointDates, | ||
}, | ||
series: Object.values(series), | ||
}); | ||
}; | ||
} | ||
|
||
if (ingestStatElement) { | ||
ingestStatsGraph(ingestStatElement); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.