Skip to content

Commit ae3c5c5

Browse files
committed
Refactor all systems to use Values; connmon becomes separate
The "connmon" tool can now display stats for SQLAlchemy stats that are sent to a collectd server via the "network" plugin or through any other means. Previously, the connmon tool could only display stats for messages that were sent to a the collectd server by the SQLAlchemy-collectd plugin itself. The server side configuration for "connmon" is now separate from that of the SQLAlchemy-collectd plugin, and the two plugins can run independently of each other. This allows for a configuration where many hosts send SQLAlchemy-collectd messages to local collectd servers for aggregation, and those servers then pass their messages onto another collectd server, where the "connmon" tool can provide a view inside the current stats. In order to achieve this, major refactoring such that the internals now deal with data in terms of a structure which mirrors the collectd-python "Values" object is in place, along with a rearchitecture of the connmon tool such that it now consumes collectd "Values" objects from a particular collectd server regardless of how those "Values" arrived in that server. Fixes: #8 Change-Id: Idbbf607ad571f9eb723f2230ec1a3adad33aa536
1 parent 39e1e1a commit ae3c5c5

32 files changed

Lines changed: 1375 additions & 792 deletions

README.rst

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,6 @@ if you are using gevent, eventlet, asyncio, gunicorn, etc. threads are your
185185
friend).
186186

187187

188-
TODO
189-
^^^^
190-
191-
We can add options so that stats are still grouped under parent pids, that
192-
is instead of using ``<progname>`` as the classifier we use
193-
``<progname>-<parentpid>``, like ``nova_api-15840`` vs. ``nova_api-4573``, etc.
194-
Of course we can report on the raw subprocess identifiers as well but this
195-
doesn't appear to be that useful.
196-
197-
198188

199189
Server
200190
------
@@ -434,8 +424,8 @@ As an added feature, the **connmon** UX has now been integrated into SQLAlchemy-
434424
This is a console application that displays a "top"-like display of the current
435425
status of connections.
436426

437-
Using the configuration above, we can add a "monitor" line to our collectd
438-
server configuration::
427+
Using the configuration above, we can add a a plugin configuration for the
428+
connmon server plugin::
439429

440430

441431
LoadPlugin python
@@ -451,15 +441,29 @@ server configuration::
451441
# set to "debug" to show messages received
452442
loglevel "info"
453443

454-
# connmon monitor port
444+
</Module>
445+
446+
Import "sqlalchemy_collectd.connmon.plugin"
447+
<Module "sqlalchemy_collectd.connmon.plugin">
455448
monitor "localhost" 25828
449+
450+
# set to "debug" to show messaging
451+
#loglevel "debug"
456452
</Module>
453+
457454
</Plugin>
458455

459456
We can now run "connmon" on localhost port 25828::
460457

461458
connmon --port 25828
462459

460+
The connmon plugin and command line tool as of version 0.6 works independently
461+
of the "server" plugin, and may be configured by itself without the server
462+
plugin being present. It now consumes sqlalchemy-collectd events not only from
463+
the local server plugin if present, but from also from any other
464+
sqlalchemy-collectd messages that are forwarded to the server from elsewhere,
465+
typically via the "network" plugin.
466+
463467
Screenshot of connmon:
464468

465469
|connmon_screenshot|

examples/helloworld/README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ In one terminal window, run collectd as an interactive application with
1111
the -f flag::
1212

1313
# cd examples/helloworld
14-
# collectd -f -C collectdconsole.conf
14+
# collectd -f -C client_plus_connmon.conf
1515

16-
The ``collectdconsole.conf`` includes a relative path to the
16+
The ``client_plus_connmon.conf`` file includes a relative path to the
1717
sqlalchemy-collectd checkout as the module path.
1818

1919
Step Two - Run the demo program
@@ -29,7 +29,7 @@ Step Three - watch collectd console
2929

3030
Output looks something like::
3131

32-
$ collectd -f -C collectdconsole.conf
32+
$ collectd -f -C client_plus_connmon.conf
3333
[2018-02-11 18:29:35] plugin_load: plugin "logfile" successfully loaded.
3434
[2018-02-11 18:29:35] [info] plugin_load: plugin "write_log" successfully loaded.
3535
[2018-02-11 18:29:35] [info] plugin_load: plugin "python" successfully loaded.
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ LoadPlugin write_log
1717
Format JSON
1818
</Plugin>
1919

20+
LoadPlugin network
21+
<Plugin network>
22+
<Server "localhost" "25826">
23+
SecurityLevel "None"
24+
25+
</Server>
26+
</Plugin>
27+
2028
LoadPlugin python
2129
<Plugin python>
2230
ModulePath "../../"
@@ -27,13 +35,19 @@ LoadPlugin python
2735
<Module "sqlalchemy_collectd.server.plugin">
2836
listen "localhost" 25827
2937

30-
# set to "debug" to show messages received
31-
loglevel "info"
38+
# set to "debug" to show messaging
39+
loglevel "debug"
3240

33-
# connmon monitor port
34-
monitor "localhost" 25828
41+
</Module>
42+
43+
Import "sqlalchemy_collectd.connmon.plugin"
44+
<Module "sqlalchemy_collectd.connmon.plugin">
45+
monitor "localhost" 25828
3546

