Skip to content

Commit c77c3cf

Browse files
committed
Show uptime on landing page
1 parent 5a7eded commit c77c3cf

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/apps/relay/RelayWebsocket.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void RelayServer::runWebsocket(ThreadPool<MsgWebsocket>::Thread &thr) {
4545
flat_hash_map<uint64_t, Connection*> connIdToConnection;
4646
uint64_t nextConnectionId = 1;
4747
bool gracefulShutdown = false;
48+
uint64_t serverStart = ::time(nullptr);
4849

4950
std::string tempBuf;
5051
tempBuf.reserve(cfg().events__maxEventSize + MAX_SUBID_SIZE + 100);
@@ -102,8 +103,8 @@ void RelayServer::runWebsocket(ThreadPool<MsgWebsocket>::Thread &thr) {
102103
return std::string_view(rendered); // memory only valid until next call
103104
};
104105

105-
auto getLandingPageHttpResponse = [&supportedNips, ver = uint64_t(0), rendered = std::string("")]() mutable {
106-
if (ver != cfg().version()) {
106+
auto getLandingPageHttpResponse = [&supportedNips, &serverStart, ver = uint64_t(0), lastUpdate = uint64_t(0), rendered = std::string("")]() mutable {
107+
if (ver != cfg().version() || (uint64_t)::time(nullptr) - lastUpdate > 3600) {
107108
auto maybeUrl = [](std::string_view inp){
108109
if (inp.starts_with("http://") || inp.starts_with("https://")) {
109110
std::string output = "<a href=\"";
@@ -121,10 +122,12 @@ void RelayServer::runWebsocket(ThreadPool<MsgWebsocket>::Thread &thr) {
121122
std::string version;
122123
uint64_t negentropy;
123124
std::function<std::string(std::string_view)> maybeUrl;
124-
} ctx = { tao::json::to_string(supportedNips()), APP_GIT_VERSION, negentropy::PROTOCOL_VERSION - 0x60, maybeUrl };
125+
uint64_t uptime;
126+
} ctx = { tao::json::to_string(supportedNips()), APP_GIT_VERSION, negentropy::PROTOCOL_VERSION - 0x60, maybeUrl, (uint64_t)::time(nullptr) - serverStart };
125127

126128
rendered = preGenerateHttpResponse("text/html", ::strfrytmpl::landing(ctx).str);
127129
ver = cfg().version();
130+
lastUpdate = ::time(nullptr);
128131
}
129132

130133
return std::string_view(rendered); // memory only valid until next call

src/tmpls/landing.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@
187187
<td><a href="https://github.com/hoytech/negentropy">negentropy</a></td>
188188
<td>$(ctx.negentropy)</td>
189189
</tr>
190+
191+
<tr>
192+
<td>Uptime</td>
193+
<td>$(ctx.uptime / 86400) days</td>
194+
</tr>
190195
</table>
191196
</body>
192197
</html>

0 commit comments

Comments
 (0)