|
32 | 32 | )
|
33 | 33 |
|
34 | 34 | from twisted.internet import reactor
|
| 35 | +from twisted.python.threadpool import ThreadPool |
35 | 36 |
|
36 | 37 | import synapse
|
37 | 38 | from synapse.metrics._exposition import (
|
@@ -522,6 +523,42 @@ def collect(self):
|
522 | 523 | labelnames=("type", "reason"),
|
523 | 524 | )
|
524 | 525 |
|
| 526 | +threadpool_total_threads = Gauge( |
| 527 | + "synapse_threadpool_total_threads", |
| 528 | + "Total number of threads currently in the threadpool", |
| 529 | + ["name"], |
| 530 | +) |
| 531 | + |
| 532 | +threadpool_total_working_threads = Gauge( |
| 533 | + "synapse_threadpool_working_threads", |
| 534 | + "Number of threads currently working in the threadpool", |
| 535 | + ["name"], |
| 536 | +) |
| 537 | + |
| 538 | +threadpool_total_min_threads = Gauge( |
| 539 | + "synapse_threadpool_min_threads", |
| 540 | + "Minimum number of threads configured in the threadpool", |
| 541 | + ["name"], |
| 542 | +) |
| 543 | + |
| 544 | +threadpool_total_max_threads = Gauge( |
| 545 | + "synapse_threadpool_max_threads", |
| 546 | + "Maximum number of threads configured in the threadpool", |
| 547 | + ["name"], |
| 548 | +) |
| 549 | + |
| 550 | + |
| 551 | +def register_threadpool(name: str, threadpool: ThreadPool) -> None: |
| 552 | + """Add metrics for the threadpool.""" |
| 553 | + |
| 554 | + threadpool_total_min_threads.labels(name).set(threadpool.min) |
| 555 | + threadpool_total_max_threads.labels(name).set(threadpool.max) |
| 556 | + |
| 557 | + threadpool_total_threads.labels(name).set_function(lambda: len(threadpool.threads)) |
| 558 | + threadpool_total_working_threads.labels(name).set_function( |
| 559 | + lambda: len(threadpool.working) |
| 560 | + ) |
| 561 | + |
525 | 562 |
|
526 | 563 | class ReactorLastSeenMetric:
|
527 | 564 | def collect(self):
|
|
0 commit comments