sctp_stats.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2010 iptelorg GmbH
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /** sctp statistics.
  19. * @file sctp_stats.c
  20. * @ingroup: core (sctp)
  21. */
  22. /*
  23. * History:
  24. * --------
  25. * 2010-08-09 initial version (andrei)
  26. */
  27. #ifdef USE_SCTP
  28. #include "sctp_stats.h"
  29. #ifdef USE_SCTP_STATS
  30. #include "../../counters.h"
  31. #include "sctp_server.h"
  32. struct sctp_counters_h sctp_cnts_h;
  33. enum sctp_info_req { SCTP_INFO_NONE, SCTP_INFO_CONN_NO, SCTP_INFO_TRACKED_NO };
  34. static counter_val_t sctp_info(counter_handle_t h, void* what);
  35. /* sctp counters definitions */
  36. counter_def_t sctp_cnt_defs[] = {
  37. {&sctp_cnts_h.established, "established", 0, 0, 0,
  38. "incremented each time a new association is established."},
  39. {&sctp_cnts_h.connect_failed, "connect_failed", 0, 0, 0,
  40. "incremented each time a new outgoing connection fails."},
  41. {&sctp_cnts_h.local_reject, "local_reject", 0, 0, 0,
  42. "number of rejected incoming connections."},
  43. {&sctp_cnts_h.remote_shutdown, "remote_shutdown", 0, 0, 0,
  44. "incremented each time an association is closed by the peer."},
  45. {&sctp_cnts_h.assoc_shutdown, "assoc_shutdown", 0, 0, 0,
  46. "incremented each time an association is shutdown."},
  47. {&sctp_cnts_h.comm_lost, "comm_lost", 0, 0, 0,
  48. "incremented each time an established connection is close due to"
  49. "some error."},
  50. {&sctp_cnts_h.sendq_full, "sendq_full", 0, 0, 0,
  51. "number of failed send attempt due to exceeded buffering capacity"
  52. " (full kernel buffers)."},
  53. {&sctp_cnts_h.send_failed, "send_failed", 0, 0, 0,
  54. "number of failed send attempt for any reason except full buffers."},
  55. {&sctp_cnts_h.send_force_retry, "send_force_retry", 0, 0, 0,
  56. "incremented each time a failed send is force-retried"
  57. "(possible only if sctp_send_retries ! = 0"},
  58. {0, "current_opened_connections", 0,
  59. sctp_info, (void*)(long)SCTP_INFO_CONN_NO,
  60. "number of currently opened associations."},
  61. {0, "current_tracked_connections", 0,
  62. sctp_info, (void*)(long)SCTP_INFO_TRACKED_NO,
  63. "number of currently tracked associations."},
  64. {0, 0, 0, 0, 0, 0 }
  65. };
  66. /** helper function for some stats (which are kept internally inside sctp).
  67. */
  68. static counter_val_t sctp_info(counter_handle_t h, void* what)
  69. {
  70. enum sctp_info_req w;
  71. struct sctp_gen_info i;
  72. if (sctp_disable)
  73. return 0;
  74. w = (int)(long)what;
  75. sctp_get_info(&i);
  76. switch(w) {
  77. case SCTP_INFO_CONN_NO:
  78. return i.sctp_connections_no;
  79. case SCTP_INFO_TRACKED_NO:
  80. return i.sctp_tracked_no;
  81. case SCTP_INFO_NONE:
  82. break;
  83. };
  84. return 0;
  85. }
  86. /** intialize sctp statistics.
  87. * Must be called before forking.
  88. * @return < 0 on errror, 0 on success.
  89. */
  90. int sctp_stats_init()
  91. {
  92. if (counter_register_array("sctp", sctp_cnt_defs) < 0)
  93. goto error;
  94. return 0;
  95. error:
  96. return -1;
  97. }
  98. void sctp_stats_destroy()
  99. {
  100. /* do nothing */
  101. }
  102. #endif /* USE_SCTP_STATS */
  103. #endif /* USE_SCTP */
  104. /* vi: set ts=4 sw=4 tw=79:ai:cindent: */