Skip to content

Commit 5cfa7bb

Browse files
zzzeekGerrit Code Review
authored andcommitted
Merge "Add connmon implementation"
2 parents 429c4ca + 6e6da33 commit 5cfa7bb

File tree

19 files changed

+773
-144
lines changed

19 files changed

+773
-144
lines changed

README.rst

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ collectd.d/sqlalchemy.conf file, assuming a system-installed sqlalchemy-collectd
214214

215215
# set to "debug" to show messages received
216216
loglevel "info"
217+
217218
</Module>
218219
</Plugin>
219220

@@ -424,4 +425,44 @@ explicitly referred to by absolute path within a conf file, and then to
424425
make matters worse when this option is used, we have to uncomment the location
425426
of the default types.db file in the central collectd.conf else it will
426427
no longer be able to find it. Given the choice between "very nice names"
427-
and "no need to set up three separate config files", we chose the latter :)
428+
and "no need to set up three separate config files", we chose the latter :)
429+
430+
connmon mode
431+
============
432+
433+
As an added feature, the **connmon** UX has now been integrated into SQLAlchemy-collectd.
434+
This is a console application that displays a "top"-like display of the current
435+
status of connections.
436+
437+
Using the configuration above, we can add a "monitor" line to our collectd
438+
server configuration::
439+
440+
441+
LoadPlugin python
442+
<Plugin python>
443+
LogTraces true
444+
445+
Import "sqlalchemy_collectd.server.plugin"
446+
447+
<Module "sqlalchemy_collectd.server.plugin">
448+
# ipv4 only for the moment
449+
listen "0.0.0.0" 25827
450+
451+
# set to "debug" to show messages received
452+
loglevel "info"
453+
454+
# connmon monitor port
455+
monitor "localhost" 25828
456+
</Module>
457+
</Plugin>
458+
459+
We can now run "connmon" on localhost port 25828::
460+
461+
connmon --port 25828
462+
463+
Screenshot of connmon:
464+
465+
|connmon_screenshot|
466+
467+
.. |connmon_screenshot| image:: connmon.png
468+
:width: 800

connmon.png

147 KB
Loading

examples/helloworld/README.rst

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ Hello World Example
44

55
A minimal example to see sqlalchemy-collectd do something.
66

7-
87
Step One - Run collectd as a console app
98
========================================
109

1110
In one terminal window, run collectd as an interactive application with
1211
the -f flag::
1312

14-
# cd examples/helloworld
15-
# collectd -f -C collectdconsole.conf
13+
# cd examples/helloworld
14+
# collectd -f -C collectdconsole.conf
1615

1716
The ``collectdconsole.conf`` includes a relative path to the
1817
sqlalchemy-collectd checkout as the module path.
@@ -23,28 +22,39 @@ Step Two - Run the demo program
2322
This program uses a SQLite database for starters. It spins up
2423
five processes with 20 threads each::
2524

26-
# python run_queries.py
25+
# python run_queries.py
2726

2827
Step Three - watch collectd console
2928
===================================
3029

3130
Output looks something like::
3231

