Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display round-trip time on the subtitle of the custom service ping #800

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/customservices.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ API key can be generated in Settings > Administration > Auth Tokens

## Ping

For Ping you need to set the type to Ping and provide a url. By default the HEAD method is used but it can be configured to use GET using the optional `method` property.
For Ping you need to set the type to Ping and provide a url. By default the HEAD method is used but it can be configured to use GET using the optional `method` property. You can also choose to show the round trip time (RTT) by setting `showRtt` to true, default is false.

```yaml
- name: "Awesome app"
type: Ping
logo: "assets/tools/sample.png"
subtitle: "Bookmark example"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you support both subtitle and showRtt (see comment below), you can keep this line

tag: "app"
url: "https://www.reddit.com/r/selfhosted/"
method: "head"
showRtt: false
```

## Prometheus
Expand Down
15 changes: 15 additions & 0 deletions src/components/services/Ping.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
{{ status }}
</div>
</template>
<template #content>
<p class="title is-4">{{ item.name }}</p>
<p class="subtitle is-6">
<template v-if="status === 'online' && item.showRtt">
{{ rtt }} ms
</template>
Comment on lines +11 to +13
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to still have the subtitle if showRtt is set to false, could you add it?
Also maybe, if showRtt is set to true, and service is not online, it could say "Unknown RTT" or something like that?

</p>
</template>
</Generic>
</template>

Expand All @@ -23,6 +31,7 @@ export default {
},
data: () => ({
status: null,
rtt: null,
}),
created() {
this.fetchStatus();
Expand All @@ -39,12 +48,17 @@ export default {
return;
}

const startTime = performance.now();

this.fetch("/", { method, cache: "no-cache" }, false)
.then(() => {
this.status = "online";
const endTime = performance.now();
this.rtt = Math.round(endTime - startTime);
})
.catch(() => {
this.status = "offline";
this.rtt = null; // Reset rtt on failure
});
},
},
Expand Down Expand Up @@ -81,3 +95,4 @@ export default {
}
}
</style>