Skip to content

Instantly share code, notes, and snippets.

View portante's full-sized avatar

Peter Portante portante

View GitHub Profile
@portante
portante / get-curr-logs
Created May 12, 2017 19:55
Simple bash script to get the logs of all the logging component pods with timestamps
#!/bin/bash
function fetchlogs {
if [ $1 = "kibana" ]; then
_container="-c kibana"
else
_container=""
fi
for i in $(oc get pods --output=name -l component=$1 | sed 's|pod/||') ; do oc logs $i $_container > $i.$2.log ; done
}
@portante
portante / check_kibana_access_by_token.bash
Last active May 10, 2017 15:07
A simple script to verify Kibana can access ES on behalf of a user
#!/bin/bash
_BASE=/etc/kibana/keys
_CA=$_BASE/ca
_CERT=$_BASE/cert
_KEY=$_BASE/key
ls -l $_CA $_CERT $_KEY
_USER=foo
_TOKEN=bar
@portante
portante / check_es_state.sh
Last active September 14, 2017 03:11
A simple script to check the state of Elasticsearch from within an ES pod in an OpenShift cluster
#!/bin/bash
ES_URL='https://localhost:9200'
curl_get='curl -s -X GET --cacert /etc/elasticsearch/secret/admin-ca --cert /etc/elasticsearch/secret/admin-cert --key /etc/elasticsearch/secret/admin-key'
date
$curl_get $ES_URL/_cat/health?v
$curl_get $ES_URL/_cat/nodes?v
$curl_get $ES_URL/_cat/indices?v 2>&1 | grep -vE "^green"
$curl_get $ES_URL/_cat/indices?v 2>&1 | grep "searchguard"
@portante
portante / check_kibana_access.bash
Last active May 10, 2017 13:32
A simple script to check if Kibana has access from within a kibana pod/container for OpenShift.
#!/bin/bash
_BASE=/etc/kibana/keys
_CA=$_BASE/ca
_CERT=$_BASE/cert
_KEY=$_BASE/key
ls -l $_CA $_CERT $_KEY
ES_URL='https://logging-es:9200'
curl_get="curl -X GET --cacert $_CA --cert $_CERT --key $_KEY"
#!/usr/bin/env python
# Use via: curl -X GET http://localhost:9200/_cluster/health?level=indices
import sys, json
#json_doc = json.load(open(sys.argv[1]))
json_doc = json.load(sys.stdin)
#json.dump(json_doc, sys.stdout, indent=4, sort_keys=True)
@portante
portante / dump_index_shards_and_replica_counts.py
Last active April 13, 2017 19:31
Simple python script to process stdin from include settings API to dump number of primary shards and replica counts.
#!/usr/bin/env python
# Use via: curl -X GET http://localhost:9200/_all/_settings?pretty
import sys, json
#json_doc = json.load(open(sys.argv[1]))
json_doc = json.load(sys.stdin)
#json.dump(json_doc, sys.stdout, indent=4, sort_keys=True)
@portante
portante / merge-kibana-logs
Created April 10, 2017 15:54
Simple python script to merge logs from kibana
#!/usr/bin/env python
import os, sys, json
lines = []
for fn in sys.argv[1:]:
with open(fn, "r") as fp:
line_count = 0
for line in fp.readlines():
line_doc = json.loads(line)
@portante
portante / format-es-logs
Last active January 11, 2018 14:11
Hacky set of python and bash scripts to format output of ES _search query output using the "scroll" API (see https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-request-scroll.html)
#!/usr/bin/env python
# Use via: curl -X GET http://localhost:9200/<index>/_search/?fields=@timestamp,level,hostname,kubernetes.host,kubernetes.pod_name,kubernetes.container_name,message&q=message:<string>
import sys, os, json
if len(sys.argv) == 1 or sys.argv[1] == '-':
json_doc = json.load(sys.stdin)
else:
json_doc = json.load(open(sys.argv[1]))
@portante
portante / thoughts.txt
Created April 4, 2017 22:13
Thoughts About Logging Trade-offs
> We certainly don't want to log all that with every message. Given that
> UUID is UU, can't that be squirreled away in a lookup table somewhere else
> out of the fast path?
Unfortunately, it seems we have a clash of two valid concerns with logging:
1. efficiency: How do emit logs efficiently such that the process of emitting, collecting, and shipping them off does not over-burden the environment making it unusable
1. utility: How do we include sufficient metadata surrounding the logs so that they are useful when a entity consumes them
These are age-old trade-offs that we are discussing.
@portante
portante / example-sg-seeding.java
Created March 20, 2017 19:07
An example code flow for seeding
seeded_state = UNSEEDED;
lock = Lock();
syncing = Sync();
process() {
if (seeded_state == SEEDED) {
continue;
} else {
lock.lock();
try {