Skip to content

Instantly share code, notes, and snippets.

Avatar

Hung whatvn

View GitHub Profile
@whatvn
whatvn / mfsmonitor.py
Created Feb 14, 2012
Nagios script for Moosefs monitoring
View mfsmonitor.py
#!/usr/bin/env python
# Nagios monitoring script for moosefs master server
# Based on mfscgiserv from moosefs author
# hungnv 13022012
import socket
import struct
import sys
@whatvn
whatvn / timeout.sh
Created Feb 24, 2012
kill a proc after timeout
View timeout.sh
#!/bin/bash
#
# The Bash shell script executes a command with a time-out.
# Upon time-out expiration SIGTERM (15) is sent to the process. If the signal
# is blocked, then the subsequent SIGKILL (9) terminates it.
#
# Based on the Bash documentation example.
# Hello Chet,
# please find attached a "little easier" :-) to comprehend
View zsparse.py
#!/usr/bin/env python
# hungnv
import csv
L0 = [ x[0] for x in csv.reader(open('ZS_SOURCE.csv','r')) ]
L1 = [ x[1] for x in csv.reader(open('ZS_SOURCE.csv','r')) ]
L2 = [ x[2] for x in csv.reader(open('ZS_SOURCE.csv','r')) ]
L3 = [ x[3] for x in csv.reader(open('ZS_SOURCE.csv','r')) ]
#FL = []
for i in xrange(len(L1)):
@whatvn
whatvn / heath_check.py
Created May 8, 2012
This is what I think my application will use to perform heathcheck for http server
View heath_check.py
def heart_check(target):
global last_check
if int(time() - last_check) > 5:
logger(ctime() + ": Perform heart check")
p = re.compile("[a-z0-9-.]*?\.[a-z0-9]+$")
domain_tld = p.findall(target)[0]
conn = HTTPConnection(domain_tld, timeout = 5)
try:
accepted_responses = (404, 302, 304, 301, 200)
conn.request('HEAD', '/')
@whatvn
whatvn / read_mfs_write_qfs.py
Created Nov 17, 2012
Read from MooseFS, write to QFS
View read_mfs_write_qfs.py
"""
- sequence read
- sequence write
"""
import os
import sys
import time
import errno
@whatvn
whatvn / read_mfs_write_qfs_multithread.py
Created Nov 17, 2012
Read from MooseFS, write to QFS using multithreading
View read_mfs_write_qfs_multithread.py
"""
- sequence read
- sequence write
"""
import os
import sys
import time
import errno
@whatvn
whatvn / Usage
Last active Aug 29, 2015
script based on rasterize.js (phantomjs) to take screenshot of a given website (not full page), code listed here I just copy from many website and combined into working one.
View Usage
export QTWEBKIT_PLUGIN_PATH=/usr/lib/browser-plugins:/usr/lib/flash-plugin:/usr/lib/mozilla/plugin:/usr/lib64/flash-plugin:/usr/lib64/mozilla/plugins:/usr/lib64/opera/plugins; export LIBXCB_ALLOW_SLOPPY_LOCK=1;xvfb-run --server-args="-screen 0, 1280x800x24" phantomjs --load-plugins=yes ambientscreenshot.js http://google.com /data/imgs/google.png
@whatvn
whatvn / cacti_memcache_multiport.xml
Created Aug 4, 2014
Cacti memcache template multiport
View cacti_memcache_multiport.xml
<cacti>
<hash_020016b09df6b35e243cb959f0fac2a1de48f2>
<name>Memcached Server - Multiport</name>
<graph_templates>hash_000016ddd8df13eea701e8e0515081995fcfd8|hash_0000169298c486308a406a19d77e68e367fd53|hash_000016540aaa04728046da9eb5fc3b17931aee|hash_0000168fc8202d6b446dfa6b9cab4ab8b6ff84|hash_0000166ea53ffa66406a3d46fcbb4cb85ce5ae|hash_000016fddba8d561e012a395cbf909deb4d1da</graph_templates>
<data_queries></data_queries>
</hash_020016b09df6b35e243cb959f0fac2a1de48f2>
<hash_000016ddd8df13eea701e8e0515081995fcfd8>
<name>Memcached - Bytes Used - Multiport</name>
<graph>
<t_title>on</t_title>
View crawler.java
public void process(String topic, ConsumerConnector consumer) {
Map<String, Integer> topicCountMap = new HashMap<>();
topicCountMap.put(topic, new Integer(1));
Map<String, List<KafkaStream<byte[], byte[]>>> consumerMap = consumer.createMessageStreams(topicCountMap);
KafkaStream<byte[], byte[]> stream = consumerMap.get(topic).get(0);
ConsumerIterator<byte[], byte[]> it = stream.iterator();
while (it.hasNext()) {
try {