metrics-howto.rst 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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:port"]
  37. where ``my.server.here`` is the IP address of Synapse, and ``port`` is the listener port
  38. configured with the ``metrics`` resource.
  39. If your prometheus is older than 1.5.2, you will need to replace
  40. ``static_configs`` in the above with ``target_groups``.
  41. Restart Prometheus.
  42. Removal of deprecated metrics & time based counters becoming histograms in 0.31.0
  43. ---------------------------------------------------------------------------------
  44. The duplicated metrics deprecated in Synapse 0.27.0 have been removed.
  45. All time duration-based metrics have been changed to be seconds. This affects:
  46. +----------------------------------+
  47. | msec -> sec metrics |
  48. +==================================+
  49. | python_gc_time |
  50. +----------------------------------+
  51. | python_twisted_reactor_tick_time |
  52. +----------------------------------+
  53. | synapse_storage_query_time |
  54. +----------------------------------+
  55. | synapse_storage_schedule_time |
  56. +----------------------------------+
  57. | synapse_storage_transaction_time |
  58. +----------------------------------+
  59. Several metrics have been changed to be histograms, which sort entries into
  60. buckets and allow better analysis. The following metrics are now histograms:
  61. +-------------------------------------------+
  62. | Altered metrics |
  63. +===========================================+
  64. | python_gc_time |
  65. +-------------------------------------------+
  66. | python_twisted_reactor_pending_calls |
  67. +-------------------------------------------+
  68. | python_twisted_reactor_tick_time |
  69. +-------------------------------------------+
  70. | synapse_http_server_response_time_seconds |
  71. +-------------------------------------------+
  72. | synapse_storage_query_time |
  73. +-------------------------------------------+
  74. | synapse_storage_schedule_time |
  75. +-------------------------------------------+
  76. | synapse_storage_transaction_time |
  77. +-------------------------------------------+
  78. Block and response metrics renamed for 0.27.0
  79. ---------------------------------------------
  80. Synapse 0.27.0 begins the process of rationalising the duplicate ``*:count``
  81. metrics reported for the resource tracking for code blocks and HTTP requests.
  82. At the same time, the corresponding ``*:total`` metrics are being renamed, as
  83. the ``:total`` suffix no longer makes sense in the absence of a corresponding
  84. ``:count`` metric.
  85. To enable a graceful migration path, this release just adds new names for the
  86. metrics being renamed. A future release will remove the old ones.
  87. The following table shows the new metrics, and the old metrics which they are
  88. replacing.
  89. ==================================================== ===================================================
  90. New name Old name
  91. ==================================================== ===================================================
  92. synapse_util_metrics_block_count synapse_util_metrics_block_timer:count
  93. synapse_util_metrics_block_count synapse_util_metrics_block_ru_utime:count
  94. synapse_util_metrics_block_count synapse_util_metrics_block_ru_stime:count
  95. synapse_util_metrics_block_count synapse_util_metrics_block_db_txn_count:count
  96. synapse_util_metrics_block_count synapse_util_metrics_block_db_txn_duration:count
  97. synapse_util_metrics_block_time_seconds synapse_util_metrics_block_timer:total
  98. synapse_util_metrics_block_ru_utime_seconds synapse_util_metrics_block_ru_utime:total
  99. synapse_util_metrics_block_ru_stime_seconds synapse_util_metrics_block_ru_stime:total
  100. synapse_util_metrics_block_db_txn_count synapse_util_metrics_block_db_txn_count:total
  101. synapse_util_metrics_block_db_txn_duration_seconds synapse_util_metrics_block_db_txn_duration:total
  102. synapse_http_server_response_count synapse_http_server_requests
  103. synapse_http_server_response_count synapse_http_server_response_time:count
  104. synapse_http_server_response_count synapse_http_server_response_ru_utime:count
  105. synapse_http_server_response_count synapse_http_server_response_ru_stime:count
  106. synapse_http_server_response_count synapse_http_server_response_db_txn_count:count
  107. synapse_http_server_response_count synapse_http_server_response_db_txn_duration:count
  108. synapse_http_server_response_time_seconds synapse_http_server_response_time:total
  109. synapse_http_server_response_ru_utime_seconds synapse_http_server_response_ru_utime:total
  110. synapse_http_server_response_ru_stime_seconds synapse_http_server_response_ru_stime:total
  111. synapse_http_server_response_db_txn_count synapse_http_server_response_db_txn_count:total
  112. synapse_http_server_response_db_txn_duration_seconds synapse_http_server_response_db_txn_duration:total
  113. ==================================================== ===================================================
  114. Standard Metric Names
  115. ---------------------
  116. As of synapse version 0.18.2, the format of the process-wide metrics has been
  117. changed to fit prometheus standard naming conventions. Additionally the units
  118. have been changed to seconds, from miliseconds.
  119. ================================== =============================
  120. New name Old name
  121. ================================== =============================
  122. process_cpu_user_seconds_total process_resource_utime / 1000
  123. process_cpu_system_seconds_total process_resource_stime / 1000
  124. process_open_fds (no 'type' label) process_fds
  125. ================================== =============================
  126. The python-specific counts of garbage collector performance have been renamed.
  127. =========================== ======================
  128. New name Old name
  129. =========================== ======================
  130. python_gc_time reactor_gc_time
  131. python_gc_unreachable_total reactor_gc_unreachable
  132. python_gc_counts reactor_gc_counts
  133. =========================== ======================
  134. The twisted-specific reactor metrics have been renamed.
  135. ==================================== =====================
  136. New name Old name
  137. ==================================== =====================
  138. python_twisted_reactor_pending_calls reactor_pending_calls
  139. python_twisted_reactor_tick_time reactor_tick_time
  140. ==================================== =====================