Skip to content

Commit

Permalink
Merge pull request #1276 from DataDog/leo/pg91bgw
Browse files Browse the repository at this point in the history
[postgres] Fix #1275. buffers_backend_fsync only avail post 9.1
  • Loading branch information
Remi Hakim committed Jan 13, 2015
2 parents a7c3423 + 1dff650 commit a500824
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions checks.d/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ class PostgreSql(AgentCheck):
'buffers_clean' : ('postgresql.bgwriter.buffers_clean', MONOTONIC),
'maxwritten_clean' : ('postgresql.bgwriter.maxwritten_clean', MONOTONIC),
'buffers_backend' : ('postgresql.bgwriter.buffers_backend', MONOTONIC),
'buffers_backend_fsync': ('postgresql.bgwriter.buffers_backend_fsync', MONOTONIC),
'buffers_alloc' : ('postgresql.bgwriter.buffers_alloc', MONOTONIC),
}

NEWER_91_BGW_METRICS = {
'buffers_backend_fsync': ('postgresql.bgwriter.buffers_backend_fsync', MONOTONIC),
}

NEWER_92_BGW_METRICS = {
'checkpoint_write_time': ('postgresql.bgwriter.write_time', MONOTONIC),
'checkpoint_sync_time' : ('postgresql.bgwriter.sync_time', MONOTONIC),
Expand Down Expand Up @@ -217,6 +220,9 @@ def _is_above(self, key, db, version_to_compare):

return False

def _is_9_1_or_above(self, key, db):
return self._is_above(key, db, [9,1,0])

def _is_9_2_or_above(self, key, db):
return self._is_above(key, db, [9,2,0])

Expand All @@ -243,10 +249,11 @@ def _get_bgw_metrics(self, key, db):
# Extended 9.2+ metrics if needed
metrics = self.bgw_metrics.get(key)
if metrics is None:
self.bgw_metrics[key] = dict(self.COMMON_BGW_METRICS)
if self._is_9_1_or_above(key, db):
self.bgw_metrics[key].update(self.NEWER_91_BGW_METRICS)
if self._is_9_2_or_above(key, db):
self.bgw_metrics[key] = dict(self.COMMON_BGW_METRICS, **self.NEWER_92_BGW_METRICS)
else:
self.bgw_metrics[key] = dict(self.COMMON_BGW_METRICS)
self.bgw_metrics[key].update(self.NEWER_92_BGW_METRICS)
metrics = self.bgw_metrics.get(key)
return metrics

Expand Down

0 comments on commit a500824

Please sign in to comment.