Supporting library build
This commit is contained in:
8
cui.cpp
8
cui.cpp
@@ -412,22 +412,22 @@ void do_refresh()
|
||||
if (viewMode == VIEWMODE_KBPS)
|
||||
{
|
||||
//std::cout << "kbps viemode" << std::endl;
|
||||
getkbps (curproc->getVal(), &value_recv, &value_sent);
|
||||
curproc->getVal()->getkbps (&value_recv, &value_sent);
|
||||
}
|
||||
else if (viewMode == VIEWMODE_TOTAL_KB)
|
||||
{
|
||||
//std::cout << "total viemode" << std::endl;
|
||||
gettotalkb(curproc->getVal(), &value_recv, &value_sent);
|
||||
curproc->getVal()->gettotalkb(&value_recv, &value_sent);
|
||||
}
|
||||
else if (viewMode == VIEWMODE_TOTAL_MB)
|
||||
{
|
||||
//std::cout << "total viemode" << std::endl;
|
||||
gettotalmb(curproc->getVal(), &value_recv, &value_sent);
|
||||
curproc->getVal()->gettotalmb(&value_recv, &value_sent);
|
||||
}
|
||||
else if (viewMode == VIEWMODE_TOTAL_B)
|
||||
{
|
||||
//std::cout << "total viemode" << std::endl;
|
||||
gettotalb(curproc->getVal(), &value_recv, &value_sent);
|
||||
curproc->getVal()->gettotalb(&value_recv, &value_sent);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -183,8 +183,8 @@ void NethogsMonitor::handleUpdate()
|
||||
u_int32_t recv_bytes;
|
||||
float sent_kbs;
|
||||
float recv_kbs;
|
||||
getkbps (curproc->getVal(), &sent_kbs, &recv_kbs);
|
||||
gettotal (curproc->getVal(), &recv_bytes, &sent_bytes);
|
||||
curproc->getVal()->getkbps (&sent_kbs, &recv_kbs);
|
||||
curproc->getVal()->gettotal (&recv_bytes, &sent_bytes);
|
||||
|
||||
if( monitor_udpate_callback )
|
||||
{
|
||||
|
||||
205
process.cpp
205
process.cpp
@@ -75,6 +75,21 @@ ProcList * processes;
|
||||
std::map <std::string, Process*> unknownprocs;
|
||||
|
||||
|
||||
float tomb (u_int32_t bytes)
|
||||
{
|
||||
return ((double)bytes) / 1024 / 1024;
|
||||
}
|
||||
float tokb (u_int32_t bytes)
|
||||
{
|
||||
return ((double)bytes) / 1024;
|
||||
}
|
||||
|
||||
float tokbps (u_int32_t bytes)
|
||||
{
|
||||
return (((double)bytes) / PERIOD) / 1024;
|
||||
}
|
||||
|
||||
|
||||
void process_init ()
|
||||
{
|
||||
unknowntcp = new Process (0, "", "unknown TCP");
|
||||
@@ -100,6 +115,94 @@ int Process::getLastPacket()
|
||||
return lastpacket;
|
||||
}
|
||||
|
||||
/** Get the kb/s values for this process */
|
||||
void Process::getkbps (float * recvd, float * sent)
|
||||
{
|
||||
u_int32_t sum_sent = 0,
|
||||
sum_recv = 0;
|
||||
|
||||
/* walk though all this process's connections, and sum
|
||||
* them up */
|
||||
ConnList * curconn = this->connections;
|
||||
ConnList * previous = NULL;
|
||||
while (curconn != NULL)
|
||||
{
|
||||
if (curconn->getVal()->getLastPacket() <= curtime.tv_sec - CONNTIMEOUT)
|
||||
{
|
||||
/* stalled connection, remove. */
|
||||
ConnList * todelete = curconn;
|
||||
Connection * conn_todelete = curconn->getVal();
|
||||
curconn = curconn->getNext();
|
||||
if (todelete == this->connections)
|
||||
this->connections = curconn;
|
||||
if (previous != NULL)
|
||||
previous->setNext(curconn);
|
||||
delete (todelete);
|
||||
delete (conn_todelete);
|
||||
}
|
||||
else
|
||||
{
|
||||
u_int32_t sent = 0, recv = 0;
|
||||
curconn->getVal()->sumanddel(curtime, &recv, &sent);
|
||||
sum_sent += sent;
|
||||
sum_recv += recv;
|
||||
previous = curconn;
|
||||
curconn = curconn->getNext();
|
||||
}
|
||||
}
|
||||
*recvd = tokbps(sum_recv);
|
||||
*sent = tokbps(sum_sent);
|
||||
}
|
||||
|
||||
/** get total values for this process */
|
||||
void Process::gettotal( u_int32_t * recvd, u_int32_t * sent)
|
||||
{
|
||||
u_int32_t sum_sent = 0,
|
||||
sum_recv = 0;
|
||||
ConnList * curconn = this->connections;
|
||||
while (curconn != NULL)
|
||||
{
|
||||
Connection * conn = curconn->getVal();
|
||||
sum_sent += conn->sumSent;
|
||||
sum_recv += conn->sumRecv;
|
||||
curconn = curconn->getNext();
|
||||
}
|
||||
//std::cout << "Sum sent: " << sum_sent << std::endl;
|
||||
//std::cout << "Sum recv: " << sum_recv << std::endl;
|
||||
*recvd = sum_recv;
|
||||
*sent = sum_sent;
|
||||
}
|
||||
|
||||
void Process::gettotalmb(float * recvd, float * sent)
|
||||
{
|
||||
u_int32_t sum_sent = 0,
|
||||
sum_recv = 0;
|
||||
gettotal(&sum_recv, &sum_sent);
|
||||
*recvd = tomb(sum_recv);
|
||||
*sent = tomb(sum_sent);
|
||||
}
|
||||
|
||||
/** get total values for this process */
|
||||
void Process::gettotalkb(float * recvd, float * sent)
|
||||
{
|
||||
u_int32_t sum_sent = 0,
|
||||
sum_recv = 0;
|
||||
gettotal(&sum_recv, &sum_sent);
|
||||
*recvd = tokb(sum_recv);
|
||||
*sent = tokb(sum_sent);
|
||||
}
|
||||
|
||||
void Process::gettotalb(float * recvd, float * sent)
|
||||
{
|
||||
u_int32_t sum_sent = 0,
|
||||
sum_recv = 0;
|
||||
gettotal(&sum_recv, &sum_sent);
|
||||
//std::cout << "Total sent: " << sum_sent << std::endl;
|
||||
*sent = sum_sent;
|
||||
*recvd = sum_recv;
|
||||
}
|
||||
|
||||
|
||||
Process * findProcess (struct prg_node * node)
|
||||
{
|
||||
ProcList * current = processes;
|
||||
@@ -295,105 +398,3 @@ void procclean ()
|
||||
//delete conninode;
|
||||
prg_cache_clear();
|
||||
}
|
||||
|
||||
|
||||
/** Get the kb/s values for this process */
|
||||
void getkbps (Process * curproc, float * recvd, float * sent)
|
||||
{
|
||||
u_int32_t sum_sent = 0,
|
||||
sum_recv = 0;
|
||||
|
||||
/* walk though all this process's connections, and sum
|
||||
* them up */
|
||||
ConnList * curconn = curproc->connections;
|
||||
ConnList * previous = NULL;
|
||||
while (curconn != NULL)
|
||||
{
|
||||
if (curconn->getVal()->getLastPacket() <= curtime.tv_sec - CONNTIMEOUT)
|
||||
{
|
||||
/* stalled connection, remove. */
|
||||
ConnList * todelete = curconn;
|
||||
Connection * conn_todelete = curconn->getVal();
|
||||
curconn = curconn->getNext();
|
||||
if (todelete == curproc->connections)
|
||||
curproc->connections = curconn;
|
||||
if (previous != NULL)
|
||||
previous->setNext(curconn);
|
||||
delete (todelete);
|
||||
delete (conn_todelete);
|
||||
}
|
||||
else
|
||||
{
|
||||
u_int32_t sent = 0, recv = 0;
|
||||
curconn->getVal()->sumanddel(curtime, &recv, &sent);
|
||||
sum_sent += sent;
|
||||
sum_recv += recv;
|
||||
previous = curconn;
|
||||
curconn = curconn->getNext();
|
||||
}
|
||||
}
|
||||
*recvd = tokbps(sum_recv);
|
||||
*sent = tokbps(sum_sent);
|
||||
}
|
||||
|
||||
/** get total values for this process */
|
||||
void gettotal(Process * curproc, u_int32_t * recvd, u_int32_t * sent)
|
||||
{
|
||||
u_int32_t sum_sent = 0,
|
||||
sum_recv = 0;
|
||||
ConnList * curconn = curproc->connections;
|
||||
while (curconn != NULL)
|
||||
{
|
||||
Connection * conn = curconn->getVal();
|
||||
sum_sent += conn->sumSent;
|
||||
sum_recv += conn->sumRecv;
|
||||
curconn = curconn->getNext();
|
||||
}
|
||||
//std::cout << "Sum sent: " << sum_sent << std::endl;
|
||||
//std::cout << "Sum recv: " << sum_recv << std::endl;
|
||||
*recvd = sum_recv;
|
||||
*sent = sum_sent;
|
||||
}
|
||||
|
||||
void gettotalmb(Process * curproc, float * recvd, float * sent)
|
||||
{
|
||||
u_int32_t sum_sent = 0,
|
||||
sum_recv = 0;
|
||||
gettotal(curproc, &sum_recv, &sum_sent);
|
||||
*recvd = tomb(sum_recv);
|
||||
*sent = tomb(sum_sent);
|
||||
}
|
||||
|
||||
/** get total values for this process */
|
||||
void gettotalkb(Process * curproc, float * recvd, float * sent)
|
||||
{
|
||||
u_int32_t sum_sent = 0,
|
||||
sum_recv = 0;
|
||||
gettotal(curproc, &sum_recv, &sum_sent);
|
||||
*recvd = tokb(sum_recv);
|
||||
*sent = tokb(sum_sent);
|
||||
}
|
||||
|
||||
void gettotalb(Process * curproc, float * recvd, float * sent)
|
||||
{
|
||||
u_int32_t sum_sent = 0,
|
||||
sum_recv = 0;
|
||||
gettotal(curproc, &sum_recv, &sum_sent);
|
||||
//std::cout << "Total sent: " << sum_sent << std::endl;
|
||||
*sent = sum_sent;
|
||||
*recvd = sum_recv;
|
||||
}
|
||||
|
||||
float tomb (u_int32_t bytes)
|
||||
{
|
||||
return ((double)bytes) / 1024 / 1024;
|
||||
}
|
||||
float tokb (u_int32_t bytes)
|
||||
{
|
||||
return ((double)bytes) / 1024;
|
||||
}
|
||||
|
||||
float tokbps (u_int32_t bytes)
|
||||
{
|
||||
return (((double)bytes) / PERIOD) / 1024;
|
||||
}
|
||||
|
||||
15
process.h
15
process.h
@@ -95,6 +95,12 @@ public:
|
||||
}
|
||||
int getLastPacket ();
|
||||
|
||||
void gettotal( u_int32_t * recvd, u_int32_t * sent);
|
||||
void getkbps (float * recvd, float * sent);
|
||||
void gettotalmb(float * recvd, float * sent);
|
||||
void gettotalkb(float * recvd, float * sent);
|
||||
void gettotalb (float * recvd, float * sent);
|
||||
|
||||
char * name;
|
||||
const char * devicename;
|
||||
int pid;
|
||||
@@ -143,13 +149,4 @@ void refreshconninode ();
|
||||
|
||||
void procclean ();
|
||||
|
||||
void getkbps (Process * curproc, float * recvd, float * sent);
|
||||
void gettotal(Process * curproc, u_int32_t * recvd, u_int32_t * sent);
|
||||
void gettotalmb(Process * curproc, float * recvd, float * sent);
|
||||
void gettotalkb(Process * curproc, float * recvd, float * sent);
|
||||
void gettotalb(Process * curproc, float * recvd, float * sent);
|
||||
float tomb (u_int32_t bytes);
|
||||
float tokb (u_int32_t bytes);
|
||||
float tokbps (u_int32_t bytes);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user