Edward-Wu / srt-live-server

srt live server for low latency
Other
654 stars 196 forks source link

Statistics #43

Open yannisgu opened 4 years ago

yannisgu commented 4 years ago

Hello Edward,

I would like to be able to see the SRT statistics (Dropped packages, RTT, etc...). I configured the stat_post_url and my API is called all 5 seconds, however the call is empty. There are no query string nor request body. How can I now access the statistics?

Cheers, Yannis

Edward-Wu commented 4 years ago

hi, Yannis, the stat_post_url is not for SRT statistic info, but just for sis connection info , such as: const char SLS_SERVER_STAT_INFO_BASE[] = "\ {\ \"port\": \"%d\",\ \"role\": \"%s\",\ \"pub_domain_app\": \"\",\ \"stream_name\": \"\",\ \"url\": \"\",\ \"remote_ip\": \"\",\ \"remote_port\": \"\",\ \"start_time\": \"%s\",\ \"kbitrate\": \"0\"\ }";

if you want to get the SRT statistic info please add a interface like stat_srt_post_url by yourself.

rodneyallan commented 4 years ago

Hello Edward, it is also empty for me as well. I don't see any sis connection info. The only modification I did was to change the stat_post_url. I can see the call being made, but there is no data.

matiaspl commented 4 years ago

Same for me. Callback URL works fine, stat returns empty body.

odensc commented 4 years ago

Hey folks - I (hopefully) fixed this in #54. Feel free to give it a try from my fork: https://github.com/odensc/srt-live-server

rodneyallan commented 4 years ago

Thanks, I will give this a try.

Edward-Wu commented 4 years ago

hi, rodneyallan how 's your test result?

rodneyallan commented 4 years ago

@Edward-Wu I have not had a chance to test it yet. I will try it this week.

konjkavi commented 4 years ago

Hi, sls is installed on an U18.04 VPS. Publish, Play and Record are working! However, when a connection info request is sent from browser to http://publicip:8001/sls/stat there's no response. Same result using "odensc" fork.

sls.conf : stat_post_url http://publicip:8001/sls/stat;

error.log says 'Connection refused': SLS_INFO : [0x55c65c70b730]CTCPRole::connect, ok, m_fd=6, host=publicip, port==8001. : [0x55c65c70b730]CHttpClient::generate_http_request, write_post_content, ret=0, remote_host='publicip', remote_port=8001. : [0x55c65c70b730]CHttpClient::generate_http_request, ok, m_url='http://publicip:8001/sls/stat', content len=2. : [0x55c65c70b730]CTCPRole::read, len=-1, errno=111, err='Connection refused' : [0x55c65c70b730]CTCPRole::read, invalid tcp. .... : [0x55e03202f730]CHttpClient::check_timeout, ok, url='http://publicip:8001/sls/stat', http_method='POST', content_len=0, m_response_content_length=-1.

UFW is disabled! Assuming this is not a bug, appreciate comments on what may be causing the connection refused and invalid tcp. Thanks.

odensc commented 4 years ago

@konjkavi You can't request that URL from the browser, that's the URL it sends the stats to. So you need a server running on that IP that can receive the JSON POST data.

konjkavi commented 4 years ago

Thanks. I know this request is outside the scope of this section, but would you have a NGINX conf file by any chance for receiving JSON POST?

odensc commented 4 years ago

Nope sorry, I'd recommend a simple Node.js server using express to test.

konjkavi commented 4 years ago

Have not worked with node.js before, but created app.js (below) on the same sls server listening on port 3000 . The publicip:3000 responds to requests, but /sls/stat still not working. Obviously my app.js is no good. Appreciate if you could post replacement lines so that I may get stat working. Thank you.

const express = require('express') const app = express() const port = 3000

