Skip to content

Commit 1270028

Browse files
committed
Rename internal_types to collectd_types
Fix examples, docs, comments after #8 has merged. Change-Id: Ib9ba9fc1c89b5779fdecf8c43630271effb0a411
1 parent f8906e2 commit 1270028

8 files changed

Lines changed: 79 additions & 90 deletions

File tree

examples/helloworld/client.conf

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
1-
# A config file that lets you test collectd locally.
1+
# A config file that lets you test SQLAlchemy-collectd locally.
22
# Run just like this:
3-
# collectd -f -C collectdconsole.conf
3+
# collectd -f -C client.conf
44
# received messages will be dumped as JSON to stdout.
55

66
LoadPlugin logfile
77
<Plugin logfile>
8-
# note "debug" will usually not work
9-
LogLevel "info"
10-
File STDOUT
11-
Timestamp true
12-
PrintSeverity true
8+
# note "debug" will usually not work
9+
LogLevel "info"
10+
File STDOUT
11+
Timestamp true
12+
PrintSeverity true
1313
</Plugin>
1414

1515
LoadPlugin write_log
1616
<Plugin write_log>
17-
Format JSON
18-
</Plugin>
19-
20-
LoadPlugin network
21-
<Plugin network>
22-
<Server "localhost" "25826">
23-
SecurityLevel "None"
24-
25-
</Server>
17+
Format JSON
2618
</Plugin>
2719

2820
LoadPlugin python
@@ -36,18 +28,10 @@ LoadPlugin python
3628
listen "localhost" 25827
3729

3830
# set to "debug" to show messaging
39-
loglevel "debug"
31+
loglevel "info"
4032

4133
</Module>
4234

43-
Import "sqlalchemy_collectd.connmon.plugin"
44-
<Module "sqlalchemy_collectd.connmon.plugin">
45-
monitor "localhost" 25828
46-
47-
# set to "debug" to show messaging
48-
#loglevel "debug"
49-
</Module>
50-
5135
</Plugin>
5236

5337

examples/helloworld/client_plus_connmon.conf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
#
55
# Run the server as:
6-
# collectd -f -C collectdconsole.conf
6+
# collectd -f -C client_plus_connmon.conf
77
#
88
# received messages will be dumped as JSON to stdout.
99
#
@@ -13,17 +13,17 @@
1313
# send logging to STDOUT
1414
LoadPlugin logfile
1515
<Plugin logfile>
16-
# note "debug" will usually not work
17-
LogLevel "info"
18-
File STDOUT
19-
Timestamp true
20-
PrintSeverity true
16+
# note "debug" will usually not work
17+
LogLevel "info"
18+
File STDOUT
19+
Timestamp true
20+
PrintSeverity true
2121
</Plugin>
2222

2323
# write messages in JSON format to the log
2424
LoadPlugin write_log
2525
<Plugin write_log>
26-
Format JSON
26+
Format JSON
2727
</Plugin>
2828

2929
LoadPlugin python

sqlalchemy_collectd/client/sender.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import threading
22

3-
from .. import internal_types
3+
from .. import collectd_types
44
from .. import protocol
55

66

