Skip to content

Commit

Permalink
More updates for the review
Browse files Browse the repository at this point in the history
  • Loading branch information
DorianZaccaria committed Mar 4, 2015
1 parent c99437b commit 39a0eb5
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 29 deletions.
10 changes: 5 additions & 5 deletions checks.d/pgbouncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, name, init_config, agentConfig, instances=None):
AgentCheck.__init__(self, name, init_config, agentConfig, instances)
self.dbs = {}

def _collect_stats(self, key, db, instance_tags):
def _collect_stats(self, db, instance_tags):
"""Query pgbouncer for various metrics
"""

Expand Down Expand Up @@ -130,7 +130,7 @@ def _get_connection(self, key, host, port, user, password, use_cached=True):
status = AgentCheck.CRITICAL
self.service_check('pgbouncer.can_connect', status, tags=service_check_tags)
self.log.debug('pgbouncer status: %s' % status)
raise
pass
else:
if not host:
raise CheckException("Please specify a PgBouncer host to connect to.")
Expand All @@ -149,7 +149,7 @@ def check(self, instance):
password = instance.get('password', '')
tags = instance.get('tags', [])

key = '%s:%s:%s' % (host, port, self.DB_NAME)
key = '%s:%s' % (host, port)

if tags is None:
tags = []
Expand All @@ -158,8 +158,8 @@ def check(self, instance):

try:
db = self._get_connection(key, host, port, user, password)
self._collect_stats(key, db, tags)
self._collect_stats(db, tags)
except ShouldRestartException:
self.log.info("Resetting the connection")
db = self._get_connection(key, host, port, user, password, use_cached=False)
self._collect_stats(key, db, tags)
self._collect_stats(db, tags)
3 changes: 0 additions & 3 deletions ci/pgbouncer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ def pgb_rootdir
#{pgb_rootdir}/pgbouncer.ini)
sh %(cp $TRAVIS_BUILD_DIR/ci/resources/pgbouncer/users.txt\
#{pgb_rootdir}/users.txt)
sh %(cp $TRAVIS_BUILD_DIR/ci/resources/pgbouncer/pgbouncer_stimulus.sh\
#{pgb_rootdir}/pgbouncer_stimulus.sh)
sh %(chmod +x #{pgb_rootdir}/pgbouncer_stimulus.sh)
sh %(#{pgb_rootdir}/pgbouncer -d #{pgb_rootdir}/pgbouncer.ini)
sleep_for 3
sh %(PGPASSWORD=datadog #{pg_rootdir}/bin/psql\
Expand Down
4 changes: 0 additions & 4 deletions ci/resources/pgbouncer/pgbouncer_stimulus.sh

This file was deleted.

2 changes: 1 addition & 1 deletion ci/sysstat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def sysstat_rootdir
unless Dir.exist? File.expand_path(sysstat_rootdir)
sh %(curl -s -L\
-o $VOLATILE_DIR/sysstat-#{sysstat_version}.tar.xz\
http://perso.orange.fr/sebastien.godard/sysstat-11.0.1.tar.xz)
https://s3.amazonaws.com/travis-archive/sysstat-11.0.1.tar.xz)
sh %(mkdir -p $VOLATILE_DIR/sysstat)
sh %(mkdir -p #{sysstat_rootdir})
sh %(mkdir -p #{sysstat_rootdir}/var/log/sa)
Expand Down
14 changes: 7 additions & 7 deletions conf.d/pgbouncer.yaml.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
init_config:

instances:
# - host: localhost
# port: 15433
# username: my_username
# password: my_password
# tags:
# - optional_tag1
# - optional_tag2
# - host: localhost
# port: 15433
# username: my_username
# password: my_password
# tags:
# - optional_tag1
# - optional_tag2
1 change: 1 addition & 0 deletions source-optional-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
kazoo==1.3.1
pycurl==7.19.5
psutil==2.1.1
psycopg2==2.6
pymongo==2.6.3
pysnmp-mibs==0.1.4
pysnmp==4.2.5
1 change: 0 additions & 1 deletion source-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ httplib2==0.9
kafka-python==0.9.0-9bed11db98387c0d9e456528130b330631dc50af
ntplib==0.3.2
pg8000==1.9.6
psycopg2==2.6
PyMySQL==0.6.1
python-memcached==1.53
pyyaml==3.11
Expand Down
20 changes: 12 additions & 8 deletions tests/test_pgbouncer.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import unittest
import subprocess
from tests.common import load_check

from nose.plugins.attrib import attr
from tests.common import load_check, AgentCheckTest

import time
import psycopg2 as pg
from pprint import pprint
from nose.plugins.attrib import attr

@attr(requires='pgbouncer')
class TestPgbouncer(unittest.TestCase):
class TestPgbouncer(AgentCheckTest):
CHECK_NAME = 'pgbouncer'

def test_checks(self):

config = {
'instances': [
{
Expand Down Expand Up @@ -45,7 +43,13 @@ def test_checks(self):
self.assertTrue(len([m for m in metrics if m[0] == u'pgbouncer.stats.avg_sent']) >= 1, pprint(metrics))
self.assertTrue(len([m for m in metrics if m[0] == u'pgbouncer.stats.avg_query']) >= 1, pprint(metrics))
# Rate metrics, need 2 collection rounds
subprocess.call(['embedded/pgbouncer/pgbouncer_stimulus.sh'])
try:
connection = pg.connect(host='localhost', port='15433', user='datadog', password='datadog', database='datadog_test')
connection.set_isolation_level(pg.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
cur = connection.cursor()
cur.execute('SELECT * FROM persons;')
except Exception:
pass
time.sleep(5)
self.check.run()
metrics = self.check.get_metrics()
Expand Down

0 comments on commit 39a0eb5

Please sign in to comment.