Skip to content

Commit

Permalink
Merge pull request #1521 from DataDog/leo/phpfpm
Browse files Browse the repository at this point in the history
[phpfpm] Use monotonic counts instead of counters
  • Loading branch information
LeoCavaille committed Apr 9, 2015
2 parents a694c2a + 09472ef commit e233fa2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
19 changes: 5 additions & 14 deletions checks.d/php_fpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ class PHPFPMCheck(AgentCheck):
'total processes': 'php_fpm.processes.total',
}

RATES = {
'max children reached': 'php_fpm.processes.max_reached'
}

COUNTERS = {
MONOTONIC_COUNTS = {
'accepted conn': 'php_fpm.requests.accepted',
'slow requests': 'php_fpm.requests.slow'
'max children reached': 'php_fpm.processes.max_reached',
'slow requests': 'php_fpm.requests.slow',
}

def check(self, instance):
Expand Down Expand Up @@ -86,17 +83,11 @@ def _process_status(self, status_url, auth, tags):
continue
self.gauge(mname, int(data[key]), tags=metric_tags)

for key, mname in self.RATES.iteritems():
if key not in data:
self.log.warn("Rate metric {0} is missing from FPM status".format(key))
continue
self.rate(mname, int(data[key]), tags=metric_tags)

for key, mname in self.COUNTERS.iteritems():
for key, mname in self.MONOTONIC_COUNTS.iteritems():
if key not in data:
self.log.warn("Counter metric {0} is missing from FPM status".format(key))
continue
self.increment(mname, int(data[key]), tags=metric_tags)
self.monotonic_count(mname, int(data[key]), tags=metric_tags)

# return pool, to tag the service check with it if we have one
return pool_name
Expand Down
5 changes: 1 addition & 4 deletions tests/test_php_fpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_status(self):
'tags': ['cluster:forums']
}

self.run_check({'instances': [instance]})
self.run_check_twice({'instances': [instance]})

metrics = [
'php_fpm.listen_queue.size',
Expand All @@ -83,8 +83,5 @@ def test_status(self):

self.assertServiceCheck('php_fpm.can_ping', status=AgentCheck.OK,
count=1)
time.sleep(1)

# Run check second time to get the rate
self.run_check({'instances': [instance]})
self.assertMetric('php_fpm.processes.max_reached', count=1)

0 comments on commit e233fa2

Please sign in to comment.