statsd.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * David M. Lee, II <dlee@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. #ifndef _ASTERISK_STATSD_H
  19. #define _ASTERISK_STATSD_H
  20. /*!
  21. * \brief Support for publishing to a statsd server.
  22. *
  23. * \author David M. Lee, II <dlee@digium.com>
  24. * \since 12
  25. */
  26. #include "asterisk/optional_api.h"
  27. /*! An instantaneous measurement of a value. */
  28. #define AST_STATSD_GAUGE "g"
  29. /*!
  30. * Embarrassingly, gauge was misspelled for quite some time.
  31. * \deprecated You should spell gauge correctly.
  32. */
  33. #define AST_STATSD_GUAGE AST_STATSD_GAUGE
  34. /*! A change in a value. */
  35. #define AST_STATSD_COUNTER "c"
  36. /*! Measure of milliseconds. */
  37. #define AST_STATSD_TIMER "ms"
  38. /*! Distribution of values over time. */
  39. #define AST_STATSD_HISTOGRAM "h"
  40. /*! Events over time. Sorta like increment-only counters. */
  41. #define AST_STATSD_METER "m"
  42. /*!
  43. * \brief Send a stat to the configured statsd server.
  44. *
  45. * This function uses a character argument for value instead of
  46. * an intmax_t argument. This is designed to be simpler to use for
  47. * updating a current value rather than resetting it.
  48. *
  49. * \param metric_name String (UTF-8) name of the metric.
  50. * \param type_str Type of metric to send.
  51. * \param value Value to send.
  52. * \param sample_rate Percentage of samples to send.
  53. * \since 13
  54. */
  55. AST_OPTIONAL_API(void, ast_statsd_log_string, (const char *metric_name,
  56. const char *metric_type, const char *value, double sample_rate), {});
  57. /*!
  58. * \brief Send a stat to the configured statsd server.
  59. * \since 13.7.0
  60. *
  61. * This is the most flexible function for sending a message to the statsd
  62. * server. In addition to allowing the string value and sample rate to be specified,
  63. * the metric_name can be formed as a printf style string with variable
  64. * arguments.
  65. *
  66. * \param metric_name Format string (UTF-8) specifying the name of the metric.
  67. * \param metric_type Type of metric to send.
  68. * \param value Value to send.
  69. * \param sample_rate Percentage of samples to send.
  70. *
  71. * Example Usage:
  72. * \code
  73. * ast_statsd_log_string_va(AST_STATSD_GAUGE, "+1", 1.0, "endpoints.states.%s", state_name);
  74. * \endcode
  75. */
  76. AST_OPTIONAL_API_ATTR(void, format(printf, 1, 5), ast_statsd_log_string_va,
  77. (const char *metric_name, const char *metric_type, const char *value, double sample_rate, ...), {});
  78. /*!
  79. * \brief Send a stat to the configured statsd server.
  80. *
  81. * The is nearly the most flexible function for sending a message to the statsd
  82. * server, but also the least easy to use. See ast_statsd_log() or
  83. * ast_statsd_log_sample() for a slightly more convenient interface.
  84. *
  85. * \param metric_name String (UTF-8) name of the metric.
  86. * \param type_str Type of metric to send.
  87. * \param value Value to send.
  88. * \param sample_rate Percentage of samples to send.
  89. * \since 12
  90. */
  91. AST_OPTIONAL_API(void, ast_statsd_log_full, (const char *metric_name,
  92. const char *metric_type, intmax_t value, double sample_rate), {});
  93. /*!
  94. * \brief Send a stat to the configured statsd server.
  95. * \since 13.7.0
  96. *
  97. * This is the most flexible function for sending a message to the statsd
  98. * server. In addition to allowing the value and sample rate to be specified,
  99. * the metric_name can be formed as a printf style string with variable
  100. * arguments.
  101. *
  102. * \param metric_name Format string (UTF-8) specifying the name of the metric.
  103. * \param metric_type Type of metric to send.
  104. * \param value Value to send.
  105. * \param sample_rate Percentage of samples to send.
  106. *
  107. * Example Usage:
  108. * \code
  109. * ast_statsd_log_full_va(AST_STATSD_TIMER, rtt, 1.0, "endpoint.%s.rtt", endpoint_name);
  110. * \endcode
  111. */
  112. AST_OPTIONAL_API_ATTR(void, format(printf, 1, 5), ast_statsd_log_full_va,
  113. (const char *metric_name, const char *metric_type, intmax_t value, double sample_rate, ...), {});
  114. /*!
  115. * \brief Send a stat to the configured statsd server.
  116. * \param metric_name String (UTF-8) name of the metric.
  117. * \param metric_type Type of metric to send.
  118. * \param value Value to send.
  119. * \since 12
  120. */
  121. AST_OPTIONAL_API(void, ast_statsd_log, (const char *metric_name,
  122. const char *metric_type, intmax_t value), {});
  123. /*!
  124. * \brief Send a random sampling of a stat to the configured statsd server.
  125. *
  126. * The type of sampled metrics is always \ref AST_STATSD_COUNTER. The given
  127. * \a sample_rate should be a percentage between 0.0 and 1.0. If it's <= 0.0,
  128. * then no samples will be sent. If it's >= 1.0, then all samples will be sent.
  129. *
  130. * \param metric_name String (UTF-8) name of the metric.
  131. * \param value Value to send.
  132. * \param sample_rate Percentage of samples to send.
  133. * \since 12
  134. */
  135. AST_OPTIONAL_API(void, ast_statsd_log_sample, (const char *metric_name,
  136. intmax_t value, double sample_rate), {});
  137. #endif /* _ASTERISK_STATSD_H */