poll an http URL and show stats

269 views Asked by At

I'm working on something where I need to poll an http URL and get the numbers available as part of the response and show graphical stats on a web page.

Does anyone know of any opensource software which can do something like this?

Sample URL:

http://dataqueue.com:8080/datamq/message/getcount?q=order.sales&class=com.xyz.entitiy.Order&metadata={}

which Results 15000

then another url would result 10000 etc.

1

There are 1 answers

0
Fabian Schultz On

If I understand your question correctly, you can use plain Javascript to achieve something like this. Here's an example that does a server request every five seconds:

function req() {
  fetch('http://reqres.in/api/users', {
    method: 'post',
    body: JSON.stringify({
      name: 'morpheus',
      job: 'leader'
    })})
    .then(res => res.json())
    .then(json => {
      document.getElementById('View').innerHTML =  json.id;
    });
}

req();
setInterval(() => req(), 5000);
<div id="View"></div>

There are also libraries that make this easier, for example PollJS. You can find more on Github. If you have control over the server, you might want to check out Socket.io.