mirror of
https://mau.dev/maunium/synapse.git
synced 2025-01-07 13:34:48 +01:00
Option to serve metrics from their own localhost-only TCP port instead of muxed on the main listener
This commit is contained in:
parent
a2cdd11d4a
commit
b98b4c135d
2 changed files with 15 additions and 2 deletions
|
@ -129,7 +129,8 @@ class SynapseHomeServer(HomeServer):
|
||||||
location of the web client. This does nothing if web_client is not
|
location of the web client. This does nothing if web_client is not
|
||||||
True.
|
True.
|
||||||
"""
|
"""
|
||||||
web_client = self.get_config().webclient
|
config = self.get_config()
|
||||||
|
web_client = config.webclient
|
||||||
|
|
||||||
# list containing (path_str, Resource) e.g:
|
# list containing (path_str, Resource) e.g:
|
||||||
# [ ("/aaa/bbb/cc", Resource1), ("/aaa/dummy", Resource2) ]
|
# [ ("/aaa/bbb/cc", Resource1), ("/aaa/dummy", Resource2) ]
|
||||||
|
@ -155,7 +156,7 @@ class SynapseHomeServer(HomeServer):
|
||||||
self.root_resource = Resource()
|
self.root_resource = Resource()
|
||||||
|
|
||||||
metrics_resource = self.get_resource_for_metrics()
|
metrics_resource = self.get_resource_for_metrics()
|
||||||
if metrics_resource is not None:
|
if config.metrics_port is None and metrics_resource is not None:
|
||||||
desired_tree.append((METRICS_PREFIX, metrics_resource))
|
desired_tree.append((METRICS_PREFIX, metrics_resource))
|
||||||
|
|
||||||
# ideally we'd just use getChild and putChild but getChild doesn't work
|
# ideally we'd just use getChild and putChild but getChild doesn't work
|
||||||
|
@ -234,6 +235,13 @@ class SynapseHomeServer(HomeServer):
|
||||||
)
|
)
|
||||||
logger.info("Synapse now listening on port %d", config.unsecure_port)
|
logger.info("Synapse now listening on port %d", config.unsecure_port)
|
||||||
|
|
||||||
|
metrics_resource = self.get_resource_for_metrics()
|
||||||
|
if metrics_resource and config.metrics_port is not None:
|
||||||
|
reactor.listenTCP(
|
||||||
|
config.metrics_port, Site(metrics_resource), interface="127.0.0.1",
|
||||||
|
)
|
||||||
|
logger.info("Metrics now running on 127.0.0.1 port %d", config.metrics_port)
|
||||||
|
|
||||||
|
|
||||||
def get_version_string():
|
def get_version_string():
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -20,6 +20,7 @@ class MetricsConfig(Config):
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
super(MetricsConfig, self).__init__(args)
|
super(MetricsConfig, self).__init__(args)
|
||||||
self.enable_metrics = args.enable_metrics
|
self.enable_metrics = args.enable_metrics
|
||||||
|
self.metrics_port = args.metrics_port
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_arguments(cls, parser):
|
def add_arguments(cls, parser):
|
||||||
|
@ -29,3 +30,7 @@ class MetricsConfig(Config):
|
||||||
'--enable-metrics', dest="enable_metrics", action="store_true",
|
'--enable-metrics', dest="enable_metrics", action="store_true",
|
||||||
help="Enable collection and rendering of performance metrics"
|
help="Enable collection and rendering of performance metrics"
|
||||||
)
|
)
|
||||||
|
metrics_group.add_argument(
|
||||||
|
'--metrics-port', metavar="PORT", type=int,
|
||||||
|
help="Separate port to accept metrics requests on (on localhost)"
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue