Skip to content

Instantly share code, notes, and snippets.

import tornado.web
import tornado.ioloop
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write()
application = tornado.web.Application([
(r"/", MainHandler),
@Dnile
Dnile / okhttp.java
Created January 18, 2015 16:09
android http get with okhttp
String url = "http://api.openweathermap.org/data/2.5/weather?q=London,uk";
OkHttpClient client = new OkHttpClient();
try{
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
@Dnile
Dnile / connect_aws.py
Created February 12, 2015 19:52
just a boto ec2 conenction sequence abstracted
import boto.ec2
import os
access = os.environ['aws_access_key_id']
secret = os.environ['aws_secret_access_key']
conn = boto.ec2.connect_to_region(region, aws_access_key_id=access,
aws_secret_access_key=secret)
@Dnile
Dnile / scribe-ubuntu
Last active February 11, 2018 19:03
#!/bin/bash
echo "Install the necessary tools"
sudo apt-get update
sudo apt-get -y install make flex bison libtool libevent-dev automake pkg-config libssl-dev libboost-all-dev libbz2-dev build-essential g++ python-dev git
echo "git cloning Thrift"
apt-
import boto
ec2 = boto.connect_ec2()
res = ec2.get_all_instances()
instances = [i for r in res for i in r.instances]
vol = ec2.get_all_volumes()
def attachedvolumes():
print 'Attached Volume ID - Instance ID','-','Device Name'
for volumes in vol:
if volumes.attachment_state() == 'attached':
filter = {'block-device-mapping.volume-id':volumes.id}
import json
import click
import requests
def get_status(node):
es_stats = requests.get("http://%s:8080/_cluster/health?level=indices" % node)
indices = es_stats.json()['indices']
bad_indices = {k:v['status'] for k,v in indices.items() if 'green' not in v['status'] and 'nginx' in k}
for k,v in bad_indices.items():
@Dnile
Dnile / Dockerfile
Last active September 29, 2015 21:51
attempt to run promtheus locally
FROM sdurrheimer/alpine-glibc
MAINTAINER The Prometheus Authors <prometheus-developers@googlegroups.com>
WORKDIR /gopath/src/github.com/prometheus/prometheus
COPY . /gopath/src/github.com/prometheus/prometheus
RUN apk add --update -t build-deps tar openssl git make bash curl\
&& source ./scripts/goenv.sh /go /gopath \
&& make build \
&& cp prometheus promtool /bin/ \
FROM prom/prometheus
EXPOSE 9090
VOLUME [ "/prometheus" ]
WORKDIR /prometheus
ENTRYPOINT [ "/bin/prometheus" ]
CMD [ "-config.file=/etc/prometheus/prometheus.yml", \
"-storage.local.path=/prometheus", \
"-alertmanager.url=http://localhost:9093", \
"-web.console.libraries=/etc/prometheus/console_libraries", \
#host running out of memory!
ALERT HighMem
IF 100 -(node_memory_MemFree + node_memory_Buffers + node_memory_Cached) / node_memory_MemTotal* 100 > 80
FOR 1m
WITH {
severity="page"
}
SUMMARY "Instance {{$labels.host}} has high memory consumption"
DESCRIPTION "{{$labels.host}} of job {{$labels.job}} has less than 40% of memory available for more than 1 minutes."
# my global config
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
evaluation_interval: 15s # By default, scrape targets every 15 seconds.
# scrape_timeout is set to the global default (10s).
# Attach these extra labels to all timeseries collected by this Prometheus instance.
external_labels:
monitor: 'codelab-monitor'