41 days ago · Tech · 0 comments

I wanted to try my new Prometheus setup with some useful data, and since I want to learn how to use Prometheus, I thought it would be fun and useful to do this. In case you're not familiar with it, Prometheus is a server app that gathers metrics in a database. Metrics that are then displayed in some specialized web app such as Grafana (the most popular for this usage). I won't go into details of how to install prometheus, since this can be found in many places on the Web. The JavaScript Here's the JS code I've put on all my pages (in all.js at the top): const worker = new Worker('/javascripts/worker.js'); worker.postMessage({ page: window.location.pathname }); and here's the content of my worker.js: self.onmessage = async (e) => { const { page } = e.data; await fetch('/prom_collector.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: page }), keepalive: true, // survives page unload }); }; BTW, why use JavaScript and not the backend…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.