Skip to content

Instantly share code, notes, and snippets.

@alq666
alq666 / getaddrinfo.strace
Created January 31, 2013 15:54
Tracing the relevant calls behind socket.getaddrinfo(...)
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("172.16.0.23")}, 16) = 0
gettimeofday({1359647342, 917639}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
sendto(3, "\314c\1\0\0\1\0\0\0\0\0\0\3app\tdatadoghq\3com\0\0"..., 35, MSG_NOSIGNAL, NULL, 0) = 35
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLIN}])
ioctl(3, FIONREAD, [146]) = 0
recvfrom(3, "\314c\201\200\0\1\0\1\0\1\0\0\3app\tdatadoghq\3com\0\0"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("172.16.0.23")}, [16]) = 146
close(3) = 0
stat("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=63, ...}) = 0
@alq666
alq666 / ddmonitor.diff
Created March 12, 2013 16:41
Allowing more generic monitor configuration
diff --git a/providers/ddmonitor.rb b/providers/ddmonitor.rb
index 1616a7a..70bee54 100644
--- a/providers/ddmonitor.rb
+++ b/providers/ddmonitor.rb
@@ -11,6 +11,7 @@ action :add do
owner "dd-agent"
mode 00400
notifies :restart, resources(:service => "datadog-agent")
+ variables :config => new_resource.config, :credentials => new_resource.credentials
end
@alq666
alq666 / graphs.md
Last active December 16, 2015 06:28

To get stacked metrics:

{
  "viz": "timeseries",
  "requests": [
    {
      "q": "8*sum:system.net.bytes_sent{host:flex02.lax04.netdna.com, device:eth2},8*sum:system.net.bytes_sent{host:flex02.lhr02.netdna.com, device:eth2}"
    }
 ],
@alq666
alq666 / desk.py
Created July 29, 2013 19:10
Simple python script to pull json out of desk (in this case, just cases)
import simplejson as json
import pycurl
# Run pip install pycurl before
url = "https://datadog.desk.com/api/v2/cases"
c = pycurl.Curl()
c.setopt(pycurl.URL, url)
c.setopt(pycurl.HTTPHEADER, ["Accept: application/json"])
@alq666
alq666 / gist:6282566
Last active December 21, 2015 09:08
Nested Loop (cost=6923.33..11770.59 rows=1 width=362) (actual time=17128.188..22109.283 rows=10858 loops=1)
Buffers: shared hit=83494
-> Bitmap Heap Scan on context c (cost=6923.33..11762.31 rows=1 width=329) (actual time=17128.121..22031.783 rows=10858 loops=1)
Recheck Cond: ((tags @> '{blah}'::text[]) AND (x_key = 1))
Filter: (key = ANY ('{15368196,(a lot more keys here)}'::integer[]))
Buffers: shared hit=50919
-> BitmapAnd (cost=6923.33..6923.33 rows=269 width=0) (actual time=132.910..132.910 rows=0 loops=1)
Buffers: shared hit=1342
-> Bitmap Index Scan on context_tags_idx (cost=0.00..1149.61 rows=15891 width=0) (actual time=64.614..64.614 rows=264777 loops=1)
Index Cond: (tags @> '{blah}'::text[])
SELECT c.key,
c.x_key,
c.tags,
x.name
FROM context c
JOIN x
ON c.x_key = x.key
WHERE c.key = ANY (ARRAY[15368196, -- 11,000 other keys --)])
AND c.x_key = 1
AND c.tags @> ARRAY[E'blah'];
SELECT c.key,
c.x_key,
c.tags,
x.name
FROM context c
JOIN x
ON c.x_key = x.key
WHERE c.key = ANY (VALUES (15368196), -- 11,000 other keys --)
AND c.x_key = 1
AND c.tags @> ARRAY[E'blah'];
Buffers: shared hit=83494
-> Bitmap Heap Scan on context c (cost=6923.33..11762.31 rows=1 width=329) (actual time=17128.121..22031.783 rows=10858 loops=1)
Recheck Cond: ((tags @> '{blah}'::text[]) AND (x_key = 1))
Filter: (key = ANY ('{15368196,(a lot more keys here)}'::integer[]))
Buffers: shared hit=50919
Nested Loop (cost=168.22..2116.29 rows=148 width=362) (actual time=22.134..256.531 rows=10858 loops=1)
Buffers: shared hit=44967
-> Index Scan using x_pkey on x (cost=0.00..8.27 rows=1 width=37) (actual time=0.071..0.073 rows=1 loops=1)
Index Cond: (id = 1)
Buffers: shared hit=4
-> Nested Loop (cost=168.22..2106.54 rows=148 width=329) (actual time=22.060..242.406 rows=10858 loops=1)
Buffers: shared hit=44963
-> HashAggregate (cost=168.22..170.22 rows=200 width=4) (actual time=21.529..32.820 rows=11215 loops=1)
-> Values Scan on "*VALUES*" (cost=0.00..140.19 rows=11215 width=4) (actual time=0.005..9.527 rows=11215 loops=1)
-> Index Scan using context_pkey on context c (cost=0.00..9.67 rows=1 width=329) (actual time=0.015..0.016 rows=1 loops=11215)
# Create the datadog user with select only permissions:
# CREATE USER datadog WITH PASSWORD '<complex_password>';
#
# Grant select permissions on a table or view that you want to monitor:
# GRANT SELECT ON <schema>.<table> TO datadog;
#
# Grant permissions for a specific column on a table or view that you want to monitor:
# GRANT SELECT (id, name) ON <schema>.<table> TO datadog;
#
# Let non-superusers look at pg_stat_activity in a read-only fashon.