Skip to content

Instantly share code, notes, and snippets.

def get_load_avg():
load_avg = list (os.getloadavg())
return {#"1m": load_avg[0],
"5m": load_avg[1],
"15m":load_avg[2],
}
def get_disk_usage():
disk_usage = {}
@MauricioRoman
MauricioRoman / gist:d4f0ba7d424148246e61
Created October 24, 2015 12:47
Send Data to Skyline
def send_to_skyline(series, metric_set):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Datapoints are {metric:[ [timestamp,value],[timestamp,value]...]}
for record in series:
metric = "%s.%s" % (metric_set, record['metric'])
datapoint = [record['timestamp'],record['value']]
packet = msgpack.packb((metric, datapoint))
sock.sendto(packet, (socket.gethostname(), SKYLINE_UDP_PORT))
@MauricioRoman
MauricioRoman / gist:dc305d0cbaab929b86bd
Created October 24, 2015 12:44
regex to parse empty nginx logs
regex = "(?P<ipaddress>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(.+)(?P<dateandtime>\d{2}\/[a-zA-Z]{3}\/\d{4}:\d{2}:\d{2}:\d{2})(.+)(?P<statuscode>\d{3})"
#!/usr/bin/python
import requests, urllib2, simplejson, datetime, time
# Constants
MAX_RETRIES = 15 #Max number of retries when requesting data
TIMEOUT_RETURN = 100 #Timeout in calling API to retrieve results
DELAY = 0.5 #Delay per retry in seconds (increases * no_retries)
MAX_FIELDS = 300 #Max fields to retrieve from field request via API