Skip to content

Instantly share code, notes, and snippets.

@toddlers
toddlers / check_forkrate.sh
Created February 3, 2014 07:23
The process counter in /proc/stat . Normally you would only expect a fork rate of 1-10/sec on a production box with steady traffic.
#!/bin/bash
DATAFILE="/var/tmp/nagios_check_forkrate.dat"
VALID_INTERVAL=600
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=-1
@toddlers
toddlers / check_swap_paging_rate.sh
Created February 3, 2014 07:34
it’s actually the rate it’s swapped in/out that can impact performance, not the quantity
#!/bin/bash
# Show the rate of swapping (in number of pages) between executions
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=-1
EXITFLAG=$OK
WARN_THRESHOLD=1
@toddlers
toddlers / notify.sh
Created February 3, 2014 07:37
Notify when the system rebooted
#!/bin/bash
#
# *************************************************
# chkconfig: 2345 99 99
# description: notify email address on system boot.
# *************************************************
# Installing:
# 1) save as /etc/rc.d/init.d/notify
# 2) set the desired email address in "MAILADD" variable
# 3) chmod a+w /etc/rc.d/init.d/notify
#!/usr/bin/env bash
# call like this on the target server:
# NODENAME='foo' CHEF_ENV='production' RUNLIST='["role[foo]","recipe[bar]"]' CHEFREPO='git@example.com:repo.git' bash <( curl -L https://raw.github.com/gist/1026628 )
# You will need to ensure that the ssh key is already set up on the server.
set -e
export CHEF_DIR="${HOME}/chef"
sudo rm -rf $CHEF_DIR
mkdir -p "$CHEF_DIR"
@toddlers
toddlers / coredump.cfg
Created March 5, 2014 10:01
enable coredump in centos
Step 1.
Edit /etc/security/limits.conf
Step 2.
Notice this is set to all processes but if you have a process running as a service account replace the * with the service account.
Step 3.
Next, you will have to restart the process for this change to go into effect.
# vi /etc/security/limits.conf
#!/bin/bash
# herein we backup our indexes! this script should run at like 6pm or something, after logstash
# rotates to a new ES index and theres no new data coming in to the old one. we grab metadatas,
# compress the data files, create a restore script, and push it all up to S3.
TODAY=`date +"%Y.%m.%d"`
INDEXNAME="logstash-$TODAY" # this had better match the index name in ES
INDEXDIR="/usr/local/elasticsearch/data/logstash/nodes/0/indices/"
BACKUPCMD="/usr/local/backupTools/s3cmd --config=/usr/local/backupTools/s3cfg put"
BACKUPDIR="/mnt/es-backups/"
YEARMONTH=`date +"%Y-%m"`
@toddlers
toddlers / sort_string_list.py
Created June 24, 2014 07:53
sorting list of string on length basis
#!/usr/bin/env python
def lensort(list):
for index in range(1,len(list)):
currentValue = list[index]
position = index
while position > 0 and len(list[position - 1]) > len(currentValue):
list[position] = list[position - 1]
position = position -1
@toddlers
toddlers / reverse_file.py
Created June 25, 2014 09:53
reverse files lines
#!/usr/bin//env python
# reverse print the contents of a file
import sys
x = open(sys.argv[1]).readlines()
y = []
m = len(x) - 1
for i in range(len(x)):
print x[m]
m = m -1
@toddlers
toddlers / word_frequency.py
Last active August 29, 2015 14:03
counting word frequency in a file
#!/usr/bin/env python
# usage : word_frequency.py foo.txt
# will print the words frequency in random order
def word_frequency(words):
""" Returns frequency of each word given a list of words.
>>> word_frequency.py([a,b,a])
{'a': 2, 'b' : 1}
"""
@toddlers
toddlers / json_parsing.py
Created June 27, 2014 11:10
parsing json data in python
>>> content = urllib2.urlopen('http://httpbin.org/get').read()
>>> print content
{
"args": {},
"headers": {
"Accept-Encoding": "identity",
"Connection": "close",
"Host": "httpbin.org",
"User-Agent": "Python-urllib/2.7",
"X-Request-Id": "5a77cb68-7064-4997-afc1-4481f4bfa706"