stats.h 4.9 KB

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