Skip to content

Instantly share code, notes, and snippets.

View kszarek's full-sized avatar

Krzysztof Szarek kszarek

View GitHub Profile
@kszarek
kszarek / logstash.conf.erb
Created May 11, 2016 07:31
Logstash configuration for reading s3 buckets logs
input {
s3 {
access_key_id => "<%= @access_key_id %>"
secret_access_key => "<%= @secret_access_key %>"
bucket => "airhelp-logs-s3-<%= node.chef_environment %>"
region => "eu-west-1"
type => "s3"
interval => 20
codec => "plain"
sincedb_path => "<%= node['logstash-s3']['sincedb_path'] %>"
@kszarek
kszarek / elastic-clean-type.sh
Created August 23, 2016 21:42
Remove document type from ES index
#!/bin/bash
set -e
type=application
month=2016.02
for index in $(curl -s 'localhost:9200/_cat/shards'|grep $month|awk '{print $1}'|sort|uniq)
do
echo
echo "Cleaning $index"
echo
curl -XDELETE http://localhost:9200/${index}/${type}
@kszarek
kszarek / exec
Created October 13, 2017 09:47
Whisper / storage-schemas.conf changing retention time
find /var/lib/graphite/whisper/staging/ -type f -name '*.wsp' -exec /root/whisper-migrate {} \;
@kszarek
kszarek / main.go
Created October 25, 2017 14:02
Read TF comment
func readLines(path string) ([]string, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
var lines []string
scanner := bufio.NewScanner(file)
comment := false
@kszarek
kszarek / remove-es-node.sh
Created November 10, 2017 08:37
ElasticSearch: Removes all shards from given node's IP
#!/bin/bash
set -e
if [[ $# -ne 1 ]]
then
echo "Removes all shards from given node's IP."
echo
echo "$0 source_node_IP|NONE"
exit 1
fi
@kszarek
kszarek / es-shard-allocate.py
Created November 24, 2017 15:35
ElasticSeach: force to allocate a primary shard
#!/usr/bin/env python3
# script will force to allocate unassigned shards in the cluster
# based on: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/cluster-reroute.html
import urllib.request
import json
host = 'http://es-main-master2-gew2-staging'
destination_host = 'es-main-data2-gew2-staging'
shards_uri = ':9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason&format=json'
@kszarek
kszarek / graceful-shutdown-in-aws.tf
Created December 25, 2017 18:06
Terraform - graceful shutdown on AWS
resource "aws_sqs_queue" "graceful_termination_queue" {
name = "graceful_termination_queue"
}
resource "aws_iam_role" "autoscaling_role" {
name = "autoscaling_role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
@kszarek
kszarek / Dockerfile
Created November 8, 2018 16:53
Go application on docker scratch image
# This is the first stage, for building things that will be required by the
# final stage (notably the binary)
FROM golang
# Copy in just the go.mod and go.sum files, and download the dependencies. By
# doing this before copying in the other dependencies, the Docker build cache
# can skip these steps so long as neither of these two files change.
COPY go.mod go.sum ./
RUN go mod download
@kszarek
kszarek / aws-stats.sh
Last active June 19, 2019 15:18
Bash script to get ec2 and ebs count from multiple AWS accounts
#!/usr/bin/env bash
AWS_REGION=eu-west-1
envs='staging development dt-staging dt-production qa accounting team-bravo'
aws() {
docker run --rm -it \
--mount type=bind,source="$HOME"/.aws,destination=/root/.aws,readonly \
--mount type=bind,source="$(pwd)",destination=/data,consistency=cached \
-e AWS_PROFILE \
@kszarek
kszarek / gcp-stats.sh
Last active February 18, 2021 03:09
Bash script to get VM count and disk volume sizes from GCP projects
#!/usr/bin/env bash
envs='airhelp-staging airhelp-production ah-test-174206'
get_vm_count(){
ENV_NAME="$1"
count=$(gcloud --project="$ENV_NAME" compute instances list|grep -v NAME -c)
echo "VM count for $ENV_NAME: $count"
}