Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add postgres custom metrics #78

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions files/puppet_last_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from checks import AgentCheck
from time import time
import yaml #requires PyYAML

class puppetCheck(AgentCheck):
def check(self, instance):
with open("/var/lib/puppet/state/last_run_summary.yaml", "r") as summary:
file_data = yaml.load(summary)
date = file_data["time"]["last_run"]
failures = file_data["events"]["failure"]
age_seconds = time() - date

version = file_data["version"]["puppet"]
tag = "puppet_version:" + version

self.gauge("puppet.last_run_age_seconds",age_seconds,tags=[tag])
self.gauge("puppet.last_run_num_failures",failures,tags=[tag])
9 changes: 8 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@
require => Package['datadog-agent'],
}

file {['/etc/dd-agent/conf.d/', '/etc/dd-agent/checks.d/']:
ensure => directory,
owner => 'dd-agent'
}

#for puppet run success reporting to datadog.
include datadog_agent::puppet_last_run

# main agent config file
file { '/etc/dd-agent/datadog.conf':
ensure => file,
Expand All @@ -135,5 +143,4 @@
puppetmaster_user => $puppetmaster_user,
}
}

}
8 changes: 7 additions & 1 deletion manifests/integrations/postgres.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
# Track per relation/table metrics. Array of strings.
# Warning: this can collect lots of metrics per relation
# (10 + 10 per index)
# $custom_metrics
# Track metrics from custom queries
# See https://github.com/ipolishchuk/dd-agent/blob/master/conf.d/postgres.yaml.example
# for more details
#
# Sample Usage:
#
Expand All @@ -35,11 +39,13 @@
$username = 'datadog',
$password,
$tags = [],
$tables = []
$tables = [],
$custom_metrics = []
) inherits datadog_agent::params {

validate_array($tags)
validate_array($tables)
validate_array($custom_metrics)

file { "${datadog_agent::params::conf_dir}/postgres.yaml":
ensure => file,
Expand Down
14 changes: 14 additions & 0 deletions manifests/puppet_last_run.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class datadog_agent::puppet_last_run {
file { '/etc/dd-agent/checks.d/puppet_last_run.py':
ensure => file,
owner => 'dd-agent',
source => 'puppet:///modules/datadog_agent/puppet_last_run.py',
notify => Service['datadog-agent'],
} ->
file { '/etc/dd-agent/conf.d/puppet_last_run.yaml':
ensure => file,
content => template('datadog_agent/puppet_last_run.yaml.erb'),
owner => 'dd-agent',
notify => Service['datadog-agent'],
}
}
43 changes: 43 additions & 0 deletions templates/agent-conf.d/postgres.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,46 @@ instances:
<%- end -%>
<%- end -%>
<% end -%>

# Custom metrics
# Below are some examples of commonly used metrics, which are implemented as custom metrics.
# Uncomment them if you want to use them as is, or use as an example for creating your own custom metrics.
# The format for describing custome metrics is identical with the one used for common metrics in postgres.py
# Be extra careful with ensuring proper custom metrics description format. If your custom metric does not work
# after an agent restart, look for errors in the otput of "/etc/init.d/datadog-agent info" command, as well as
# /var/log/datadog/collector.log file.
#
# custom_metrics:
# - # Londiste 3 replication lag
# descriptors:
# - [consumer_name, consumer_name]
# metrics:
# GREATEST(0, EXTRACT(EPOCH FROM lag)) as lag: [postgresql.londiste_lag, GAUGE]
# GREATEST(0, EXTRACT(EPOCH FROM last_seen)) as last_seen: [postgresql.londiste_last_seen, GAUGE]
# pending_events: [postgresql.londiste_pending_events, GAUGE]
# query: SELECT as consumer_name, %s from pgq.get_consumer_info() where consumer_name !~ 'watermark$';
# relation: false

<% if @custom_metrics and ! Array(@custom_metrics).empty? %>
custom_metrics:
<% if Array(@custom_metrics).include?('londiste3_replication') %>
- # Londiste 3 replication lag
descriptors:
- [consumer_name, consumer_name]
metrics:
GREATEST(0, EXTRACT(EPOCH FROM lag)) as lag: [postgresql.londiste_lag, GAUGE]
GREATEST(0, EXTRACT(EPOCH FROM last_seen )) as last_seen: [postgresql.londiste_last_seen, GAUGE]
pending_events: [postgresql.londiste_pending_events, GAUGE]
query: SELECT consumer_name, %s from pgq.get_consumer_info() where consumer_name !~ 'watermark$';
relation: false
<% end -%>
<% if Array(@custom_metrics).include?('tx_duration_92') %>
- # Max transaction and query duration for postgresql v9.2+
descriptors: []
metrics:
GREATEST(0, EXTRACT(EPOCH FROM max(now()-xact_start))) as max_tx_duration: [postgresql.max_tx_duration, GAUGE]
GREATEST(0, EXTRACT(EPOCH FROM max(case when state = 'active' then now() - query_start else interval '0 s' end))) as max_query_duration: [postgresql.max_query_duration, GAUGE]
query: SELECT %s from pg_stat_activity where state != 'idle';
relation: false
<% end -%>
<% end -%>
4 changes: 4 additions & 0 deletions templates/puppet_last_run.yaml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
init_config:

instances:
- name: puppet_last_run_metric