add guppe server status to web views and explain active groups

This commit is contained in:
Will Murphy 2022-11-07 21:14:30 -06:00
parent 45bf8f9674
commit 367ca308d6
3 changed files with 58 additions and 2 deletions

View file

@ -49,7 +49,8 @@ const apex = ActivitypubExpress({
actorParam: 'actor', actorParam: 'actor',
objectParam: 'id', objectParam: 'id',
itemsPerPage: 100, itemsPerPage: 100,
offlineMode: true, // delivery done in workers only // delivery done in workers only in production
offlineMode: process.env.NODE_ENV === 'production',
routes routes
}) })
@ -174,6 +175,16 @@ app.get('/groups', (req, res, next) => {
return res.status(500).send() return res.status(500).send()
}) })
}) })
app.get('/stats', async (req, res, next) => {
try {
const queueSize = await apex.store.db.collection('deliveryQueue')
.countDocuments({ attempt: 0 })
const uptime = process.uptime()
res.json({ queueSize, uptime })
} catch (err) {
next(err)
}
})
app.use(function (err, req, res, next) { app.use(function (err, req, res, next) {
console.error(err.message, req.body, err.stack) console.error(err.message, req.body, err.stack)

View file

@ -1,8 +1,12 @@
<template> <template>
<div id="app"> <div id="app">
<div class="w3-bar w3-black w3-card"> <div class="w3-bar w3-black w3-card">
<div class="w3-container w3-section"> <div class="w3-section flex">
<router-link to="/"><i class="fas fa-home" title="home"></i></router-link> <router-link to="/"><i class="fas fa-home" title="home"></i></router-link>
<div v-if="stats" class="flex">
<div>Uptime: {{ uptime }}</div>
<div>Backlog: {{ queueSize }}</div>
</div>
</div> </div>
</div> </div>
<div class="w3-row"> <div class="w3-row">
@ -18,6 +22,38 @@
</div> </div>
</template> </template>
<script>
export default {
data () {
return {
stats: undefined
}
},
mounted () {
window.fetch('/stats', { headers: { Accept: 'application/json' } })
.then(res => res.json())
.then(data => (this.stats = data))
.catch(err => console.warn('Error fetching stats', err))
},
computed: {
uptime () {
if (!this.stats) {
return
}
const fmtd = (this.stats.uptime / 3600)
.toLocaleString(undefined, { maximumFractionDigits: 1, minimumFractionDigits: 1 })
return `${fmtd} hours`
},
queueSize () {
if (!this.stats) {
return
}
return `${this.stats.queueSize.toLocaleString()} posts`
}
}
}
</script>
<style> <style>
#app { #app {
font-family: 'Avenir', Helvetica, Arial, sans-serif; font-family: 'Avenir', Helvetica, Arial, sans-serif;
@ -25,4 +61,12 @@
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
color: #2c3e50; color: #2c3e50;
} }
.flex {
display: flex;
justify-content: space-between;
}
.flex > * {
padding-left: 16px;
padding-right: 16px;
}
</style> </style>

View file

@ -22,6 +22,7 @@
<li>Visit a @{{ domain }} group profile to see the group history</li> <li>Visit a @{{ domain }} group profile to see the group history</li>
</ol> </ol>
<h2 class="w3-center">Active Groups</h2> <h2 class="w3-center">Active Groups</h2>
<p class="w3-center">Top 50 groups with the most recent posts</p>
<div class="profile-grid w3-margin-bottom w3-mobile"> <div class="profile-grid w3-margin-bottom w3-mobile">
<div v-for="group of groups" class="w3-card w3-container w3-section" :key="group._id"> <div v-for="group of groups" class="w3-card w3-container w3-section" :key="group._id">
<profile-summary :actor="group" class="profile"/> <profile-summary :actor="group" class="profile"/>