def test_multiple_conns(self): conn1 = collectd.Connection(collectd_host="localhost") conn2 = collectd.Connection(collectd_host="127.0.0.1") conn1.foo.record(baz=5) conn2.bar.record(baz=5) collectd.take_snapshots() self.assertQueued(2)
def test_sameness(self): for params in [{"hostname": "127.0.0.1"}, {"collectd_port": 1337}]: self.assertTrue(self.conn is not collectd.Connection(**params)) self.assertTrue( collectd.Connection(plugin_inst="xkcd", **params) is not collectd.Connection(**params)) self.assertTrue( collectd.Connection(**params) is collectd.Connection(**params))
import time, random import collectd collectd.start_threads() conn = collectd.Connection() while True: conn.some_category.record(some_counter=1, another_stat=random.random()) if random.randrange(2): conn.coin_stats.record("heads", flips=1) else: conn.coin_stats.record("tails", flips=1) time.sleep(random.randint(1, 4))
return for v in val: c = conn.Values(type=v['t']) c.plugin = v['k'] c.dispatch(values=[v['v']]) def getopts(argv): opts = {} # Empty dictionary to store key-value pairs. while argv: # While there are arguments left to parse... if argv[0][0] == '-': # Found a "-name value" pair. new_key = argv[0].replace('-', '', 1) opts[new_key] = argv[1] # Add key and value to the dictionary. argv = argv[ 1:] # Reduce the argument list by copying it starting from index 1. print('Opts input:') print(opts) return opts if __name__ == '__main__': cfg = getopts(sys.argv) readvals(True) collectd.start_threads() conn = collectd.Connection(cfg['host_name'], cfg['collectd_name'], cfg['collectd_port']) else: conn.register_config(readconf) conn.register_read(readvals, int(cfg['interval']))
def test_plugin_inst(self): conn = collectd.Connection(collectd_port=self.TEST_PORT, plugin_inst="xkcd") self.assertTrue("xkcd" in self.send_and_recv(conn, foo=5))
def test_plugin_name(self): conn = collectd.Connection(collectd_port=self.TEST_PORT, plugin_name="dckx") self.assertTrue("dckx" in self.send_and_recv(conn, foo=5))
def setUp(self): self.conn = collectd.Connection(collectd_port=self.TEST_PORT) self.server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server.bind(("localhost", self.TEST_PORT))
def test_multiple_counters(self): conn = collectd.Connection() conn.foo.record(baz=5) conn.bar.record(baz=5) collectd.take_snapshots() self.assertQueued(1)
def test_regular(self): collectd.Connection().test.record(foo=5) collectd.take_snapshots() self.assertQueued(1)
def test_empty(self): conn = collectd.Connection() collectd.take_snapshots() self.assertQueued(0) conn.test self.assertQueued(0)
def setUp(self): self.conn = collectd.Connection()