Skip to content

Commit 53ba6ec

Browse files
committed
move the collectdconsole thing into examples/
1 parent 698f6b9 commit 53ba6ec

File tree

4 files changed

+95
-26
lines changed

4 files changed

+95
-26
lines changed

examples/helloworld/README.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
====================
2+
Hello World Example
3+
====================
4+
5+
A minimal example to see sqlalchemy-collectd do something.
6+
7+
8+
Step One - Run collectd as a console app
9+
========================================
10+
11+
In one terminal window, run collectd as an interactive application with
12+
the -f flag::
13+
14+
# cd examples/helloworld
15+
# collectd -f -C collectdconsole.conf
16+
17+
The ``collectdconsole.conf`` includes a relative path to the
18+
sqlalchemy-collectd checkout as the module path.
19+
20+
Step Two - Run the demo program
21+
================================
22+
23+
This program uses a SQLite database for starters. It spins up
24+
five processes with 20 threads each::
25+
26+
# python run_queries.py
27+
28+
Step Three - watch collectd console
29+
===================================
30+
31+
Output looks something like::
32+
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"}]

collectdconsole.conf renamed to examples/helloworld/collectdconsole.conf

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ LoadPlugin write_log
1919

2020
LoadPlugin python
2121
<Plugin python>
22-
ModulePath "/home/classic/dev/sqlalchemy-collectd"
22+
ModulePath "../../"
2323
LogTraces true
2424

25-
</Plugin>
26-
27-
<Plugin python>
2825
Import "sqlalchemy_collectd.server.plugin"
2926

3027
<Module "sqlalchemy_collectd.server.plugin">
@@ -36,25 +33,3 @@ LoadPlugin python
3633
</Plugin>
3734

3835

39-
LoadPlugin write_graphite
40-
41-
<Plugin write_graphite>
42-
<Node "local">
43-
Host localhost
44-
Port "2003"
45-
Protocol "tcp"
46-
ReconnectInterval 0
47-
LogSendErrors true
48-
Prefix "collectd."
49-
#Postfix "collectd"
50-
StoreRates true
51-
AlwaysAppendDS false
52-
EscapeCharacter "_"
53-
SeparateInstances false
54-
PreserveSeparator false
55-
DropDuplicateFields false
56-
</Node>
57-
</Plugin>
58-
59-
#LoadPlugin interface
60-
#LoadPlugin cpu

examples/helloworld/file.db

Whitespace-only changes.

examples/helloworld/run_queries.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from sqlalchemy import create_engine
2+
import random
3+
import time
4+
import threading
5+
import multiprocessing
6+
7+
import logging
8+
logging.basicConfig()
9+
logging.getLogger("sqlalchemy_collectd").setLevel(logging.DEBUG)
10+
11+
e = create_engine("sqlite:///file.db?plugin=collectd")
12+
13+
14+
def worker():
15+
e.dispose()
16+
17+
def screw_w_pool():
18+
while True:
19+
conn = e.connect()
20+
try:
21+
time.sleep(random.random())
22+
conn.execute("select 1")
23+
time.sleep(random.random())
24+
finally:
25+
conn.close()
26+
time.sleep(random.randint(1, 5))
27+
28+
threads = [threading.Thread(target=screw_w_pool) for i in range(20)]
29+
for t in threads:
30+
t.daemon = True
31+
t.start()
32+
33+
while True:
34+
time.sleep(1)
35+
36+
37+
procs = [multiprocessing.Process(target=worker) for i in range(5)]
38+
for proc in procs:
39+
time.sleep(.5)
40+
proc.daemon = True
41+
proc.start()
42+
43+
while True:
44+
time.sleep(1)

0 commit comments

Comments
 (0)