Skip to content

Instantly share code, notes, and snippets.

View jcantrill's full-sized avatar

Jeff Cantrill jcantrill

View GitHub Profile
@portante
portante / are-shards-balanced.py
Last active September 13, 2019 03:10
A simple script to generate a report of Elasticsearch shard usage (from _cat/shards/?v&bytes=b) to see which shards of an index are not evenly spread across the cluster.
#!/usr/bin/env python2
# A script to generate a report of Elasticsearch shard usage
# (from _cat/shards?v&bytes=b) to see which shards of an index
# are not evenly spread across the cluster, and for a set of
# hard-coded date patterns, which date patterns are not spread
# evenly across the cluster.
#
# E.g.
# $ curl -X GET http://localhost:9200/_cat/shards?v\&bytes=b -o shards.lis
@jcantrill
jcantrill / images
Created September 5, 2018 18:17
get the images
#!/bin/bash
pod=$1
echo "DCs"
echo "----"
oc get dc -n logging -o yaml | grep image: | sort | uniq
echo "DSs"
echo "----"
oc get ds -n logging -o yaml | grep image: | sort | uniq
@jcantrill
jcantrill / fluent-logs
Created July 25, 2018 13:08
Get the logs of the fluent pods
#!/bin/bash
pod=${1:-}
if [ -z "${pod}" ]; then
pod=$(oc get pods -l component=fluentd -o jsonpath={.items[*].metadata.name})
fi
for p in ${pod}; do
echo ">>>>>>>><<<<<<<<<<<<<"
echo " ${p}"
echo ">>>>>>>><<<<<<<<<<<<<"
oc logs $p
@jcantrill
jcantrill / delete-index-patterns
Last active August 27, 2018 17:00
This script finds the old index patterns that match the 'project.*.*.*.*' and removes them from the .kibana index
#!/bin/bash -e
POD=$1
SIZE="${SIZE:-1000}"
index=".kibana"
oc exec -n logging -c elasticsearch $POD -- es_util --query="$index/index-pattern/_search?pretty&stored_fields=_id&size=$SIZE" | grep id | grep project\..* | cut -d ':' -f 2 | cut -d '"' -f 2 | paste -sd " " > patterns
echo '' > payload
for p in $(cat patterns); do
echo "{\"delete\":{\"_index\":\"${index}\", \"_type\":\"index-pattern\", \"_id\":\"$p\"}}"i # >> payload
done
cat payload
@jcantrill
jcantrill / check-fluent-connectivity-to-es
Last active July 25, 2018 13:00
This script checks the ability of the fluent pods to connect to Elasticsearch
#!/bin/sh
pods=${1:-"--all"}
shift
if [ "${pods}" == "--all" ]; then
pods=$(oc get pods -l component=fluentd -o jsonpath={.items[*].metadata.name})
fi
for p in $pods; do
output=$(oc exec $p -- curl --silent -q https://logging-es:9200/ --key /etc/fluent/keys/key --cacert /etc/fluent/keys/ca --cert /etc/fluent/keys/cert "$@")
@jcantrill
jcantrill / move-replica-shard
Created July 12, 2018 20:49
Move a specific shard from one node to another
#!/bin/bash -e
#
# Copyright 2017 Red Hat, Inc. and/or its affiliates
# and other contributors as indicated by the @author tags.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#!/bin/bash
POD=$1
enable=${2:-"all"} #or none
PERSIST=${PERSIST:-"transient"}
oc exec -n logging -c elasticsearch $POD -- es_util --query=_cluster/settings -XPUT -d "{\"${PERSIST}\":{\"cluster.routing.allocation.enable\":\"${enable}\"}}"
@jcantrill
jcantrill / allocate-shard
Created July 12, 2018 20:45
allocate a single shard
#!/bin/bash -e
#
# Copyright 2017 Red Hat, Inc. and/or its affiliates
# and other contributors as indicated by the @author tags.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@jcantrill
jcantrill / allocate-all-shards
Last active July 17, 2018 18:02
Allocate all non-assigned primary shards
#!/bin/bash
# This script allocates all primary shards that are unassigned to a a given node using
# the openshift binary. The binary must be in the path and the user executing the script
# must have access to logging project. The inputs are:
# pod An Elasticsearch pod name
# node An node Elasticsearch cluster which should be any one of the DC's. We could
# probably infer this from the pod name
pod=$1
node=$2
@jcantrill
jcantrill / unassigned
Last active July 24, 2018 20:28
Unassiged shards
#!/bin/bash
pod=$1
oc exec -c elasticsearch $pod -- es_util --query=_cat/shards?h=index,shard,prirep,state,unassigned.reason| grep UNASSIGNED