]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - src/s_stats.c
Need to initialize linebuf separately.
[irc/rqf/shadowircd.git] / src / s_stats.c
index 42e4dec44e676fae27c4c313dced6832410b4cf9..c972293a3344cd948e6f0529db3ce17746fe0aaf 100644 (file)
 /*
  * stats stuff
  */
-struct ServerStatistics ServerStats;
+static struct ServerStatistics ircst;
+struct ServerStatistics *ServerStats = &ircst;
 
 void
 init_stats()
 {
-       /* XXX nothing to do - was ServerStats init -- dwr */
+       memset(&ircst, 0, sizeof(ircst));
 }
 
 /*
@@ -56,73 +57,109 @@ init_stats()
  * output      - NONE 
  * side effects        -
  */
-void\r
-tstats(struct Client *source_p)\r
-{\r
-       struct Client *target_p;\r
-       struct ServerStatistics sp;\r
-       rb_dlink_node *ptr;\r
-\r
-       memcpy(&sp, &ServerStats, sizeof(struct ServerStatistics));\r
-\r
-       RB_DLINK_FOREACH(ptr, serv_list.head)\r
-       {\r
-               target_p = ptr->data;\r
-\r
-               sp.is_sbs += target_p->localClient->sendB;\r
-               sp.is_sbr += target_p->localClient->receiveB;\r
-               sp.is_sti += rb_current_time() - target_p->localClient->firsttime;\r
-               sp.is_sv++;\r
-       }\r
-\r
-       RB_DLINK_FOREACH(ptr, lclient_list.head)\r
-       {\r
-               target_p = ptr->data;\r
-\r
-               sp.is_cbs += target_p->localClient->sendB;\r
-               sp.is_cbr += target_p->localClient->receiveB;\r
-               sp.is_cti += rb_current_time() - target_p->localClient->firsttime;\r
-               sp.is_cl++;\r
-       }\r
-\r
-       sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
-                               "T :accepts %u refused %u", \r
-                               sp.is_ac, sp.is_ref);\r
-       sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
-                               "T :rejected %u delaying %lu", \r
-                               sp.is_rej, delay_exit_length());\r
-       sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
-                               "T :nicks being delayed %lu", get_nd_count());\r
-       sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
-                               "T :unknown commands %u prefixes %u",\r
-                               sp.is_unco, sp.is_unpf);\r
-       sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
-                               "T :nick collisions %u saves %u unknown closes %u",\r
-                               sp.is_kill, sp.is_save, sp.is_ni);\r
-       sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
-                               "T :wrong direction %u empty %u", \r
-                               sp.is_wrdi, sp.is_empt);\r
-       sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
-                               "T :numerics seen %u", \r
-                               sp.is_num);\r
-       sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
-                               "T :auth successes %u fails %u",\r
-                               sp.is_asuc, sp.is_abad);\r
-       sendto_one_numeric(source_p, RPL_STATSDEBUG, "T :Client Server");\r
-       sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
-                               "T :connected %u %u",\r
-                               sp.is_cl, sp.is_sv);\r
-       sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
-                               "T :bytes sent %lluK %lluK",\r
-                               sp.is_cbs / 1024, \r
-                               sp.is_sbs / 1024);\r
-       sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
-                               "T :bytes recv %lluK %lluK",\r
-                               sp.is_cbr / 1024, \r
-                               sp.is_sbr / 1024);\r
-       sendto_one_numeric(source_p, RPL_STATSDEBUG,\r
-                               "T :time connected %lu %lu",\r
-                               sp.is_cti, sp.is_sti);\r
+void
+tstats(struct Client *source_p)
+{
+       struct Client *target_p;
+       struct ServerStatistics *sp;
+       struct ServerStatistics tmp;
+       rb_dlink_node *ptr;
+
+       sp = &tmp;
+       memcpy(sp, ServerStats, sizeof(struct ServerStatistics));
+
+       RB_DLINK_FOREACH(ptr, serv_list.head)
+       {
+               target_p = ptr->data;
+
+               sp->is_sbs += target_p->localClient->sendB;
+               sp->is_sbr += target_p->localClient->receiveB;
+               sp->is_sks += target_p->localClient->sendK;
+               sp->is_skr += target_p->localClient->receiveK;
+               sp->is_sti += rb_current_time() - target_p->localClient->firsttime;
+               sp->is_sv++;
+               if(sp->is_sbs > 1023)
+               {
+                       sp->is_sks += (sp->is_sbs >> 10);
+                       sp->is_sbs &= 0x3ff;
+               }
+               if(sp->is_sbr > 1023)
+               {
+                       sp->is_skr += (sp->is_sbr >> 10);
+                       sp->is_sbr &= 0x3ff;
+               }
+       }
+
+       RB_DLINK_FOREACH(ptr, lclient_list.head)
+       {
+               target_p = ptr->data;
+
+               sp->is_cbs += target_p->localClient->sendB;
+               sp->is_cbr += target_p->localClient->receiveB;
+               sp->is_cks += target_p->localClient->sendK;
+               sp->is_ckr += target_p->localClient->receiveK;
+               sp->is_cti += rb_current_time() - target_p->localClient->firsttime;
+               sp->is_cl++;
+               if(sp->is_cbs > 1023)
+               {
+                       sp->is_cks += (sp->is_cbs >> 10);
+                       sp->is_cbs &= 0x3ff;
+               }
+               if(sp->is_cbr > 1023)
+               {
+                       sp->is_ckr += (sp->is_cbr >> 10);
+                       sp->is_cbr &= 0x3ff;
+               }
+
+       }
+
+       RB_DLINK_FOREACH(ptr, unknown_list.head)
+       {
+               sp->is_ni++;
+       }
+
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                          "T :accepts %u refused %u", sp->is_ac, sp->is_ref);
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                       "T :rejected %u delaying %lu", 
+                       sp->is_rej, rb_dlink_list_length(&delay_exit));
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                       "T :nicks being delayed %lu",
+                       get_nd_count());
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                          "T :unknown commands %u prefixes %u",
+                          sp->is_unco, sp->is_unpf);
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                          "T :nick collisions %u saves %u unknown closes %u",
+                          sp->is_kill, sp->is_save, sp->is_ni);
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                          "T :wrong direction %u empty %u", 
+                          sp->is_wrdi, sp->is_empt);
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                          "T :numerics seen %u", sp->is_num);
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                          "T :tgchange blocked msgs %u restricted addrs %lu",
+                          sp->is_tgch, rb_dlink_list_length(&tgchange_list));
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                          "T :auth successes %u fails %u",
+                          sp->is_asuc, sp->is_abad);
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                          "T :sasl successes %u fails %u",
+                          sp->is_ssuc, sp->is_sbad);
+       sendto_one_numeric(source_p, RPL_STATSDEBUG, "T :Client Server");
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                          "T :connected %u %u", sp->is_cl, sp->is_sv);
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                          "T :bytes sent %d.%uK %d.%uK",
+                          (int) sp->is_cks, sp->is_cbs, 
+                          (int) sp->is_sks, sp->is_sbs);
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                          "T :bytes recv %d.%uK %d.%uK",
+                          (int) sp->is_ckr, sp->is_cbr, 
+                          (int) sp->is_skr, sp->is_sbr);
+       sendto_one_numeric(source_p, RPL_STATSDEBUG,
+                          "T :time connected %d %d",
+                          (int) sp->is_cti, (int) sp->is_sti);
 }
 
 void