Skip to content

Commit 446c406

Browse files
authored
Merge pull request #3585 from MrKomodoDragon/service-status-frontend
LB-1680: Add frontend display of service status
2 parents 0a45760 + ec1be66 commit 446c406

File tree

3 files changed

+74
-10
lines changed

3 files changed

+74
-10
lines changed

frontend/js/src/about/current-status/CurrentStatus.tsx

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { useQuery } from "@tanstack/react-query";
22
import React from "react";
33
import { useLocation } from "react-router";
44
import { RouteQuery } from "../../utils/Loader";
5+
import {
6+
fullLocalizedDateFromTimestampOrISODate,
7+
formatSecondsDuration,
8+
} from "../../utils/utils";
9+
510
import UserEvolutionChart, { UserEvolutionData } from "./UserEvolutionChart";
611

712
type CurrentStatusLoaderData = {
@@ -12,16 +17,23 @@ type CurrentStatusLoaderData = {
1217
label: string;
1318
}[];
1419
userCount: number;
20+
serviceStatus: {
21+
time: number;
22+
dump_age: number;
23+
stats_age: number;
24+
sitewide_stats_age: number;
25+
incoming_listen_count: number;
26+
};
1527
userCountEvolution: UserEvolutionData[];
16-
load: string;
1728
};
1829

1930
export default function CurrentStatus() {
2031
const location = useLocation();
2132
const { data } = useQuery<CurrentStatusLoaderData>(
2233
RouteQuery(["current-status"], location.pathname)
2334
);
24-
const { userCount, listenCount, listenCountsPerDay, load } = data || {};
35+
const { userCount, listenCount, listenCountsPerDay, serviceStatus } =
36+
data || {};
2537
return (
2638
<>
2739
<h2 className="page-title">Current status</h2>
@@ -88,10 +100,58 @@ export default function CurrentStatus() {
88100
doc.
89101
</p>
90102

91-
<h3>load average</h3>
92-
93-
<p>Current server load average</p>
94-
<div className="border p-4 rounded bg-body-tertiary">{load}</div>
103+
<h3>Current Service Status</h3>
104+
<table className="table table-border table-sm table-striped">
105+
<thead>
106+
<tr>
107+
<th>Field</th>
108+
<th>Value</th>
109+
</tr>
110+
</thead>
111+
<tbody>
112+
{serviceStatus && (
113+
<tr>
114+
<td>Last Updated</td>
115+
<td>
116+
{fullLocalizedDateFromTimestampOrISODate(
117+
new Date(serviceStatus.time * 1000)
118+
)}
119+
</td>
120+
</tr>
121+
)}
122+
{serviceStatus && (
123+
<tr>
124+
<td>Database Dump Age</td>
125+
<td>{formatSecondsDuration(serviceStatus.dump_age)}</td>
126+
</tr>
127+
)}
128+
{serviceStatus && (
129+
<tr>
130+
<td>Stats Age</td>
131+
<td>{formatSecondsDuration(serviceStatus.stats_age)}</td>
132+
</tr>
133+
)}
134+
{serviceStatus && (
135+
<tr>
136+
<td>Sitewide Stats Age</td>
137+
<td>
138+
{formatSecondsDuration(serviceStatus.sitewide_stats_age)}
139+
</td>
140+
</tr>
141+
)}
142+
{serviceStatus && (
143+
<tr>
144+
<td>Incoming Listen Count</td>
145+
<td>
146+
{new Intl.NumberFormat().format(
147+
serviceStatus.incoming_listen_count
148+
)}{" "}
149+
listens
150+
</td>
151+
</tr>
152+
)}
153+
</tbody>
154+
</table>
95155
</div>
96156
</div>
97157
</>

frontend/js/src/utils/utils.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Rating } from "react-simple-star-rating";
66
import { toast } from "react-toastify";
77
import { Link } from "react-router";
88
import ReactMarkdown from "react-markdown";
9+
import { formatDuration, intervalToDuration } from "date-fns";
910
import SpotifyPlayer from "../common/brainzplayer/SpotifyPlayer";
1011
import YoutubePlayer from "../common/brainzplayer/YoutubePlayer";
1112
import NamePill from "../personal-recommendations/NamePill";
@@ -729,6 +730,11 @@ const preciseTimestamp = (
729730
return `${timeago.ago(listened_at)}`;
730731
}
731732
};
733+
const formatSecondsDuration = (seconds: number): string => {
734+
return formatDuration(intervalToDuration({ start: 0, end: seconds * 1000 }), {
735+
format: ["months", "days", "hours", "minutes"],
736+
});
737+
};
732738
// recieves or unix epoch timestamp int or ISO datetime string
733739
const fullLocalizedDateFromTimestampOrISODate = (
734740
unix_epoch_timestamp: number | string | Date | undefined | null
@@ -1454,6 +1460,7 @@ export {
14541460
getAlbumLink,
14551461
formatWSMessageToListen,
14561462
preciseTimestamp,
1463+
formatSecondsDuration,
14571464
fullLocalizedDateFromTimestampOrISODate,
14581465
convertDateToUnixTimestamp,
14591466
getPageProps,

listenbrainz/webserver/views/index.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ def index():
9393
@index_bp.post("/current-status/")
9494
@web_listenstore_needed
9595
def current_status():
96-
load = "%.2f %.2f %.2f" % os.getloadavg()
97-
9896
service_status = get_service_status()
9997
listen_count = _ts.get_total_listen_count()
10098
try:
@@ -128,8 +126,7 @@ def current_status():
128126
})
129127

130128
data = {
131-
"load": load,
132-
"service-status": service_status,
129+
"serviceStatus": service_status,
133130
"listenCount": format(int(listen_count), ",d") if listen_count else "0",
134131
"userCount": user_count,
135132
"userCountEvolution": user_count_evolution,

0 commit comments

Comments
 (0)