@@ -26,7 +26,7 @@ def __init__(
2626
collectd_host,
2727
collectd_port,
2828
log,
29-
plugin=internal_types.COLLECTD_PLUGIN_NAME,
29+
plugin=collectd_types.COLLECTD_PLUGIN_NAME,
3030
):
3131
self.hostname = hostname
3232
self.stats_name = stats_name
@@ -69,10 +69,10 @@ def get_sender(
6969
cls.create_mutex.release()
7070

7171

72-
@sends(internal_types.pool_internal)
72+
@sends(collectd_types.pool_internal)
7373
def _send_pool(values, collection_target):
7474
return values.build(
75-
type=internal_types.pool_internal.name,
75+
type=collectd_types.pool_internal.name,
7676
values=[
7777
collection_target.num_pools,
7878
collection_target.num_checkedout,
@@ -84,10 +84,10 @@ def _send_pool(values, collection_target):
8484
)
8585

8686

87-
@sends(internal_types.totals_internal)
87+
@sends(collectd_types.totals_internal)
8888
def _send_connection_totals(values, collection_target):
8989
return values.build(
90-
type=internal_types.totals_internal.name,
90+
type=collectd_types.totals_internal.name,
9191
values=[
9292
collection_target.total_checkouts,
9393
collection_target.total_invalidated,
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1-
from . import protocol
1+
"""Type objects representing the collectd types used.
2+
3+
There are two classes of types here; "internal" types are used between
4+
the SQLAlchemy-collectd client plugin embedded in applications and the
5+
SQLAlchemy-collectd server plugin. These type objects are not part of
6+
collectd's types.db, and in the interests of configuration simplicity
7+
and portability, these types are not exposed outside of the communication
8+
between the two SQLAlchemy-collectd plugins.
9+
10+
The other type defined here are "external" types, which are public collectd
11+
types defined in /usr/share/collectd/types.db or similar. We are using the
12+
"count" and "derive" types which are generic types that define a single "GAUGE"
13+
and a single "DERIVE" value, respectively. When the SQLAlchemy-collectd server
14+
plugin aggregates and reports on the results it receives from the client, it
15+
converts the "internal" types into "external" types and streams them into
16+
collectd as the result. These are the stats that are then consumable by all
17+
collectd "writer" systems such as logging, network and grafana.
218
3-
# internal types. These are used by the SQLAlchemy client plugin
4-
# to talk to the SQLAlchemy collectd plugin.
19+
20+
"""
21+
from . import protocol
522

623

724
COLLECTD_PLUGIN_NAME = "sqlalchemy"
@@ -45,6 +62,6 @@
4562
)
4663

4764

65+
# external types "count" and "derive".
4866
count_external = protocol.Type("count", ("value", protocol.VALUE_GAUGE))
49-
5067
derive_external = protocol.Type("derive", ("value", protocol.VALUE_DERIVE))

sqlalchemy_collectd/connmon/main.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from . import display
77
from . import stat
8-
from .. import internal_types
8+
from .. import collectd_types
99
from .. import protocol
1010

1111
log = logging.getLogger(__name__)
@@ -30,29 +30,17 @@ def main(argv=None):
3030

3131
network_receiver = protocol.NetworkReceiver(
3232
protocol.ServerConnection(options.host, options.port, log),
33-
[internal_types.count_external, internal_types.derive_external],
33+
[collectd_types.count_external, collectd_types.derive_external],
3434
)
3535

3636
stat_ = stat.Stat(network_receiver, log)
3737
stat_.start()
3838

3939
service_str = "[Direct host: %s:%s]" % (options.host, options.port)
4040

41-
# _dummy_wait()
4241
display_ = display.Display(stat_, service_str)
4342
display_.start()
4443

4544

46-
def _dummy_wait():
47-
import time
48-
import logging
49-
50-
# logging.basicConfig()
51-
log.setLevel(logging.DEBUG)
52-
53-
while True:
54-
time.sleep(5)
55-
56-
5745
if __name__ == "__main__":
5846
main()

sqlalchemy_collectd/connmon/plugin.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import collectd
66

7-
from .. import internal_types
7+
from .. import collectd_types
88
from .. import protocol
99
from ..server.logging import CollectdHandler
1010

@@ -27,7 +27,7 @@ def start_plugin(config):
2727
)
2828
CollectdHandler.setup(__name__, config_dict.get("loglevel", ("info",))[0])
2929

30-
types = [internal_types.derive_external, internal_types.count_external]
30+
types = [collectd_types.derive_external, collectd_types.count_external]
3131

3232
message_sender = protocol.NetworkSender(
3333
protocol.ClientConnection(monitor_host, int(monitor_port), log), types
@@ -42,17 +42,16 @@ def start_plugin(config):
4242

4343

4444
def write(cd_values_obj):
45-
"""Receive values from the collectd server in which we are embedded, and
46-
send them to an aggregator that will broadcast them to clients.
45+
"""Receive values from the collectd server and forward out on UDP
46+
for connmon listeners to receive.
4747
4848
The values are received as "external" types, meaning they use the
49-
"derive" and "count" types in collectd types.db; an aggregator collects
50-
these and builds them into "internal" types which combine multiple
51-
types of values into single records.
49+
"derive" and "count" types in collectd types.db. The connmon client
50+
now receives and interprets these objects directly.
5251
5352
"""
5453

55-
if cd_values_obj.plugin == internal_types.COLLECTD_PLUGIN_NAME:
54+
if cd_values_obj.plugin == collectd_types.COLLECTD_PLUGIN_NAME:
5655
values_obj = protocol.Values.from_collectd_values(cd_values_obj, log)
5756
message_sender.send(values_obj)
5857

sqlalchemy_collectd/server/receiver.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import itertools
44
import logging
55

6-
from .. import internal_types
6+
from .. import collectd_types
77
from .. import protocol
88
from .. import stream
99

@@ -12,20 +12,20 @@
1212

1313
class Receiver(object):
1414
def __init__(
15-
self, host, port, log, plugin=internal_types.COLLECTD_PLUGIN_NAME
15+
self, host, port, log, plugin=collectd_types.COLLECTD_PLUGIN_NAME
1616
):
1717
self.log = log
1818
self.plugin = plugin
19-
self.internal_types = [
20-
internal_types.pool_internal,
21-
internal_types.totals_internal,
22-
internal_types.process_internal,
19+
self.collectd_types = [
20+
collectd_types.pool_internal,
21+
collectd_types.totals_internal,
22+
collectd_types.process_internal,
2323
]
2424
self.network_receiver = protocol.NetworkReceiver(
25-
protocol.ServerConnection(host, port, log), self.internal_types
25+
protocol.ServerConnection(host, port, log), self.collectd_types
2626
)
27-
self.translator = stream.StreamTranslator(*self.internal_types)
28-
self.bucket_names = [t.name for t in self.internal_types]
27+
self.translator = stream.StreamTranslator(*self.collectd_types)
28+
self.bucket_names = [t.name for t in self.collectd_types]
2929
self.buckets = {
3030
name: stream.TimeBucket() for name in self.bucket_names
3131
}
@@ -35,7 +35,7 @@ def receive(self):
3535
self._set_stats(values_obj)
3636

3737
def summarize(self, collectd, timestamp):
38-
for type_ in self.internal_types:
38+
for type_ in self.collectd_types:
3939
for values_obj in self.get_stats_by_progname(
4040
type_.name, timestamp
4141
):
@@ -70,14 +70,14 @@ def _set_stats(self, values):
7070
# process_token (which is roughly the pid plus a unique key
7171
# generated by the client plugin). we also use a larger interval
7272
# for this value so that the process count changes more slowly
73-
process_bucket = self.buckets[internal_types.process_internal.name]
73+
process_bucket = self.buckets[collectd_types.process_internal.name]
7474
process_records = process_bucket.get_data(
7575
timestamp, interval=interval * 5
7676
)
7777
process_records[
7878
(hostname, progname, process_token)
7979
] = values.build(
80-
type=internal_types.process_internal.name, values=[1]
80+
type=collectd_types.process_internal.name, values=[1]
8181
)
8282

8383
def get_stats_by_progname(self, bucket_name, timestamp, agg_func=sum):

sqlalchemy_collectd/stream.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,35 @@
22

33

44
class StreamTranslator(object):
5-
"""Translates Value objects between internal types and "external"
5+
"""Translates Value objects from the "internal" to the "external"
66
types.
77
8-
The "external" types are the simple types that are in collectd
9-
types.db, where we are looking at the "derive" type, which is a mapping
10-
to a single protocol.VALUE_DERIVE value, and the "count" type, which is
11-
a mapping to a zero-bounded protocol.VALUE_GAUGE type. There is also
12-
a "gauge" type however we are working with zero-bounded ranges.
13-
14-
We use these pre-defined types because SQLAlchemy-collectd does not
15-
have an entry in the collectd types.db file and collectd doesn't give us
16-
a straightforward way to extend on these types.
8+
The mapping from the "internal" types in collectd_types.py to
9+
the "external" types is to break each internal type into individual
10+
values of type GAUGE or DERIVE. The collectd "count" and "derive" types
11+
defined in types.db serve as the destination for these values.
1712
13+
While the "internal" types are more efficient and suitable for the large
14+
volume of messages sent by SQLAlchemy clients, as they are sent with a low
15+
"interval" setting as well as a full set of messages per process, the
16+
"external" types are publicly available for other collectd services and as
17+
the per-process messages have been aggregated into per-"program" messages
18+
and are usually at a lower interval, there is less message volume.
1819
1920
"""
2021

21-
def __init__(self, *internal_types):
22-
self.internal_types = internal_types
22+
def __init__(self, *collectd_types):
23+
self.collectd_types = collectd_types
2324

24-
self._type_by_name = {t.name: t for t in internal_types}
25+
self._type_by_name = {t.name: t for t in collectd_types}
2526
self.external_types = {}
2627
self.external_type_to_internal = {}
2728
self._protocol_type_string_names = {
2829
protocol.VALUE_GAUGE: "count",
2930
protocol.VALUE_DERIVE: "derive",
3031
}
3132

32-
for internal_type in internal_types:
33+
for internal_type in collectd_types:
3334
for name, value_type in zip(
3435
internal_type.names, internal_type.types
3536
):

0 commit comments

Comments
 (0)