Skip to content

Instantly share code, notes, and snippets.

@qrtt1
Last active October 1, 2015 18:18
Show Gist options
  • Save qrtt1/2036572 to your computer and use it in GitHub Desktop.
Save qrtt1/2036572 to your computer and use it in GitHub Desktop.
misc & blogger
public class EatMemory
{
public static void main (String[] args) throws Exception
{
java.util.Vector v = new java.util.Vector();
int count = 1024;
while(count-->0)
{
v.add(new byte[1024 * 1024]);
}
System.out.println(new java.util.Date());
while(true)
{
Thread.sleep(5000);
}
}
}
from boto.ec2.connection import EC2Connection
import sys
if __name__ == "__main__":
conn = EC2Connection('your_id', 'your_secret')
rsv = conn.get_all_instances()
instances = []
current = None
for r in rsv:
instances += r.instances
for i in instances:
if i.id == sys.argv[1]:
if i.tags.has_key("handleClass"):
print i.tags["handleClass"]
else:
print "__unknown__:%s" % i.id
import urllib2
import boto.ec2
def get_instance_id():
return urllib2.urlopen('http://169.254.169.254/latest/meta-data/instance-id', '', 5).read()
def bind_address(key, secret, region, ip):
c = boto.ec2.connect_to_region(region, aws_access_key_id=key, aws_secret_access_key=secret)
id = get_instance_id()
for addr in c.get_all_addresses():
print addr.public_ip
print "my id:", id
c.associate_address(id, ip)
if __name__ == "__main__":
import sys
key, secret, region, ip = sys.argv[1:]
bind_address(key, secret, region, ip)
"main" prio=5 tid=7fef4a001800 nid=0x107916000 runnable [107910000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:166)
at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:90)
at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:281)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:92)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:62)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:712)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:517)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.apache.http.impl.client.DecompressingHttpClient.execute(DecompressingHttpClient.java:137)
at org.apache.http.impl.client.DecompressingHttpClient.execute(DecompressingHttpClient.java:118)
at org.gradle.api.internal.externalresource.transport.http.HttpClientHelper.performHttpRequest(HttpClientHelper.java:111)
at org.gradle.api.internal.externalresource.transport.http.HttpClientHelper.executeGetOrHead(HttpClientHelper.java:87)
at org.gradle.api.internal.externalresource.transport.http.HttpClientHelper.performRequest(HttpClientHelper.java:78)
at org.gradle.api.internal.externalresource.transport.http.HttpClientHelper.performRawHead(HttpClientHelper.java:58)
at org.gradle.api.internal.externalresource.transport.http.HttpClientHelper.performHead(HttpClientHelper.java:62)
at org.gradle.api.internal.externalresource.transport.http.HttpResourceAccessor.getMetaData(HttpResourceAccessor.java:65)
at org.gradle.api.internal.externalresource.transfer.ProgressLoggingExternalResourceAccessor.getMetaData(ProgressLoggingExternalResourceAccessor.java:53)
at org.gradle.api.internal.externalresource.transfer.DefaultCacheAwareExternalResourceAccessor.getResource(DefaultCacheAwareExternalResourceAccessor.java:69)
at org.gradle.api.internal.externalresource.transport.DefaultExternalResourceRepository.getResource(DefaultExternalResourceRepository.java:65)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.getResource(ExternalResourceResolver.java:427)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.findStaticResourceUsingPatterns(ExternalResourceResolver.java:307)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.getArtifactRef(ExternalResourceResolver.java:298)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.download(ExternalResourceResolver.java:415)
at org.gradle.api.internal.artifacts.repositories.resolver.MavenResolver.download(MavenResolver.java:116)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.resolve(ExternalResourceResolver.java:397)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CacheLockingModuleVersionRepository$2.run(CacheLockingModuleVersionRepository.java:54)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:237)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:308)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:114)
at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.longRunningOperation(DefaultCacheFactory.java:185)
at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.longRunningOperation(DefaultCacheLockingManager.java:57)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CacheLockingModuleVersionRepository.resolve(CacheLockingModuleVersionRepository.java:52)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleVersionRepository.resolve(CachingModuleVersionRepository.java:192)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.memcache.CachedRepository.resolve(CachedRepository.java:63)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.UserResolverChain$ModuleVersionRepositoryArtifactResolverAdapter.resolve(UserResolverChain.java:163)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.LazyDependencyToModuleResolver$ErrorHandlingArtifactResolver.resolve(LazyDependencyToModuleResolver.java:62)
at org.gradle.api.internal.artifacts.ivyservice.ResolvedArtifactFactory$1$1$1.transform(ResolvedArtifactFactory.java:43)
at org.gradle.api.internal.artifacts.ivyservice.ResolvedArtifactFactory$1$1$1.transform(ResolvedArtifactFactory.java:40)
at org.gradle.api.internal.artifacts.ivyservice.DefaultIvyContextManager.withIvy(DefaultIvyContextManager.java:61)
at org.gradle.api.internal.artifacts.ivyservice.ResolvedArtifactFactory$1$1.create(ResolvedArtifactFactory.java:40)
at org.gradle.api.internal.artifacts.ivyservice.ResolvedArtifactFactory$1$1.create(ResolvedArtifactFactory.java:38)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:187)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:102)
at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.useCache(DefaultCacheFactory.java:189)
at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.useCache(DefaultCacheLockingManager.java:61)
at org.gradle.api.internal.artifacts.ivyservice.ResolvedArtifactFactory$1.create(ResolvedArtifactFactory.java:38)
at org.gradle.api.internal.artifacts.ivyservice.ResolvedArtifactFactory$1.create(ResolvedArtifactFactory.java:36)
at org.gradle.api.internal.artifacts.DefaultResolvedArtifact.getFile(DefaultResolvedArtifact.java:106)
at org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$1$1.isSatisfiedBy(DefaultLenientConfiguration.java:96)
at org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$1$1.isSatisfiedBy(DefaultLenientConfiguration.java:93)
at org.gradle.util.CollectionUtils.filter(CollectionUtils.java:86)
at org.gradle.util.CollectionUtils.filter(CollectionUtils.java:59)
at org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$1.create(DefaultLenientConfiguration.java:93)
at org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$1.create(DefaultLenientConfiguration.java:91)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:187)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:102)
at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.useCache(DefaultCacheFactory.java:189)
at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.useCache(DefaultCacheLockingManager.java:61)
at org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration.getArtifacts(DefaultLenientConfiguration.java:91)
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver$ErrorHandlingLenientConfiguration.getArtifacts(ErrorHandlingArtifactDependencyResolver.java:71)
at org.gradle.plugins.ide.internal.resolver.DefaultIdeDependencyResolver.getExternalArtifacts(DefaultIdeDependencyResolver.java:282)
at org.gradle.plugins.ide.internal.resolver.DefaultIdeDependencyResolver.getIdeRepoFileDependencies(DefaultIdeDependencyResolver.java:152)
at org.gradle.plugins.ide.internal.resolver.IdeDependencyResolver$getIdeRepoFileDependencies.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.gradle.plugins.ide.internal.IdeDependenciesExtractor.resolvedExternalDependencies(IdeDependenciesExtractor.groovy:111)
at org.gradle.plugins.ide.internal.IdeDependenciesExtractor$resolvedExternalDependencies.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145)
at org.gradle.plugins.ide.internal.IdeDependenciesExtractor.extractRepoFileDependencies(IdeDependenciesExtractor.groovy:57)
at org.gradle.plugins.ide.internal.IdeDependenciesExtractor$extractRepoFileDependencies.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.gradle.plugins.ide.eclipse.model.internal.ClasspathFactory$4.update(ClasspathFactory.groovy:52)
at org.gradle.plugins.ide.eclipse.model.internal.ClasspathEntryBuilder$update.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at org.gradle.plugins.ide.eclipse.model.internal.ClasspathFactory.createEntries(ClasspathFactory.groovy:79)
at org.gradle.plugins.ide.eclipse.model.internal.ClasspathFactory$createEntries.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.gradle.plugins.ide.eclipse.model.EclipseClasspath.resolveDependencies(EclipseClasspath.groovy:209)
at org.gradle.plugins.ide.eclipse.model.EclipseClasspath.mergeXmlClasspath(EclipseClasspath.groovy:216)
at org.gradle.plugins.ide.eclipse.model.EclipseClasspath$mergeXmlClasspath.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.gradle.plugins.ide.eclipse.GenerateEclipseClasspath.configure(GenerateEclipseClasspath.groovy:43)
at org.gradle.plugins.ide.eclipse.GenerateEclipseClasspath.configure(GenerateEclipseClasspath.groovy)
at org.gradle.plugins.ide.api.XmlGeneratorTask$1.configure(XmlGeneratorTask.java:37)
at org.gradle.plugins.ide.api.XmlGeneratorTask$1.configure(XmlGeneratorTask.java:31)
at org.gradle.plugins.ide.api.GeneratorTask.generate(GeneratorTask.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:219)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:533)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:516)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:289)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:46)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.Main.main(Main.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Locked ownable synchronizers:
- None
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/myapp</Set>
<Set name="war">/root/webapps/myapp</Set>
<!--
set defaults descriptor is very important
-->
<Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
</Configure>
import re, sre_constants
import sys, os, os.path
if __name__ == "__main__":
BASE = '/proc'
STATUS_TEMPLATE = '/proc/%s/status'
if len(sys.argv) > 1:
FILTER = sys.argv[1]
else:
FILTER = '.*'
try:
PATTERN = re.compile(FILTER)
except sre_constants.error:
print
print "filter parsing error => ", FILTER
print "it should be a valid regex in Python"
print
sys.exit(1)
SUM = 0
for pid in os.listdir(BASE):
status = STATUS_TEMPLATE % pid
# parse /proc/$$/status if it exists
if not os.path.exists(status):
continue
file = open(status, "r")
entry = {}
for line in file.readlines():
try:
k, v = line.split(':')
entry[ k.lower() ] = v.lower().replace('kb', '').strip()
except ValueError:
pass
file.close()
# filter process name
try:
if PATTERN.search(entry['name']) is None:
continue
data = [entry['pid'], entry['name'], entry['vmrss']]
SUM += int(entry['vmrss'])
print ",".join([ r'''"%s"''' % x for x in data])
except ValueError:
pass
except KeyError:
pass
print ",".join([ r'''"%s"''' % x for x in ["0", "__SUM__", SUM]])
import re
QUERY_TIME_PATTERN=re.compile(".*Query_time: (\d+) Lock_time: (\d+) Rows_sent: (\d+) Rows_examined: (\d+)")
XLS_LINE = 1
def processEntry(fineLog, queryTime, entries=[]):
#queryTime
for entry in entries:
gotTime = False
timeStat = []
sqls = []
for e in entry:
if "# User" in e:
gotTime = False
sqls = []
timeStat = []
continue
if "# Query_time" in e:
matches = QUERY_TIME_PATTERN.match(e)
if matches:
timeStat = [ int(x) for x in [matches.group(1), matches.group(2), matches.group(3), matches.group(4)]]
gotTime = True
continue
if gotTime:
sqls.append(e)
if timeStat == [0, 0, 0, 0]:
continue
# queryTime, timeStat, sqls
fineLog.write(",".join([str(x) for x in timeStat]))
fineLog.write(",")
fineLog.write("\"")
fineLog.write(" ".join(sqls))
fineLog.write("\"\n")
pass
def main(file):
queryTime = None
entries = []
entry = []
fineLog = open("out.txt", "w")
fineLog.write("Query_time,Lock_time,Rows_sent,Rows_examined,SQLs\n")
fh = open(file, "r")
for line in fh:
if "# Time" in line.strip():
queryTime = line
if entries:
processEntry(fineLog, queryTime, entries)
entries = []
continue
if "# User@Host" in line.strip():
if entry:
entries.append(entry)
entry = []
if queryTime:
entry.append(line.strip())
fineLog.close()
if __name__ == "__main__":
main("mysql_slow_queries.log")
#!/bin/bash
NDK_HOME=$ANDROID_NDK_ROOT
if [ `uname` != 'Linux' ]; then
HOST_OS=darwin-x86
else
HOST_OS=linux-x86
fi
PLATFORM=$NDK_HOME/platforms/android-4/arch-arm
EX_INCLUDE=$PLATFORM/usr/include
MY_CC=$NDK_HOME/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$HOST_OS/bin/arm-linux-androideabi-gcc
MY_NM=$NDK_HOME/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$HOST_OS/bin/arm-linux-androideabi-nm
MY_CC_PREFIX=$NDK_HOME/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$HOST_OS/bin/arm-linux-androideabi-
MY_LIB_GCC_A=$NDK_HOME/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$HOST_OS/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a
PREFIX=./OUTPUT
ADDITIONAL_CONFIGURE_FLAG=
export CC=$MY_CC
export CFLAGS="-I$EX_INCLUDE -g -std=c99 -O3 -fpic -DANDROID -fasm -Wno-psabi -fno-short-enums -fno-strict-aliasing -finline-limit=300 $OPTIMIZE_CFLAGS "
export LDFLAGS="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog"
export CPP="$MY_CC -I$EX_INCLUDE -E"
./configure \
--disable-gtktest \
--host=arm \
--disable-frontend \
--disable-decoder \
--enable-shared=libmp3lame \
--prefix=`pwd`/android
make install
"$MY_CC_PREFIX"ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -soname libmp3lame.so \
-shared -nostdlib -z,noexecstack -Bsymbolic --whole-archive --no-undefined -o libmp3lame.so \
libmp3lame/*.o \
-lc -lm -lz -ldl -llog --warn-once --dynamic-linker=/system/bin/linker \
$MY_LIB_GCC_A
[root@lab ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="dhcp"
HWADDR="08:00:27:61:6E:0B"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="b8e9dffa-0733-4352-8803-900b9dde4bd2"
import SocketServer
import BaseHTTPServer
import httplib
import collections
import logging
logger = logging.getLogger("SHOUTcast")
FORMAT="[%(asctime)-15s %(levelname)5s] %(message)s"
logging.basicConfig(format=FORMAT)
logger.setLevel(logging.DEBUG)
#logger.setLevel(logging.INFO)
class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
def shoutcast(self, filehandle):
conn = httplib.HTTPConnection("shoutcast.omroep.nl", 8074)
conn.request("GET", "/", "", {"icy-metadata": "1"})
resp = conn.getresponse()
data = resp.read(512)
sep = "\r\n\r\n"
sep_pos = data.index(sep)
headers = data[:sep_pos]
metaint = [ int(h.split(":")[1].strip()) for h in headers.lower().split("\n") if "icy-metaint" in h][0]
logger.debug(headers)
logger.info("metaint: %d", metaint)
# stream data
data = data[sep_pos + len(sep):]
pad = metaint - len(data)
meta_size = 0
while True:
while pad > 0:
d = resp.read(pad)
filehandle.write(d)
pad -= len(d)
if pad == 0:
meta_size = ord(resp.read(1)) * 16
# logger.info("got meta size: %d", meta_size)
if meta_size == 0:
pad = metaint
break
while meta_size > 0:
logger.info("in meta: %d", meta_size)
d = resp.read(meta_size)
meta_size -= len(d)
if meta_size == 0:
pad = metaint
def do_GET(self):
self.send_response(200, "")
self.send_header("Content-Type", "audio/mpeg")
self.end_headers()
self.shoutcast(self.wfile)
PORT = 8000
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.ec2.AmazonEC2Client;
import com.amazonaws.services.ec2.model.DescribeSpotPriceHistoryRequest;
import com.amazonaws.services.ec2.model.InstanceType;
import com.amazonaws.services.ec2.model.LaunchSpecification;
import com.amazonaws.services.ec2.model.RequestSpotInstancesRequest;
import com.amazonaws.services.ec2.model.RequestSpotInstancesResult;
import com.amazonaws.services.ec2.model.SpotPrice;
public class SpotInstanceCreator {
private static final String CREDENTIALS_PATH = "/AwsCredentials.properties";
private static final String EC2_ENDPOINT = "ec2.ap-southeast-1.amazonaws.com";
static Log logger = LogFactory.getLog(SpotInstanceCreator.class);
AmazonEC2Client ec2client;
public SpotInstanceCreator() throws IOException {
ec2client = new AmazonEC2Client(getCredentials());
ec2client.setEndpoint(EC2_ENDPOINT);
}
protected PropertiesCredentials getCredentials() throws IOException {
return new PropertiesCredentials(Ec2Util.class.getResourceAsStream(CREDENTIALS_PATH));
}
public boolean requestSpotInstances(String amiId, String data, int count) {
logger.info("ami-id: " + amiId);
RequestSpotInstancesRequest request = new RequestSpotInstancesRequest();
request.setInstanceCount(count);
request.setSpotPrice(getCurrentSpotPrice());
request.setLaunchSpecification(createLaunchSpec(amiId, data));
RequestSpotInstancesResult result = ec2client.requestSpotInstances(request);
logger.info(result);
return true;
}
protected String getCurrentSpotPrice() {
DescribeSpotPriceHistoryRequest request = new DescribeSpotPriceHistoryRequest();
request.setStartTime(new Date());
request.setInstanceTypes(Arrays.asList(InstanceType.T1Micro.toString()));
request.setProductDescriptions(Arrays.asList("Linux/UNIX"));
for (SpotPrice p : ec2client.describeSpotPriceHistory(request).getSpotPriceHistory()) {
return p.getSpotPrice();
}
throw new RuntimeException("cannot get the price of spot instances");
}
protected LaunchSpecification createLaunchSpec(String amiId, String data) {
LaunchSpecification specification = new LaunchSpecification();
specification.setInstanceType(InstanceType.T1Micro);
specification.setImageId(amiId);
specification.setKeyName(System.getProperty("EC2_KEY"));
specification.setSecurityGroups(Arrays.asList("default"));
String userData = new String(Base64.encodeBase64(("" + data).getBytes()));
specification.setUserData(userData);
logger.info("data: " + data);
logger.info("user-data: " + userData);
return specification;
}
public static void main(String[] args) throws IOException {
SpotInstanceCreator creator = new SpotInstanceCreator();
creator.requestSpotInstances("ami-aa9ed2f8", "# test test", 1);
}
}
Function exec(shell, cmd)
Set ret = shell.Exec(cmd)
exec = ret.StdOut.ReadAll
End Function
Set objShell = CreateObject("WScript.Shell")
msgbox exec(objShell, "systeminfo")
[root@prober ~]# vnstat -d
eth0 / daily
day rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
12/19/12 29.12 GiB | 990.76 MiB | 30.09 GiB | 2.92 Mbit/s
12/20/12 20.14 GiB | 683.21 MiB | 20.81 GiB | 2.02 Mbit/s
12/21/12 32.19 GiB | 1.03 GiB | 33.22 GiB | 3.23 Mbit/s
12/22/12 31.03 GiB | 1.03 GiB | 32.07 GiB | 3.11 Mbit/s
12/23/12 20.73 GiB | 716.07 MiB | 21.43 GiB | 2.11 Mbit/s
------------------------+-------------+-------------+---------------
estimated 21.02 GiB | 726 MiB | 21.73 GiB |
[root@prober ~]# vnstat
Database updated: Sun Dec 23 23:47:01 2012
eth0 since 12/19/12
rx: 133.49 GiB tx: 4.41 GiB total: 137.90 GiB
monthly
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
Dec '12 133.49 GiB | 4.41 GiB | 137.90 GiB | 582.35 kbit/s
------------------------+-------------+-------------+---------------
estimated 179.99 GiB | 5.94 GiB | 185.94 GiB |
daily
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
yesterday 31.03 GiB | 1.03 GiB | 32.07 GiB | 3.11 Mbit/s
today 21.00 GiB | 723.74 MiB | 21.71 GiB | 2.13 Mbit/s
------------------------+-------------+-------------+---------------
estimated 21.19 GiB | 729 MiB | 21.91 GiB |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment