stats.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * $Id$
  3. *
  4. *
  5. * Copyright (C) 2001-2003 Fhg Fokus
  6. *
  7. * This file is part of ser, a free SIP server.
  8. *
  9. * ser is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * For a license to use the ser software under conditions
  15. * other than those described here, or to purchase support for this
  16. * software, please contact iptel.org by e-mail at the following addresses:
  17. * [email protected]
  18. *
  19. * ser is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. */
  28. #ifndef stats_h
  29. #define stats_h
  30. #include <ctype.h>
  31. #include <sys/mman.h>
  32. #include <sys/fcntl.h>
  33. #include <sys/time.h>
  34. #include <time.h>
  35. #include <sys/utsname.h>
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <errno.h>
  39. #define _update_request( method, dir ) \
  40. do{ if (stat_file!=NULL) switch( method ) { \
  41. case METHOD_INVITE: stats->dir##_requests_inv++; break; \
  42. case METHOD_ACK: stats->dir##_requests_ack++; break; \
  43. case METHOD_CANCEL: stats->dir##_requests_cnc++; break; \
  44. case METHOD_BYE: stats->dir##_requests_bye++; break; \
  45. case METHOD_OTHER: stats->dir##_requests_other++; break; \
  46. default: LOG(L_ERR, "ERROR: unknown method in rq stats (%s)\n", \
  47. #dir); \
  48. } \
  49. }while(0)
  50. /*
  51. #define update_received_request( method ) _update_request( method, received )
  52. #define update_sent_request( method ) _update_request( method, sent )
  53. #define update_received_response( statusclass ) \
  54. _update_response( statusclass, received )
  55. #define update_sent_response( statusclass ) \
  56. _update_response( statusclass, sent )
  57. #define update_received_drops { stats->received_drops++; }
  58. #define update_fail_on_send { stats->failed_on_send++; }
  59. */
  60. #define _statusline(class, dir )\
  61. case class: stats->dir##_responses_##class++; break;
  62. /* FIXME: Don't have case for _other (see received_responses_other) */
  63. #define _update_response( statusclass, dir ) \
  64. do{ if (stat_file!=NULL) \
  65. switch( statusclass ) { \
  66. _statusline(1, dir) \
  67. _statusline(2, dir) \
  68. _statusline(3, dir) \
  69. _statusline(4, dir) \
  70. _statusline(5, dir) \
  71. _statusline(6, dir) \
  72. default: LOG(L_INFO, "ERROR: unusual status code"\
  73. " received in stats (%s)\n", #dir); \
  74. } \
  75. }while(0)
  76. #ifdef STATS
  77. # define STATS_RX_REQUEST(method) _update_request(method, received)
  78. # define STATS_TX_REQUEST(method) _update_request(method, sent )
  79. # define STATS_RX_RESPONSE(class) _update_response( class, received )
  80. # define STATS_TX_RESPONSE(class) _update_response( class, sent )
  81. # define STATS_RX_DROPS { stats->received_drops++; }
  82. # define STATS_TX_DROPS { stats->failed_on_send++; }
  83. #else
  84. # define STATS_RX_REQUEST(method)
  85. # define STATS_TX_REQUEST(method)
  86. # define STATS_RX_RESPONSE(class)
  87. # define STATS_TX_RESPONSE(class)
  88. # define STATS_RX_DROPS
  89. # define STATS_TX_DROPS
  90. #endif
  91. #ifdef STATS
  92. struct stats_s {
  93. unsigned int process_index;
  94. pid_t pid;
  95. time_t start_time;
  96. unsigned long
  97. /* received packets */
  98. received_requests_inv, /* received_requests */
  99. received_requests_ack,
  100. received_requests_cnc,
  101. received_requests_bye,
  102. received_requests_other,
  103. received_responses_1, /* received_responses */
  104. received_responses_2,
  105. received_responses_3,
  106. received_responses_4,
  107. received_responses_5,
  108. received_responses_6,
  109. received_responses_other,
  110. received_drops, /* all messages we received and did not process
  111. successfully; reasons include SIP sanity checks
  112. (missing Vias, neither request nor response,
  113. failed parsing), ser errors (malloc, action
  114. failure)
  115. */
  116. /* sent */
  117. /* sent_requests */
  118. sent_requests_inv,
  119. sent_requests_ack,
  120. sent_requests_cnc,
  121. sent_requests_bye,
  122. sent_requests_other,
  123. /* sent responses */
  124. sent_responses_1,
  125. sent_responses_2,
  126. sent_responses_3,
  127. sent_responses_4,
  128. sent_responses_5,
  129. sent_responses_6,
  130. /* FIXME: Don't want sent_responses_other?? */
  131. processed_requests,
  132. processed_responses,
  133. acc_req_time,
  134. acc_res_time,
  135. failed_on_send;
  136. };
  137. extern struct stats_s *stats;
  138. extern char *stat_file;
  139. int init_stats( int nr_of_processes );
  140. void setstats( int child_index );
  141. int dump_all_statistic();
  142. int dump_statistic(FILE *fp, struct stats_s *istats, int printheader);
  143. /* Registers handlers with SNMP module */
  144. int stats_register();
  145. #endif
  146. #endif