Skip to content

Instantly share code, notes, and snippets.

View koemu's full-sized avatar

Yuichiro SAITO koemu

View GitHub Profile
@koemu
koemu / parseStatusDat.py
Created May 10, 2013 09:16
Nagios status.dat parser for python.
# -*- coding: utf-8 -*-
import sys
import re
# ----------------------------------------------
def parseFile( path, result ):
"""
@koemu
koemu / http_client.py
Created December 13, 2013 18:31
TENTO 2013-12-14 講義資料
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 簡易HTTPクライアント
# required: Python 2.6 or later
# urllibを使っていますが、これはパッケージインストールの手間を省くためです。
import urllib
URI = "http://www.koemu.com:8888/"
@koemu
koemu / getswap.sh
Created December 18, 2013 01:09
各プロセスのスワップ使用量を調べる。 なお、root or sudo での実行が必要。 参照元: http://northernmost.org/blog/find-out-what-is-using-your-swap/
#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
# Updated: 2013-11-13 Yuichiro Saito
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
PID=`echo $DIR | cut -d / -f 3`
PROGNAME=`ps -p $PID -o comm --no-headers`
for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
@koemu
koemu / ksm_metrics.sh
Created July 23, 2014 05:52
Get ksm metrics for Mackerel
#!/bin/bash
DATE=$(date +%s)
echo -e "ksm.pages_volatile\t$(cat /sys/kernel/mm/ksm/pages_volatile)\t${DATE}"
echo -e "ksm.pages_shared\t$(cat /sys/kernel/mm/ksm/pages_shared)\t${DATE}"
echo -e "ksm.pages_sharing\t$(cat /sys/kernel/mm/ksm/pages_sharing)\t${DATE}"
echo -e "ksm.pages_unshared\t$(cat /sys/kernel/mm/ksm/pages_unshared)\t${DATE}"
@koemu
koemu / kvm_guest_virttop.py
Created July 24, 2014 05:26
Get KVM guest CPU Usage for Mackerel
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import commands
import datetime
unix_time = datetime.datetime.today().strftime('%s')
retval = commands.getstatusoutput( "virt-top -b --stream -n 2 -d 1" )
@koemu
koemu / kvm_guest_dominfo.py
Created July 24, 2014 05:29
Get KVM guest information for Mackerel
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import commands
import datetime
argv = sys.argv
if len( argv ) < 2:
print "usage " + sys.argv[0] + " info_name"
@koemu
koemu / kvm_guest_state_metrics.sh
Created July 24, 2014 05:32
Get running KVM guests for Mackerel
#!/bin/bash
DATE=$(date +%s)
echo -e "kvm.guest.state.running\t$(virsh list --uuid | sed '/^$/d' | wc -l)\t${DATE}"
echo -e "kvm.guest.state.inactive\t$(virsh list --inactive --uuid | sed '/^$/d'| wc -l)\t${DATE}"
@koemu
koemu / cacti_xml_hash_convert.py
Created July 31, 2014 10:19
Replace hash value for Cacti template xml file.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import sys
import hashlib
source = open( sys.argv[1] ).read()
result = re.finditer( r'hash\_([0-9]{6})(\w{32})', source )
@koemu
koemu / mackerel-agent.conf
Last active February 13, 2016 05:50
Get Raspberry pi temperature for Mackerel
# Please append this lines to your config file.
[plugin.metrics.raspberrypi_env_temp]
command = "/usr/local/bin/raspberrypi_env_temp.py"
type = "metric"
@koemu
koemu / yapc_asia_tokyo_2015_memo.md
Last active August 29, 2015 14:27
YAPC::Asia Tokyo 2015 メモ