stats.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  27. */
  28. #ifndef stats_h
  29. #define stats_h
  30. #include <ctype.h>
  31. #include <sys/mman.h>
  32. #include <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_INFO: stats->dir##_requests_info++; break; \
  46. case METHOD_OTHER: stats->dir##_requests_other++; break; \
  47. default: LM_ERR("unknown method in rq stats (%s)\n", #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: LM_INFO("unusual status code received in stats (%s)\n", #dir); \
  73. } \
  74. }while(0)
  75. #ifdef STATS
  76. # define STATS_RX_REQUEST(method) _update_request(method, received)
  77. # define STATS_TX_REQUEST(method) _update_request(method, sent )
  78. # define STATS_RX_RESPONSE(class) _update_response( class, received )
  79. # define STATS_TX_RESPONSE(class) _update_response( class, sent )
  80. # define STATS_RX_DROPS { stats->received_drops++; }
  81. # define STATS_TX_DROPS { stats->failed_on_send++; }
  82. #else
  83. # define STATS_RX_REQUEST(method)
  84. # define STATS_TX_REQUEST(method)
  85. # define STATS_RX_RESPONSE(class)
  86. # define STATS_TX_RESPONSE(class)
  87. # define STATS_RX_DROPS
  88. # define STATS_TX_DROPS
  89. #endif
  90. #ifdef STATS
  91. struct stats_s {
  92. unsigned int process_index;
  93. pid_t pid;
  94. time_t start_time;
  95. unsigned long
  96. /* received packets */
  97. received_requests_inv, /* received_requests */
  98. received_requests_ack,
  99. received_requests_cnc,
  100. received_requests_bye,
  101. received_requests_other,
  102. received_responses_1, /* received_responses */
  103. received_responses_2,
  104. received_responses_3,
  105. received_responses_4,
  106. received_responses_5,
  107. received_responses_6,
  108. received_responses_other,
  109. received_drops, /* all messages we received and did not process
  110. successfully; reasons include SIP sanity checks
  111. (missing Vias, neither request nor response,
  112. failed parsing), ser errors (malloc, action
  113. failure)
  114. */
  115. /* sent */
  116. /* sent_requests */
  117. sent_requests_inv,
  118. sent_requests_ack,
  119. sent_requests_cnc,
  120. sent_requests_bye,
  121. sent_requests_other,
  122. /* sent responses */
  123. sent_responses_1,
  124. sent_responses_2,
  125. sent_responses_3,
  126. sent_responses_4,
  127. sent_responses_5,
  128. sent_responses_6,
  129. /* FIXME: Don't want sent_responses_other?? */
  130. processed_requests,
  131. processed_responses,
  132. acc_req_time,
  133. acc_res_time,
  134. failed_on_send;
  135. };
  136. extern struct stats_s *stats;
  137. extern char *stat_file;
  138. int init_stats( int nr_of_processes );
  139. void setstats( int child_index );
  140. int dump_all_statistic();
  141. int dump_statistic(FILE *fp, struct stats_s *istats, int printheader);
  142. /* Registers handlers with SNMP module */
  143. int stats_register();
  144. #endif
  145. #endif