33-
$ collectd -f -C collectdconsole.conf
34-
[2018-02-11 18:29:35] plugin_load: plugin "logfile" successfully loaded.
35-
[2018-02-11 18:29:35] [info] plugin_load: plugin "write_log" successfully loaded.
36-
[2018-02-11 18:29:35] [info] plugin_load: plugin "python" successfully loaded.
37-
[2018-02-11 18:29:35] [info] sqlalchemy_collectd plugin version 0.0.1
38-
[2018-02-11 18:29:35] [info] Python version: 3.6.4 (default, Jan 23 2018, 22:28:37)
39-
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)]
40-
[2018-02-11 18:29:35] [info] Initialization complete, entering read-loop.
41-
[2018-02-11 18:29:45] [info] write_log values:
42-
[{"values":[0],"dstypes":["gauge"],"dsnames":["value"],"time":1518391784.793,"interval":10.000,"host":"photon2","plugin":"sqlalchemy","plugin_instance":"run_queries.py","type":"count","type_instance":"checkedin"}]
43-
[2018-02-11 18:29:45] [info] write_log values:
44-
[{"values":[0],"dstypes":["gauge"],"dsnames":["value"],"time":1518391784.793,"interval":10.000,"host":"photon2","plugin":"sqlalchemy","plugin_instance":"run_queries.py","type":"count","type_instance":"detached"}]
45-
[2018-02-11 18:29:45] [info] write_log values:
46-
[{"values":[6],"dstypes":["gauge"],"dsnames":["value"],"time":1518391784.793,"interval":10.000,"host":"photon2","plugin":"sqlalchemy","plugin_instance":"run_queries.py","type":"count","type_instance":"numprocs"}]
47-
[2018-02-11 18:29:45] [info] write_log values:
48-
[{"values":[6],"dstypes":["gauge"],"dsnames":["value"],"time":1518391784.793,"interval":10.000,"host":"photon2","plugin":"sqlalchemy","plugin_instance":"run_queries.py","type":"count","type_instance":"numpools"}]
49-
[2018-02-11 18:29:45] [info] write_log values:
50-
[{"values":[28],"dstypes":["gauge"],"dsnames":["value"],"time":1518391784.793,"interval":10.000,"host":"photon2","plugin":"sqlalchemy","plugin_instance":"host","type":"count","type_instance":"checkedout"}]
32+
$ collectd -f -C collectdconsole.conf
33+
[2018-02-11 18:29:35] plugin_load: plugin "logfile" successfully loaded.
34+
[2018-02-11 18:29:35] [info] plugin_load: plugin "write_log" successfully loaded.
35+
[2018-02-11 18:29:35] [info] plugin_load: plugin "python" successfully loaded.
36+
[2018-02-11 18:29:35] [info] sqlalchemy_collectd plugin version 0.0.1
37+
[2018-02-11 18:29:35] [info] Python version: 3.6.4 (default, Jan 23 2018, 22:28:37)
38+
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)]
39+
[2018-02-11 18:29:35] [info] Initialization complete, entering read-loop.
40+
[2018-02-11 18:29:45] [info] write_log values:
41+
[{"values":[0],"dstypes":["gauge"],"dsnames":["value"],"time":1518391784.793,"interval":10.000,"host":"photon2","plugin":"sqlalchemy","plugin_instance":"run_queries.py","type":"count","type_instance":"checkedin"}]
42+
[2018-02-11 18:29:45] [info] write_log values:
43+
[{"values":[0],"dstypes":["gauge"],"dsnames":["value"],"time":1518391784.793,"interval":10.000,"host":"photon2","plugin":"sqlalchemy","plugin_instance":"run_queries.py","type":"count","type_instance":"detached"}]
44+
[2018-02-11 18:29:45] [info] write_log values:
45+
[{"values":[6],"dstypes":["gauge"],"dsnames":["value"],"time":1518391784.793,"interval":10.000,"host":"photon2","plugin":"sqlalchemy","plugin_instance":"run_queries.py","type":"count","type_instance":"numprocs"}]
46+
[2018-02-11 18:29:45] [info] write_log values:
47+
[{"values":[6],"dstypes":["gauge"],"dsnames":["value"],"time":1518391784.793,"interval":10.000,"host":"photon2","plugin":"sqlalchemy","plugin_instance":"run_queries.py","type":"count","type_instance":"numpools"}]
48+
[2018-02-11 18:29:45] [info] write_log values:
49+
[{"values":[28],"dstypes":["gauge"],"dsnames":["value"],"time":1518391784.793,"interval":10.000,"host":"photon2","plugin":"sqlalchemy","plugin_instance":"host","type":"count","type_instance":"checkedout"}]
50+
51+
Step Four - Try out Connmon
52+
===========================
53+
54+
The **connmon** console client is an optional feature that connects to the
55+
SQLAlchemy-collectd plugin running inside the collectd server to print live
56+
stats. Once the above steps are all running, try out the client::
57+
58+
# connmon
59+
60+

examples/helloworld/collectdconsole.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ LoadPlugin python
2929

3030
# set to "debug" to show messages received
3131
loglevel "info"
32+
33+
# connmon monitor port
34+
monitor "localhost" 25828
35+
3236
</Module>
3337
</Plugin>
3438

examples/helloworld/run_queries.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
from sqlalchemy import create_engine
1+
import logging
2+
import multiprocessing
23
import random
3-
import time
44
import threading
5-
import multiprocessing
5+
import time
6+
7+
from sqlalchemy import create_engine
68

7-
import logging
89
logging.basicConfig()
910
logging.getLogger("sqlalchemy_collectd").setLevel(logging.DEBUG)
1011

11-
e = create_engine("sqlite:///file.db?plugin=collectd")
1212

13+
def worker(appname):
14+
e = create_engine(
15+
"sqlite:///file.db?plugin=collectd&collectd_program_name=%s" % appname
16+
)
1317

14-
def worker():
1518
e.dispose()
1619

1720
def screw_w_pool():
@@ -25,7 +28,7 @@ def screw_w_pool():
2528
conn.close()
2629
time.sleep(random.randint(1, 5))
2730

28-
threads = [threading.Thread(target=screw_w_pool) for i in range(20)]
31+
threads = [threading.Thread(target=screw_w_pool) for i in range(5)]
2932
for t in threads:
3033
t.daemon = True
3134
t.start()
@@ -34,11 +37,14 @@ def screw_w_pool():
3437
time.sleep(1)
3538

3639

37-
procs = [multiprocessing.Process(target=worker) for i in range(5)]
40+
procs = [
41+
multiprocessing.Process(target=worker, args=(("worker %d" % (i % 20)),))
42+
for i in range(50)
43+
]
3844
for proc in procs:
39-
time.sleep(.5)
45+
time.sleep(0.5)
4046
proc.daemon = True
4147
proc.start()
4248

4349
while True:
44-
time.sleep(1)
50+
time.sleep(1)

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ def run_tests(self):
6868
zip_safe=False,
6969
install_requires=requires,
7070
entry_points={
71+
"console_scripts": ["connmon = sqlalchemy_collectd.connmon.main:main"],
7172
"sqlalchemy.plugins": [
7273
"collectd = sqlalchemy_collectd.client.plugin:Plugin"
73-
]
74+
],
7475
},
7576
)

sqlalchemy_collectd/client/worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def _check_threads_started():
1818
if _WORKER_THREAD is None or _PID != ospid:
1919

2020
_PID = ospid
21-
_WORKER_THREAD = threading.Thread(target=_process, args=(5,))
21+
_WORKER_THREAD = threading.Thread(target=_process, args=(2,))
2222
_WORKER_THREAD.daemon = True
2323
_WORKER_THREAD.start()
2424

sqlalchemy_collectd/connmon/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)