metrics-howto.rst 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. How to monitor Synapse metrics using Prometheus
  2. ===============================================
  3. 1. Install Prometheus:
  4. Follow instructions at http://prometheus.io/docs/introduction/install/
  5. 2. Enable Synapse metrics:
  6. There are two methods of enabling metrics in Synapse.
  7. The first serves the metrics as a part of the usual web server and can be
  8. enabled by adding the "metrics" resource to the existing listener as such::
  9. resources:
  10. - names:
  11. - client
  12. - metrics
  13. This provides a simple way of adding metrics to your Synapse installation,
  14. and serves under ``/_synapse/metrics``. If you do not wish your metrics be
  15. publicly exposed, you will need to either filter it out at your load
  16. balancer, or use the second method.
  17. The second method runs the metrics server on a different port, in a
  18. different thread to Synapse. This can make it more resilient to heavy load
  19. meaning metrics cannot be retrieved, and can be exposed to just internal
  20. networks easier. The served metrics are available over HTTP only, and will
  21. be available at ``/``.
  22. Add a new listener to homeserver.yaml::
  23. listeners:
  24. - type: metrics
  25. port: 9000
  26. bind_addresses:
  27. - '0.0.0.0'
  28. For both options, you will need to ensure that ``enable_metrics`` is set to
  29. ``True``.
  30. Restart Synapse.
  31. 3. Add a Prometheus target for Synapse.
  32. It needs to set the ``metrics_path`` to a non-default value (under ``scrape_configs``)::
  33. - job_name: "synapse"
  34. metrics_path: "/_synapse/metrics"
  35. static_configs:
  36. - targets: ["my.server.here:9092"]
  37. If your prometheus is older than 1.5.2, you will need to replace
  38. ``static_configs`` in the above with ``target_groups``.
  39. Restart Prometheus.
  40. Removal of deprecated metrics & time based counters becoming histograms in 0.31.0
  41. ---------------------------------------------------------------------------------
  42. The duplicated metrics deprecated in Synapse 0.27.0 have been removed.
  43. All time duration-based metrics have been changed to be seconds. This affects:
  44. +----------------------------------+
  45. | msec -> sec metrics |
  46. +==================================+
  47. | python_gc_time |
  48. +----------------------------------+
  49. | python_twisted_reactor_tick_time |
  50. +----------------------------------+
  51. | synapse_storage_query_time |
  52. +----------------------------------+
  53. | synapse_storage_schedule_time |
  54. +----------------------------------+
  55. | synapse_storage_transaction_time |
  56. +----------------------------------+
  57. Several metrics have been changed to be histograms, which sort entries into
  58. buckets and allow better analysis. The following metrics are now histograms:
  59. +-------------------------------------------+
  60. | Altered metrics |
  61. +===========================================+
  62. | python_gc_time |
  63. +-------------------------------------------+
  64. | python_twisted_reactor_pending_calls |
  65. +-------------------------------------------+
  66. | python_twisted_reactor_tick_time |
  67. +-------------------------------------------+
  68. | synapse_http_server_response_time_seconds |
  69. +-------------------------------------------+
  70. | synapse_storage_query_time |
  71. +-------------------------------------------+
  72. | synapse_storage_schedule_time |
  73. +-------------------------------------------+
  74. | synapse_storage_transaction_time |
  75. +-------------------------------------------+
  76. Block and response metrics renamed for 0.27.0
  77. ---------------------------------------------
  78. Synapse 0.27.0 begins the process of rationalising the duplicate ``*:count``
  79. metrics reported for the resource tracking for code blocks and HTTP requests.
  80. At the same time, the corresponding ``*:total`` metrics are being renamed, as
  81. the ``:total`` suffix no longer makes sense in the absence of a corresponding
  82. ``:count`` metric.
  83. To enable a graceful migration path, this release just adds new names for the
  84. metrics being renamed. A future release will remove the old ones.
  85. The following table shows the new metrics, and the old metrics which they are
  86. replacing.
  87. ==================================================== ===================================================
  88. New name Old name
  89. ==================================================== ===================================================
  90. synapse_util_metrics_block_count synapse_util_metrics_block_timer:count
  91. synapse_util_metrics_block_count synapse_util_metrics_block_ru_utime:count
  92. synapse_util_metrics_block_count synapse_util_metrics_block_ru_stime:count
  93. synapse_util_metrics_block_count synapse_util_metrics_block_db_txn_count:count
  94. synapse_util_metrics_block_count synapse_util_metrics_block_db_txn_duration:count
  95. synapse_util_metrics_block_time_seconds synapse_util_metrics_block_timer:total
  96. synapse_util_metrics_block_ru_utime_seconds synapse_util_metrics_block_ru_utime:total
  97. synapse_util_metrics_block_ru_stime_seconds synapse_util_metrics_block_ru_stime:total
  98. synapse_util_metrics_block_db_txn_count synapse_util_metrics_block_db_txn_count:total
  99. synapse_util_metrics_block_db_txn_duration_seconds synapse_util_metrics_block_db_txn_duration:total
  100. synapse_http_server_response_count synapse_http_server_requests
  101. synapse_http_server_response_count synapse_http_server_response_time:count
  102. synapse_http_server_response_count synapse_http_server_response_ru_utime:count
  103. synapse_http_server_response_count synapse_http_server_response_ru_stime:count
  104. synapse_http_server_response_count synapse_http_server_response_db_txn_count:count
  105. synapse_http_server_response_count synapse_http_server_response_db_txn_duration:count
  106. synapse_http_server_response_time_seconds synapse_http_server_response_time:total
  107. synapse_http_server_response_ru_utime_seconds synapse_http_server_response_ru_utime:total
  108. synapse_http_server_response_ru_stime_seconds synapse_http_server_response_ru_stime:total
  109. synapse_http_server_response_db_txn_count synapse_http_server_response_db_txn_count:total
  110. synapse_http_server_response_db_txn_duration_seconds synapse_http_server_response_db_txn_duration:total
  111. ==================================================== ===================================================
  112. Standard Metric Names
  113. ---------------------
  114. As of synapse version 0.18.2, the format of the process-wide metrics has been
  115. changed to fit prometheus standard naming conventions. Additionally the units
  116. have been changed to seconds, from miliseconds.
  117. ================================== =============================
  118. New name Old name
  119. ================================== =============================
  120. process_cpu_user_seconds_total process_resource_utime / 1000
  121. process_cpu_system_seconds_total process_resource_stime / 1000
  122. process_open_fds (no 'type' label) process_fds
  123. ================================== =============================
  124. The python-specific counts of garbage collector performance have been renamed.
  125. =========================== ======================
  126. New name Old name
  127. =========================== ======================
  128. python_gc_time reactor_gc_time
  129. python_gc_unreachable_total reactor_gc_unreachable
  130. python_gc_counts reactor_gc_counts
  131. =========================== ======================
  132. The twisted-specific reactor metrics have been renamed.
  133. ==================================== =====================
  134. New name Old name
  135. ==================================== =====================
  136. python_twisted_reactor_pending_calls reactor_pending_calls
  137. python_twisted_reactor_tick_time reactor_tick_time
  138. ==================================== =====================