Skip to content

Instantly share code, notes, and snippets.

@hito-asa
hito-asa / how_to_print_jvm_oids.scala
Created February 14, 2011 11:31
How to print jvm oids
classOf[sun.management.snmp.jvmmib.JVM_MANAGEMENT_MIBOidTable].getDeclaredField("varList") match { case f:java.lang.reflect.Field => f.setAccessible(true); f.get(null).asInstanceOf[Array[com.sun.jmx.snmp.SnmpOidRecord]].foreach(s => println(s.getName + "\t" + s.getOid))}
#!/bin/sh
VERSION=0.11.0
URL=http://repo.typesafe.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/0.11.0/sbt-launch.jar
PWD=`cd .;pwd`
SCRIPT=${PWD}/sbt-${VERSION}
wget "$URL" -O ${PWD}/sbt-launch-${VERSION}.jar
echo "#!/bin/sh
JAR=${PWD}/sbt-launch-${VERSION}.jar
if [ -z \"\$JAVA_HOME\" ]; then
@hito-asa
hito-asa / out_kestrel.rb
Created November 3, 2011 17:57
fluent-plugin-kestrel
module Fluent
class KestrelOutput < BufferedOutput
Fluent::Plugin.register_output('kestrel', self)
attr_reader :hosts, :kestrel
def initialize
super
require 'msgpack'
require 'kestrel'
end
@hito-asa
hito-asa / agent_fluentd.conf
Created March 29, 2012 06:45
fluentd agent
<source>
type tail
path path_to_file1
pos_file path_to_pos_file1
tag app.file1
format /^(?<ip>[^ ]+) [^ ]+ [^ ]+ \[(?<time>[^\]]+)\] "(?<method>\S+) /(?<country>[A-Z0-9]{0,3})_(?<domain>[^/]+)/(?<module>[^/]+)/(?<controller>[^/]+)/(?<action>[^/]+)/(?<record>\S*)" (?<code>\d+) (?<res_time>\d+) "(?<referer>[^\"]*)" "(?<old_device>[^_\" ]*)_(?<device>[^_\" ]*)_(?<browser>[^_\" ]*) ?(?<guid>[^\"]*)" "(?<vuid>\d*) ?(?<option>[^\"]*)"$/
time_format %d/%b/%Y:%H:%M:%S %z
rotate_wait = 5s
</source>
class Fluent::SplitterOutput < Fluent::Output
Fluent::Plugin.register_output('splitter', self)
PATTERN_MAX_NUM = 20
(1..PATTERN_MAX_NUM).each do |i|
config_param ('pattern' + i.to_s).to_sym, :string, :default => nil
end
config_param :preserve_tag, :bool, :default => false
@hito-asa
hito-asa / tumblr_gist.css
Created September 3, 2012 07:50
tumblr_gist
<!-- Gist CSS -->
<style type="text/css" media="screen">
.gist{
margin: 15px 0 !important;
}
.gist-file{
border: none !important;
}
.gist-meta{
private[worker] case class QueueMonitor(processor: Processor) extends Actor with Logger {
private[this] val BLOCK_TIME = Some(1000L)
def act {
loop {
{
reactWithin(1000) {
case Take =>
// blocking dequeue
processor.queue.dequeue(BLOCK_TIME) map { message =>
@SuppressWarnings("unchecked")
public static <T> T get(Object key) throws IllegalArgumentException {
return (T) delegate().get(key);
}
private void fetchAndWriteLog(LogQuery query, String fileName) throws Exception {
FileService fs = FileServiceFactory.getFileService();
AppEngineFile file = null;
FileWriteChannel channel = null;
Writer writer = null;
try {
long start = System.currentTimeMillis();
file = fs.createNewGSFile(new GSFileOptionsBuilder()
.setBucket(GS_BUCKET_NAME)
oauth2_refresh_token = JSON.parse(`cat ~/.appcfg_oauth2_tokens`)["refresh_token"]
`#{$APPCFG} request_logs --oauth2 --noauth_local_webserver --oauth2_refresh_token=#{oauth2_refresh_token} --severity=1 --num_days=2 --end_date=#{TARGET_DATE_NAME} #{$SRC_DIR} #{LOG_TMP_DIR}/request.log`
`grep -s "^ [0-9]\\+:[0-9]\\+\\.[0-9]\\+ #{PREFIX_OF_ACTIVITY_LOG} \\(#{TARGET_DATE_PLUS1_NAME} 0[0-3]\\|#{TARGET_DATE_NAME} \\(0[4-9]\\|1[0-9]\\|2[0-3]\\)\\)" #{LOG_TMP_DIR}/request.log | sed "s/^ [0-9]\\+:[0-9]\\+\\.[0-9]\\+ #{PREFIX_OF_ACTIVITY_LOG} //" > #{LOG_FILE}`
GS_DIR = "gs://backetname/activity-log"
`#{$GSUTIL} cp #{LOG_FILE} #{GS_DIR}/#{TARGET_DATE_YMD}`