Implemented stats logging on the connector level - closes #1
This commit is contained in:
parent
890a8a89c7
commit
0716c319a6
5 changed files with 53 additions and 12 deletions
|
@ -271,8 +271,9 @@ namespace Buffer{
|
||||||
tmp += charbuf;
|
tmp += charbuf;
|
||||||
}
|
}
|
||||||
if (tmp != ""){
|
if (tmp != ""){
|
||||||
std::cout << "Push attempt from IP " << tmp << std::endl;
|
if (tmp[0] == 'P'){
|
||||||
if (tmp == waiting_ip){
|
std::cout << "Push attempt from IP " << tmp.substr(2) << std::endl;
|
||||||
|
if (tmp.substr(2) == waiting_ip){
|
||||||
if (!ip_input.connected()){
|
if (!ip_input.connected()){
|
||||||
std::cout << "Push accepted!" << std::endl;
|
std::cout << "Push accepted!" << std::endl;
|
||||||
ip_input = (*usersIt).S;
|
ip_input = (*usersIt).S;
|
||||||
|
@ -285,6 +286,10 @@ namespace Buffer{
|
||||||
(*usersIt).Disconnect("Push denied - invalid IP address!");
|
(*usersIt).Disconnect("Push denied - invalid IP address!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (tmp[0] == 'S'){
|
||||||
|
/// \todo Parse and save stats
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(*usersIt).Send(ringbuf, buffers);
|
(*usersIt).Send(ringbuf, buffers);
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,6 +175,7 @@ namespace Connector_HTTP{
|
||||||
int Segment = -1;
|
int Segment = -1;
|
||||||
int ReqFragment = -1;
|
int ReqFragment = -1;
|
||||||
int temp;
|
int temp;
|
||||||
|
unsigned int lastStats = 0;
|
||||||
//int CurrentFragment = -1; later herbruiken?
|
//int CurrentFragment = -1; later herbruiken?
|
||||||
|
|
||||||
while (conn.connected() && !FLV::Parse_Error){
|
while (conn.connected() && !FLV::Parse_Error){
|
||||||
|
@ -263,6 +264,14 @@ namespace Connector_HTTP{
|
||||||
fprintf(stderr, "Sending a video fragment. %i left in buffer, %i requested\n", (int)Flash_FragBuffer.size(), Flash_RequestPending);
|
fprintf(stderr, "Sending a video fragment. %i left in buffer, %i requested\n", (int)Flash_FragBuffer.size(), Flash_RequestPending);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
if (inited){
|
||||||
|
unsigned int now = time(0);
|
||||||
|
if (now != lastStats){
|
||||||
|
lastStats = now;
|
||||||
|
std::string stat = "S "+conn.getStats();
|
||||||
|
ss.write(stat);
|
||||||
|
}
|
||||||
|
}
|
||||||
ss.canRead();
|
ss.canRead();
|
||||||
switch (ss.ready()){
|
switch (ss.ready()){
|
||||||
case -1:
|
case -1:
|
||||||
|
|
|
@ -58,6 +58,8 @@ int Connector_RTMP::Connector_RTMP(Socket::Connection conn){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int lastStats = 0;
|
||||||
|
|
||||||
while (Socket.connected() && !FLV::Parse_Error){
|
while (Socket.connected() && !FLV::Parse_Error){
|
||||||
//only parse input if available or not yet init'ed
|
//only parse input if available or not yet init'ed
|
||||||
//rightnow = getNowMS();
|
//rightnow = getNowMS();
|
||||||
|
@ -84,6 +86,14 @@ int Connector_RTMP::Connector_RTMP(Socket::Connection conn){
|
||||||
#endif
|
#endif
|
||||||
inited = true;
|
inited = true;
|
||||||
}
|
}
|
||||||
|
if (inited){
|
||||||
|
unsigned int now = time(0);
|
||||||
|
if (now != lastStats){
|
||||||
|
lastStats = now;
|
||||||
|
std::string stat = "S "+Socket.getStats();
|
||||||
|
SS.write(stat);
|
||||||
|
}
|
||||||
|
}
|
||||||
SS.canRead();
|
SS.canRead();
|
||||||
switch (SS.ready()){
|
switch (SS.ready()){
|
||||||
case -1:
|
case -1:
|
||||||
|
@ -374,7 +384,7 @@ void Connector_RTMP::parseChunk(){
|
||||||
Socket.close();//disconnect user
|
Socket.close();//disconnect user
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
SS.write(Socket.getHost()+'\n');
|
SS.write("P "+Socket.getHost()+'\n');
|
||||||
#if DEBUG >= 4
|
#if DEBUG >= 4
|
||||||
fprintf(stderr, "Connected to buffer, starting to sent data...\n");
|
fprintf(stderr, "Connected to buffer, starting to sent data...\n");
|
||||||
#endif
|
#endif
|
||||||
|
@ -594,7 +604,7 @@ void Connector_RTMP::parseChunk(){
|
||||||
Socket.close();//disconnect user
|
Socket.close();//disconnect user
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
SS.write(Socket.getHost()+'\n');
|
SS.write("P "+Socket.getHost()+'\n');
|
||||||
#if DEBUG >= 4
|
#if DEBUG >= 4
|
||||||
fprintf(stderr, "Connected to buffer, starting to send data...\n");
|
fprintf(stderr, "Connected to buffer, starting to send data...\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,12 +11,19 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
std::string uint2string(unsigned int i){
|
||||||
|
std::stringstream st;
|
||||||
|
st << i;
|
||||||
|
return st.str();
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new base socket. This is a basic constructor for converting any valid socket to a Socket::Connection.
|
/// Create a new base socket. This is a basic constructor for converting any valid socket to a Socket::Connection.
|
||||||
/// \param sockNo Integer representing the socket to convert.
|
/// \param sockNo Integer representing the socket to convert.
|
||||||
Socket::Connection::Connection(int sockNo){
|
Socket::Connection::Connection(int sockNo){
|
||||||
sock = sockNo;
|
sock = sockNo;
|
||||||
up = 0;
|
up = 0;
|
||||||
down = 0;
|
down = 0;
|
||||||
|
conntime = time(0);
|
||||||
Error = false;
|
Error = false;
|
||||||
Blocking = false;
|
Blocking = false;
|
||||||
}//Socket::Connection basic constructor
|
}//Socket::Connection basic constructor
|
||||||
|
@ -27,6 +34,7 @@ Socket::Connection::Connection(){
|
||||||
sock = -1;
|
sock = -1;
|
||||||
up = 0;
|
up = 0;
|
||||||
down = 0;
|
down = 0;
|
||||||
|
conntime = time(0);
|
||||||
Error = false;
|
Error = false;
|
||||||
Blocking = false;
|
Blocking = false;
|
||||||
}//Socket::Connection basic constructor
|
}//Socket::Connection basic constructor
|
||||||
|
@ -64,6 +72,7 @@ Socket::Connection::Connection(std::string address, bool nonblock){
|
||||||
Blocking = false;
|
Blocking = false;
|
||||||
up = 0;
|
up = 0;
|
||||||
down = 0;
|
down = 0;
|
||||||
|
conntime = time(0);
|
||||||
sockaddr_un addr;
|
sockaddr_un addr;
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
strncpy(addr.sun_path, address.c_str(), address.size()+1);
|
strncpy(addr.sun_path, address.c_str(), address.size()+1);
|
||||||
|
@ -92,6 +101,7 @@ Socket::Connection::Connection(std::string host, int port, bool nonblock){
|
||||||
Blocking = false;
|
Blocking = false;
|
||||||
up = 0;
|
up = 0;
|
||||||
down = 0;
|
down = 0;
|
||||||
|
conntime = time(0);
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << port;
|
ss << port;
|
||||||
|
|
||||||
|
@ -205,6 +215,11 @@ unsigned int Socket::Connection::dataDown(){
|
||||||
return down;
|
return down;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a std::string of stats, ended by a newline.
|
||||||
|
std::string Socket::Connection::getStats(){
|
||||||
|
return getHost() + uint2string(time(0) - conntime) + " " + uint2string(up) + uint2string(down) + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
/// Writes data to socket. This function blocks if the socket is blocking and all data cannot be written right away.
|
/// Writes data to socket. This function blocks if the socket is blocking and all data cannot be written right away.
|
||||||
/// If the socket is nonblocking and not all data can be written, this function sets internal variable Blocking to true
|
/// If the socket is nonblocking and not all data can be written, this function sets internal variable Blocking to true
|
||||||
/// and returns false.
|
/// and returns false.
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace Socket{
|
||||||
std::string remotehost; ///< Stores remote host address.
|
std::string remotehost; ///< Stores remote host address.
|
||||||
unsigned int up;
|
unsigned int up;
|
||||||
unsigned int down;
|
unsigned int down;
|
||||||
|
unsigned int conntime;
|
||||||
public:
|
public:
|
||||||
Connection(); ///< Create a new disconnected base socket.
|
Connection(); ///< Create a new disconnected base socket.
|
||||||
Connection(int sockNo); ///< Create a new base socket.
|
Connection(int sockNo); ///< Create a new base socket.
|
||||||
|
@ -51,6 +52,7 @@ namespace Socket{
|
||||||
std::string getError(); ///< Returns a string describing the last error that occured.
|
std::string getError(); ///< Returns a string describing the last error that occured.
|
||||||
unsigned int dataUp(); ///< Returns total amount of bytes sent.
|
unsigned int dataUp(); ///< Returns total amount of bytes sent.
|
||||||
unsigned int dataDown(); ///< Returns total amount of bytes received.
|
unsigned int dataDown(); ///< Returns total amount of bytes received.
|
||||||
|
std::string getStats(); ///< Returns a std::string of stats, ended by a newline.
|
||||||
friend class Server;
|
friend class Server;
|
||||||
bool Error; ///< Set to true if a socket error happened.
|
bool Error; ///< Set to true if a socket error happened.
|
||||||
bool Blocking; ///< Set to true if a socket is currently or wants to be blocking.
|
bool Blocking; ///< Set to true if a socket is currently or wants to be blocking.
|
||||||
|
|
Loading…
Add table
Reference in a new issue