Skip to content

Instantly share code, notes, and snippets.

View slok's full-sized avatar
⚙️
Building reliable solutions

Xabier Larrakoetxea Gallego slok

⚙️
Building reliable solutions
View GitHub Profile
@slok
slok / amfirer.go
Last active November 11, 2021 06:10
Alertmanager alarm tester. Fire a custom alert to your alertmanager: https://github.com/prometheus/alertmanager
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"net/url"
#!/bin/bash
# Wait until consul instance on clust
INSTANCE_IP="127.0.0.1"
NEXT_WAIT_TIME=0
MAX_WAIT_TIME=35
check_consul_sync() {
# If we don't have leaders _last_log_index then get it
@slok
slok / mockserver.go
Created March 14, 2017 09:35
A simple HTTP server to mock responses
package main
import (
"flag"
"fmt"
"log"
"net/http"
)
func initFlags(addr *string, port *int, retCode *int, body *string) {
@slok
slok / trap.sh
Created September 15, 2016 16:23
onliner trap
trap 'echo captured;sleep 30;exit' SIGINT SIGTERM && while true; do sleep 1; done
@slok
slok / main.go
Created June 12, 2016 10:09
handler & handlerfunc golang pattern example
// Package main is an example of how handler pattern works in golang.
//
// At first you will need some sort of start point. To do this we create
// ExampleHandler interface, this interface has a trigger method that will
// execute the chain, in his case is RunExample, it accepts a writer, and a
// custom input object, as you see there is an out and an in parameter.
//
// We could work like this you can create multiple ExampleHandlers in a helper
// function and call them on in another. But this is not very handy and it smells
//
gvm install go1.6.2
gvm use go1.6.2 --default
gvm pkgset create slok
gvm pkgenv slok
# Add this lines
export GOPATH; GOPATH="/home/slok/projects/work/go:/home/slok/projects/personal/go:$GOPATH"
export PATH; PATH="/home/slok/projects/work/go/bin:/home/slok/projects/personal/go/bin:$PATH"
gvm pkgset use slok --default
@slok
slok / fabfile.py
Last active October 9, 2015 08:09
test
from fabric.api import *
@task
@runs_once
def deploy():
print(env)
print(env.get('fabric_bolt_deploy_id', 0))
print(env.get('deployer_email', "unknown"))
@slok
slok / run_docker_x11.sh
Created February 22, 2015 11:11
x11 with docker archlinux
KEY=$(xauth list |grep $(hostname) | awk '{ print $3 }' | head -n 1)
DCK_HOST=docker-skype
xauth add $DCK_HOST/unix:0 . $KEY
docker run -it --rm -v /tmp/.X11-unix:/tmp/.X11-unix \
-v $HOME/.Xauthority:/tmp/.Xauthority \
-v /dev/snd:/dev/snd \
-e DISPLAY=unix$DISPLAY \
-e XAUTHORITY=/tmp/.Xauthority \
-h $DCK_HOST \
@slok
slok / quantile.py
Last active August 29, 2015 14:14
quantile
import com.matttproud.quantile as quantile
with open('test_data.txt') as f:
data = list(map(float, f.readlines()))
#a = np.array(list(data))
#quantile = {
# '0.5': np.percentile(a, 0.05),
# '0.9': np.percentile(a, 0.09),
# '0.99': np.percentile(a, 0.99),
@slok
slok / prometheus.conf
Last active August 29, 2015 14:14
prometheus
global {
scrape_interval: "15s" # By default, scrape targets every 15 seconds.
evaluation_interval: "15s" # By default, evaluate rules every 15 seconds.
labels: {
label: {
name: "monitor"
value: "test-monitor"
}
}