Working VoD stats.
This commit is contained in:
parent
c57c9b64d3
commit
df4b8b1568
2 changed files with 49 additions and 1 deletions
|
@ -264,6 +264,25 @@ void CheckStats(JSON::Value & stats){
|
||||||
if (currTime - lastBuffer[jit->first] > 120){
|
if (currTime - lastBuffer[jit->first] > 120){
|
||||||
stats.removeMember(jit->first);
|
stats.removeMember(jit->first);
|
||||||
return;
|
return;
|
||||||
|
}else{
|
||||||
|
if (jit->second.isMember("curr") && jit->second["curr"].size() > 0){
|
||||||
|
long long int nowtime = time(0);
|
||||||
|
for (JSON::ObjIter u_it = jit->second["curr"].ObjBegin(); u_it != jit->second["curr"].ObjEnd(); ++u_it){
|
||||||
|
if (u_it->second.isMember("now") && u_it->second["now"].asInt() < nowtime - 3){
|
||||||
|
jit->second["log"].append(u_it->second);
|
||||||
|
jit->second["curr"].removeMember(u_it->first);
|
||||||
|
if (jit->second["curr"].size() < 1){
|
||||||
|
break;
|
||||||
|
}else{
|
||||||
|
if (jit->second["curr"].ObjBegin() != u_it){
|
||||||
|
u_it--;
|
||||||
|
}else{
|
||||||
|
u_it = jit->second["curr"].ObjBegin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -438,6 +457,7 @@ int main(int argc, char ** argv){
|
||||||
Connector::Storage["statistics"][thisbuffer]["curr"] = Request["curr"];
|
Connector::Storage["statistics"][thisbuffer]["curr"] = Request["curr"];
|
||||||
std::string nowstr = Request["totals"]["now"].asString();
|
std::string nowstr = Request["totals"]["now"].asString();
|
||||||
Connector::Storage["statistics"][thisbuffer]["totals"][nowstr] = Request["totals"];
|
Connector::Storage["statistics"][thisbuffer]["totals"][nowstr] = Request["totals"];
|
||||||
|
Connector::Storage["statistics"][thisbuffer]["totals"][nowstr].removeMember("now");
|
||||||
Connector::Storage["statistics"][thisbuffer]["totals"].shrink(600);//limit to 10 minutes of data
|
Connector::Storage["statistics"][thisbuffer]["totals"].shrink(600);//limit to 10 minutes of data
|
||||||
//if metadata is available, store it
|
//if metadata is available, store it
|
||||||
for (JSON::ObjIter jit = Request["log"].ObjBegin(); jit != Request["log"].ObjEnd(); jit++){
|
for (JSON::ObjIter jit = Request["log"].ObjBegin(); jit != Request["log"].ObjEnd(); jit++){
|
||||||
|
@ -446,6 +466,29 @@ int main(int argc, char ** argv){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Request.isMember("vod")){
|
||||||
|
std::string thisfile = Request["vod"]["filename"];
|
||||||
|
for (JSON::ObjIter oit = Connector::Storage["streams"].ObjBegin(); oit != Connector::Storage["streams"].ObjEnd(); ++oit){
|
||||||
|
if (oit->second["channel"]["URL"].asString() == thisfile){
|
||||||
|
Connector::lastBuffer[oit->first] = time(0);
|
||||||
|
if (Request["vod"].isMember("meta")){
|
||||||
|
Connector::Storage["statistics"][oit->first]["meta"] = Request["vod"]["meta"];
|
||||||
|
}
|
||||||
|
JSON::Value sockit = (long long int)it->getSocket();
|
||||||
|
std::string nowstr = Request["vod"]["now"].asString();
|
||||||
|
Connector::Storage["statistics"][oit->first]["curr"][sockit.asString()] = Request["vod"];
|
||||||
|
Connector::Storage["statistics"][oit->first]["curr"][sockit.asString()].removeMember("meta");
|
||||||
|
JSON::Value nowtotal;
|
||||||
|
for (JSON::ObjIter u_it = Connector::Storage["statistics"][oit->first]["curr"].ObjBegin(); u_it != Connector::Storage["statistics"][oit->first]["curr"].ObjEnd(); ++u_it){
|
||||||
|
nowtotal["up"] = nowtotal["up"].asInt() + u_it->second["up"].asInt();
|
||||||
|
nowtotal["down"] = nowtotal["down"].asInt() + u_it->second["down"].asInt();
|
||||||
|
nowtotal["count"] = nowtotal["count"].asInt() + 1;
|
||||||
|
}
|
||||||
|
Connector::Storage["statistics"][oit->first]["totals"][nowstr] = nowtotal;
|
||||||
|
Connector::Storage["statistics"][oit->first]["totals"].shrink(600);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
it->Received().erase(0, newlines+2);
|
it->Received().erase(0, newlines+2);
|
||||||
newlines = it->Received().find("\n\n");
|
newlines = it->Received().find("\n\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,7 @@ int main(int argc, char** argv){
|
||||||
JSON::Value meta = JSON::fromDTMI(meta_str);
|
JSON::Value meta = JSON::fromDTMI(meta_str);
|
||||||
JSON::Value last_pack;
|
JSON::Value last_pack;
|
||||||
|
|
||||||
|
bool meta_sent = false;
|
||||||
long long now, timeDiff = 0, lastTime = 0;
|
long long now, timeDiff = 0, lastTime = 0;
|
||||||
Stats sts;
|
Stats sts;
|
||||||
|
|
||||||
|
@ -115,7 +116,11 @@ int main(int argc, char** argv){
|
||||||
json_sts["vod"]["connector"] = sts.connector;
|
json_sts["vod"]["connector"] = sts.connector;
|
||||||
json_sts["vod"]["filename"] = conf.getString("filename");
|
json_sts["vod"]["filename"] = conf.getString("filename");
|
||||||
json_sts["vod"]["now"] = (long long int)time(0);
|
json_sts["vod"]["now"] = (long long int)time(0);
|
||||||
|
json_sts["vod"]["start"] = (long long int)(time(0) - sts.conntime);
|
||||||
|
if (!meta_sent){
|
||||||
json_sts["vod"]["meta"] = meta;
|
json_sts["vod"]["meta"] = meta;
|
||||||
|
meta_sent = true;
|
||||||
|
}
|
||||||
StatsSocket.Send(json_sts.toString().c_str());
|
StatsSocket.Send(json_sts.toString().c_str());
|
||||||
StatsSocket.Send("\n\n");
|
StatsSocket.Send("\n\n");
|
||||||
StatsSocket.flush();
|
StatsSocket.flush();
|
||||||
|
|
Loading…
Add table
Reference in a new issue