metrics-howto.rst 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. python_twisted_reactor_tick_time
  49. synapse_storage_query_time
  50. synapse_storage_schedule_time
  51. synapse_storage_transaction_time
  52. ================================
  53. Several metrics have been changed to be histograms, which sort entries into
  54. buckets and allow better analysis. The following metrics are now histograms:
  55. =========================================
  56. Altered metrics
  57. =========================================
  58. python_gc_time
  59. python_twisted_reactor_pending_calls
  60. python_twisted_reactor_tick_time
  61. synapse_http_server_response_time_seconds
  62. synapse_storage_query_time
  63. synapse_storage_schedule_time
  64. synapse_storage_transaction_time
  65. =========================================
  66. Block and response metrics renamed for 0.27.0
  67. ---------------------------------------------
  68. Synapse 0.27.0 begins the process of rationalising the duplicate ``*:count``
  69. metrics reported for the resource tracking for code blocks and HTTP requests.
  70. At the same time, the corresponding ``*:total`` metrics are being renamed, as
  71. the ``:total`` suffix no longer makes sense in the absence of a corresponding
  72. ``:count`` metric.
  73. To enable a graceful migration path, this release just adds new names for the
  74. metrics being renamed. A future release will remove the old ones.
  75. The following table shows the new metrics, and the old metrics which they are
  76. replacing.
  77. ==================================================== ===================================================
  78. New name Old name
  79. ==================================================== ===================================================
  80. synapse_util_metrics_block_count synapse_util_metrics_block_timer:count
  81. synapse_util_metrics_block_count synapse_util_metrics_block_ru_utime:count
  82. synapse_util_metrics_block_count synapse_util_metrics_block_ru_stime:count
  83. synapse_util_metrics_block_count synapse_util_metrics_block_db_txn_count:count
  84. synapse_util_metrics_block_count synapse_util_metrics_block_db_txn_duration:count
  85. synapse_util_metrics_block_time_seconds synapse_util_metrics_block_timer:total
  86. synapse_util_metrics_block_ru_utime_seconds synapse_util_metrics_block_ru_utime:total
  87. synapse_util_metrics_block_ru_stime_seconds synapse_util_metrics_block_ru_stime:total
  88. synapse_util_metrics_block_db_txn_count synapse_util_metrics_block_db_txn_count:total
  89. synapse_util_metrics_block_db_txn_duration_seconds synapse_util_metrics_block_db_txn_duration:total
  90. synapse_http_server_response_count synapse_http_server_requests
  91. synapse_http_server_response_count synapse_http_server_response_time:count
  92. synapse_http_server_response_count synapse_http_server_response_ru_utime:count
  93. synapse_http_server_response_count synapse_http_server_response_ru_stime:count
  94. synapse_http_server_response_count synapse_http_server_response_db_txn_count:count
  95. synapse_http_server_response_count synapse_http_server_response_db_txn_duration:count
  96. synapse_http_server_response_time_seconds synapse_http_server_response_time:total
  97. synapse_http_server_response_ru_utime_seconds synapse_http_server_response_ru_utime:total
  98. synapse_http_server_response_ru_stime_seconds synapse_http_server_response_ru_stime:total
  99. synapse_http_server_response_db_txn_count synapse_http_server_response_db_txn_count:total
  100. synapse_http_server_response_db_txn_duration_seconds synapse_http_server_response_db_txn_duration:total
  101. ==================================================== ===================================================
  102. Standard Metric Names
  103. ---------------------
  104. As of synapse version 0.18.2, the format of the process-wide metrics has been
  105. changed to fit prometheus standard naming conventions. Additionally the units
  106. have been changed to seconds, from miliseconds.
  107. ================================== =============================
  108. New name Old name
  109. ================================== =============================
  110. process_cpu_user_seconds_total process_resource_utime / 1000
  111. process_cpu_system_seconds_total process_resource_stime / 1000
  112. process_open_fds (no 'type' label) process_fds
  113. ================================== =============================
  114. The python-specific counts of garbage collector performance have been renamed.
  115. =========================== ======================
  116. New name Old name
  117. =========================== ======================
  118. python_gc_time reactor_gc_time
  119. python_gc_unreachable_total reactor_gc_unreachable
  120. python_gc_counts reactor_gc_counts
  121. =========================== ======================
  122. The twisted-specific reactor metrics have been renamed.
  123. ==================================== =====================
  124. New name Old name
  125. ==================================== =====================
  126. python_twisted_reactor_pending_calls reactor_pending_calls
  127. python_twisted_reactor_tick_time reactor_tick_time
  128. ==================================== =====================