app.post('/sls/stat', function(request, response){ console.log(request.body); // your JSON response.send(request.body); // echo the result back });

app.listen(port, () => { console.log(srt stat listening at http://localhost:${port})

odensc commented 4 years ago

You need body-parser. This should work:

const express = require("express");
const bodyParser = require("body-parser");

const app = express();
app.use(bodyParser.json());

app.post("/sls/stat", (req, res) => {
    console.log(req.body)

    res.sendStatus(200);
});

app.listen(3000, () => console.log("Server started"));
konjkavi commented 4 years ago

Hmm... server response to http://publicip:3000/sls/stat is: "Cannot GET /sls/stat"

FYI, sls server is up and ffplay currently playing srt stream from it. Furthermore, sls says: [0x55cef2723730]CTCPRole::setup, setsockopt reused ok, m_fd=6. : [0x55cef2723730]CTCPRole::set_nonblock, set O_NONBLOCK ok, m_fd=6. : [0x55cef2723730]CTCPRole::connect, ok, m_fd=6, host=publicip, port==3000. : [0x55cef2723730]CHttpClient::generate_http_request, write_post_content, ret=0, remote_host='publicip', remote_port=3000. : [0x55cef2723730]CHttpClient::generate_http_request, ok, m_url='http://publicip:3000/sls/stat', content len=388. [0x55cef2723730]CHttpClient::parse_http_response, m_response_code:'200', url='http://publicip:3000/sls/stat', http_method='POST'. : [0x55cef2723730]CHttpClient::parse_http_response, m_response_content_length=2. : [0x55cef2723730]CHttpClient::parse_http_response, finished, url='http://publicip:3000/sls/stat', http_method='POST', content_len=2. : [0x55cef2723730]CHttpClient::recv, finished. : [0x55cef2723730]CTCPRole::close ok, m_fd=6.

Any thoughts? Thanks.

odensc commented 4 years ago

It completed the POST request successfully. The Node.js server should have printed the JSON data to the console - do you not see that?

You won't be able to GET the url, you would have to implement that (e.g assign the request body to a variable and send that back via the GET route)

konjkavi commented 4 years ago

Yes, I do see the stats now in console. Thank you. This is fine for now, but if you happens to have the full code that allows GET from URL, that would be awesome.

Feedback: If one day this project could come to have similar capabilities to "https://github.com/arut/nginx-rtmp-module" its utilization and popularity could balloon. From my perspective, most critical will be adapt and/or extend the current ts file recording to provide live multi bit rate hls stream. Thanks again for your help today.

odensc commented 4 years ago

Something like this should work.

const express = require("express");
const bodyParser = require("body-parser");

const app = express();
app.use(bodyParser.json());

let lastStats = {};

app.post("/sls/stat", (req, res) => {
    lastStats = req.body;

    res.sendStatus(200);
});

app.get("/sls/stat", (req, res) => res.json(lastStats));

app.listen(3000, () => console.log("Server started"));
konjkavi commented 4 years ago

It does work! Much appreciated. Thank you.

rodneyallan commented 4 years ago

@Edward-Wu and @odensc - sorry for the long delay, but I have finally be able to test the fork and it looks like it works.

[ { port: '8080', role: 'player', pub_domain_app: 'uplive.sls.com/live', stream_name: 'Lydia', url: 'live.sls.com/live/Lydia', remote_ip: '209.177.xxx.xxx', remote_port: '38535', start_time: '2020-10-08 15:41:35', kbitrate: '1347' }, { port: '8080', role: 'publisher', pub_domain_app: 'uplive.sls.com/live', stream_name: 'Lydia', url: 'uplive.sls.com/live/Lydia', remote_ip: '209.87.xxx.xxx', remote_port: '55484', start_time: '2020-10-08 15:41:33', kbitrate: '1376' }, { port: '8080', role: 'listener', pub_domain_app: '', stream_name: '', url: '', remote_ip: '', remote_port: '', start_time: '2020-10-08 15:41:29', kbitrate: '0' } ]

jengajenga commented 3 years ago

Hi guys. I'm pretty new to SRT but coming from an NGIN/RTMP background.

How exactly are we making this happen? When I click on my link the, server says no such page exists. Firewalls are off, internet is strong and stable.

Secondly, where does the code written by @odensc go? do i create a .js , paste the code and put it in the html folder?