47+
# set to "debug" to show messaging
48+
#loglevel "debug"
3649
</Module>
50+
3751
</Plugin>
3852

3953

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# this config file is the same as client.conf, but also
2+
# includes the optional "connmon" plugin.
3+
#
4+
#
5+
# Run the server as:
6+
# collectd -f -C collectdconsole.conf
7+
#
8+
# received messages will be dumped as JSON to stdout.
9+
#
10+
# then in another window run connmon:
11+
# connmon
12+
13+
# send logging to STDOUT
14+
LoadPlugin logfile
15+
<Plugin logfile>
16+
# note "debug" will usually not work
17+
LogLevel "info"
18+
File STDOUT
19+
Timestamp true
20+
PrintSeverity true
21+
</Plugin>
22+
23+
# write messages in JSON format to the log
24+
LoadPlugin write_log
25+
<Plugin write_log>
26+
Format JSON
27+
</Plugin>
28+
29+
LoadPlugin python
30+
<Plugin python>
31+
ModulePath "../../"
32+
LogTraces true
33+
34+
Import "sqlalchemy_collectd.server.plugin"
35+
36+
<Module "sqlalchemy_collectd.server.plugin">
37+
listen "localhost" 25827
38+
39+
# set to "debug" to show messaging
40+
loglevel "debug"
41+
42+
</Module>
43+
44+
Import "sqlalchemy_collectd.connmon.plugin"
45+
<Module "sqlalchemy_collectd.connmon.plugin">
46+
monitor "localhost" 25828
47+
48+
# set to "debug" to show messaging
49+
#loglevel "debug"
50+
</Module>
51+
52+
</Plugin>
53+
54+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=========================
2+
Multiple Collectd Example
3+
=========================
4+
5+
In this example, multiple collectd servers can relay their messages
6+
to a central "aggregation" collectd server via the network plugin. That
7+
aggregation server then has stats for all the endpoints together which
8+
can be viewed with collectd clients, and can also be inspected "live" using
9+
connmon.
10+
11+
* local_client.conf - defines the setup for the initial collectd servers that
12+
are close to the SQLAlchemy applications generating stats. Includes the
13+
network plugin instructing them to call out to the central aggregation server.
14+
15+
* receiver.conf - defines the central aggregation server. Note this includes
16+
only the network plugin and the connmon plugin. SQLAlchemy clients don't
17+
connect directly to this server.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
LoadPlugin network
2+
<Plugin "network">
3+
## send udp on 25826
4+
Server "localhost" "25826"
5+
</Plugin>
6+
7+
LoadPlugin python
8+
<Plugin python>
9+
ModulePath "../../"
10+
LogTraces true
11+
12+
Import "sqlalchemy_collectd.server.plugin"
13+
14+
# SQLAlchemy clients connect to port 25827
15+
<Module "sqlalchemy_collectd.server.plugin">
16+
listen "localhost" 25827
17+
18+
# set to "debug" to show messaging
19+
loglevel "info"
20+
21+
</Module>
22+
23+
24+
</Plugin>
25+
26+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
LoadPlugin network
3+
<Plugin "network">
4+
## receive udp on 25826
5+
Listen "localhost" "25826"
6+
</Plugin>
7+
8+
LoadPlugin python
9+
<Plugin python>
10+
ModulePath "../../"
11+
LogTraces true
12+
13+
Import "sqlalchemy_collectd.connmon.plugin"
14+
15+
# connmon clients connect to 25828
16+
<Module "sqlalchemy_collectd.connmon.plugin">
17+
monitor "localhost" 25828
18+
19+
# set to "debug" to show messaging
20+
loglevel "info"
21+
</Module>
22+
23+
</Plugin>
24+
25+

sqlalchemy_collectd/client/internal_types.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

sqlalchemy_collectd/client/plugin.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import absolute_import
2+
3+
import logging
14
import os
25
import socket
36
import sys
@@ -7,7 +10,8 @@
710
from . import collector
811
from . import sender
912
from . import worker
10-
from .. import protocol
13+
14+
log = logging.getLogger("sqlalchemy_collectd")
1115

1216

1317
class Plugin(CreateEnginePlugin):
@@ -69,14 +73,18 @@ def start_plugin(
6973
if progname is None:
7074
progname = os.path.basename(sys.argv[0])
7175

72-
sender_ = sender.Sender(hostname, progname)
76+
# registry on progname
7377
collection_target = collector.CollectionTarget.collection_for_name(
7478
progname
7579
)
80+
81+
# unique per Engine
7682
collector.EngineCollector(collection_target, engine)
7783

78-
connection = protocol.ClientConnection.for_host_port(
79-
collectd_host, collectd_port
84+
# registry on host/prog/host/port
85+
sender_ = sender.Sender.get_sender(
86+
hostname, progname, collectd_host, collectd_port, log
8087
)
8188

82-
worker.add_target(connection, collection_target, sender_)
89+
# registry on collection_target / sender
90+
worker.add_target(collection_target, sender_)

0 commit comments

Comments
 (0)