Skip to content

Instantly share code, notes, and snippets.

View maatthc's full-sized avatar

Alexandre Andrade maatthc

  • MaaT Tech
  • Melbourne
View GitHub Profile
@maatthc
maatthc / datadog-nginx
Last active August 29, 2015 14:24 — forked from gane5h/datadog-nginx
"""
Custom parser for nginx log suitable for use by Datadog 'dogstreams'.
To use, add to datadog.conf as follows:
dogstreams: [path to ngnix log (e.g: "/var/log/nginx/access.log"]:[path to this python script (e.g "/usr/share/datadog/agent/dogstream/nginx.py")]:[name of parsing method of this file ("parse")]
so, an example line would be:
dogstreams: /var/log/nginx/access.log:/usr/share/datadog/agent/dogstream/nginx.py:parse
Log of nginx should be defined like that:
log_format time_log '$time_local "$request" S=$status $bytes_sent T=$request_time R=$http_x_forwarded_for';
when starting dd-agent, you can find the collector.log and check if the dogstream initialized successfully
"""
//
// Find out which process is accessing Memcached on localhost.
// It uses SystemTap : https://sourceware.org/systemtap
// You will need the kernel-debuginfo-common, kernel-headers and kernel-debuginfo
// Packages installed.
//
probe begin {
printf("%5s (%s) %15s %5s %15s %5s %s %s %s %s %s %s\n",
"PID", "CMD", "saddr", "SPORT", "daddr", "DPORT", "urg","ack","psh","rst","syn","fin")
}
@maatthc
maatthc / main.py
Created March 3, 2016 00:22
Testing on run time how many parameters a function is expecting.
from inspect import getargspec;
import sys
class Consumer(object):
def __init__(self, path, callback):
print("Creating class..")
self._path = path
self._callback = callback
@maatthc
maatthc / CC_SoftLayer.py
Created May 5, 2016 07:16
Helper to the SoftLayer API - Helps protectig the API Key
import getpass
from cryptography.fernet import Fernet
import sys
def get_credentials():
# SoftLayer Username/ Api Key encrypted
encrypted_credentials = b''
secret_key = getpass.getpass("Please enter your secret key: ")
@maatthc
maatthc / CC_Datadog.py
Created May 5, 2016 07:14
Helper for Datadog API
from datadog import initialize, api
import sys
def dd_init():
dd_options = {
'api_key': '',
'app_key': ''
}
initialize(**dd_options)
return api
@maatthc
maatthc / softlayer_cancel_servers.py
Last active May 6, 2016 03:54
It cancels Baremetal servers running at SoftLayer.It also power off the server and muted the monitoring at Datadog.
"""
Cancel the server with SoftLayer, turn it off and mute the Datadog alerts for it.
The host will be available until the next 16th day of the month.
"""
import SoftLayer
import sys
from CC_SoftLayer import get_credentials as sl_get_cred
from CC_Datadog import dd_init
@maatthc
maatthc / import_from_dd_to_nr.py
Last active May 23, 2016 01:34
Generate Server list for mRemote3G from Datadog mRemote3G : https://github.com/kmscode/mRemote3G Datadog: app.datadoghq.com
"""
Generate Server list for mRemote3G (former mRemoteNG) from Datadog Infrastructure List
mRemote3G : https://github.com/kmscode/mRemote3G
Datadog: app.datadoghq.com
Author: Alexandre Andrade
"""
import json
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
puts "The Mick "
puts "Gap Year "
puts "Stan Lees Lucky Man "
puts "The Worst Witch "
puts "The Middle "
puts "Master of None "
puts "Sense8 "
puts "Da Vincis Demons "
puts "Scorpion "
puts "Citizen Khan "
@maatthc
maatthc / topN.py
Last active June 16, 2017 10:25
Read numbers from a big file and present the N largest numbers
#!/usr/bin/python
from sys import argv
import multiprocessing as mp
import time
# Ajust for number of cpus/memory
# Each process will sort an array of size : ratio_per_process * size_array_largest
ratio_per_process = 30000
# Lets consolidate the Sort after some number of interations
num_interations = 50
@maatthc
maatthc / generate_big_file.py
Created June 16, 2017 10:28
Generates a file with one random number per line.
#!/usr/bin/env python
from sys import argv, exit
import random
big_file_name = "big_file.txt"
max_size_of_number = 1000000
random.seed(123)
if len(argv) != 2:
print "Usage: %s Num_Lines" % __file__