Cancel a query
'stv_recents'テーブルから実行中のquery(status='Running')を検索してkillしたいqueryのpidを取得し、cancelコマンドをpid指定して実行すればOKです。
select pid, trim(user_name), starttime, substring(query,1,20) from stv_recents where status='Running';
cancel [pid];
select pid, trim(user_name), starttime, substring(query,1,20) from stv_recents where status='Running';
cancel [pid];
4つcoreがある場合は上記のような形で表示されます。$ mpstat -P ALL 10時19分43秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 10時19分43秒 all 8.73 0.01 1.20 0.19 0.00 0.10 0.04 0.00 89.74 10時19分43秒 0 17.30 0.00 2.28 0.44 0.00 0.32 0.06 0.00 79.60 10時19分43秒 1 7.72 0.01 1.02 0.12 0.00 0.04 0.04 0.00 91.06 10時19分43秒 2 5.24 0.01 0.80 0.11 0.00 0.02 0.03 0.00 93.79 10時19分43秒 3 4.69 0.01 0.70 0.09 0.00 0.01 0.04 0.00 94.46
$ mpstat -P ALL 1
/** A default Hadoop Configuration for the Hadoop code (e.g. file systems) that we reuse. */
val hadoopConfiguration = {
val env = SparkEnv.get
val conf = SparkHadoopUtil.get.newConfiguration()
// Explicitly check for S3 environment variables
if (System.getenv("AWS_ACCESS_KEY_ID") != null &&
System.getenv("AWS_SECRET_ACCESS_KEY") != null) {
conf.set("fs.s3.awsAccessKeyId", System.getenv("AWS_ACCESS_KEY_ID"))
conf.set("fs.s3n.awsAccessKeyId", System.getenv("AWS_ACCESS_KEY_ID"))
conf.set("fs.s3.awsSecretAccessKey", System.getenv("AWS_SECRET_ACCESS_KEY"))
conf.set("fs.s3n.awsSecretAccessKey", System.getenv("AWS_SECRET_ACCESS_KEY"))
}
// Copy any "spark.hadoop.foo=bar" system properties into conf as "foo=bar"
Utils.getSystemProperties.foreach { case (key, value) =>
if (key.startsWith("spark.hadoop.")) {
conf.set(key.substring("spark.hadoop.".length), value)
}
}
val bufferSize = System.getProperty("spark.buffer.size", "65536")
conf.set("io.file.buffer.size", bufferSize)
conf
}
要するに
$ export AWS_ACCESS_KEY_ID=xxxxxx
$ export AWS_SECRET_ACCESS_KEY=xxxxxx
$ ./spark-shell
(snip..)
scala> val data = sc.textFile("s3n://(bucket)/(path))
scala> data.count()
res0: Long = 1607157
ただし上記を実行すると、コンパイル時にエラーになります。./sbt/sbt clean SPARK_HADOOP_VERSION=2.0.0-cdh4.5.0 SPARK_YARN=true ./sbt/sbt assembly
import org.apache.hadoop.yarn.api.records.{AMResponse, ApplicationAttemptId}
というimport文があるのですが、このうち「AMResponse」インターフェースが存在しないため、コンパイルエラーになります。上記の例では、バイナリ形式でheapのダンプ情報を出力します。jmap -dump:format=b,file=[file name] [pid]
引数のファイルには、上述のjmapで出力したダンプファイルを指定します。jhat [file name]
結果は以下jmap -histo [pid] > [file name]
jmap -histo:live [pid] > [file name]
渡された文字列が空文字の場合、0が返却されます。hoge=# select json, json_array_length(json) from hoge; | 0 ["a<","b","c"] | 3
ERROR: JSON parsing error DETAIL: ----------------------------------------------- error: JSON parsing error code: 8001 context: invalid json array object 2013-11-21 00:36:08 query: 2416921 location: funcs_json.h:81 process: query1_20 [pid=9891] -----------------------------------------------
当該要素が存在しない場合は空文字が返ります。hoge=# select json, json_extract_array_element_text(json, 0); | ["a","b","c"] | a
該当するkeyが存在しない場合は空文字が返ります。hoge=# select json, json_extract_path_text(json, 'a') | {"a":1, "b":2, "c": 3} | 1
String contains invalid or unsupported UTF8 codepoints. Bad UTF8 hex sequence:
ACCEPTINVCHARS AS '_'のような形でオプション指定します。ASで置換後の任意の文字列を指定できます(デフォルトは'?')
INFO: Load into table 'hoge' completed, 59 record(s) were loaded with replacements made for ACCEPTINVCHARS. COPY
のような感じで。http://www.sada.co.jp//////index.html → http://www.sada.co.jp/index.html
こんな感じ。merge_slashes off
timezoneの変換を合わせて行う場合は、 CONVERT_TIMEZONE 関数を使用します。以下はtimezoneをJSTに変換する例。select TIMESTAMP 'epoch' + unix_time * INTERVAL '1 second' as time_stamp from hoge limit 10;
select CONVERT_TIMEZONE('JST', TIMESTAMP 'epoch' + unix_time * INTERVAL '1 second') time_stamp from hoge limit 10;
select * from pg_table_def where tablename = 'hoge';
analyze compression hoge;
{"log":{"a":1."b":2,"c":3}}
といった形で、"log"というキーの中にjsonデータをすべて包含させる必要があります。
{“a”:1, “b”:2, “c”:3 } -> {“bucket”: {“a”:1, “b”:2, “c”:3 } }
という形で、JSONデータを特定のkeyのvalue値として内包させるためのプラグインです。
ex1.
assemble foo1:bar1:to_i, foo2:bar2:to_s
record => {"foo1": "1", "foo2": 2}
reassemble => {"bar1": 1, "bar2": "2"}
ex2.
assemble foo1,foo2:bar2,foo3:bar3:unixtime_to_datetime,foo4:bar4:url_to_host
record => {"foo1": "1", "foo2": 2, "foo3": 1377946931, "foo4": "http://www.sada.co.jp/concert.html"}
reassemble => {"foo1": "1", "bar2": 2, "bar3": "2013-08-31 20:00:02", "bar4": "www.sada.co.jp"}
といった形で、"assemble"に所定のフォーマットで対象のキーとoperation内容を記述することで、plugin上でデータの加工が行えます。
{extract_key1}:{replaced_key1}:{operation1},{extract_key2}:{replaced_key2}:{operation2},....{extract_keyN}:{replaced_keyN}:{operationN}
こちらを使う事で、情報ソースのうち必要なデータを必要な形式で変換・加工し、redshiftに登録する、といった事がpluginだけで完結させる事ができます。
{“a”:1, “b”:2, “c”:3 }
というjsonデータ(msgpackデータ)を
{“bucket”: {“a”:1, “b”:2, “c”:3 } }
という様な形式に変換するプラグインです。pip install boto pip install pytz git clone https://github.com/moaikids/munin-emr.git cp munin-fluentd/plugins/emr/* /usr/share/munin/plugins/ ln -s /usr/share/munin/plugins/emr_jobflows /etc/munin/plugins/emr_jobflows
一番最後の"time_range"では、何分前のジョブ情報を取得するかを指定します(単位:分)。$ vim /etc/munin/plugin-conf.d/munin-node [emr_jobflows] user root env.access_key_id [ACCESS_KEY_ID] env.access_secret_key [ACCESS_SECRET_KEY] env.region [REGION] env.time_range 10
import boto.emr
import datetime
access_key_id = "….."
access_secret_key = "….."
conn = boto.emr.connect_to_region("ap-northeast-1", aws_access_key_id=access_key_id,aws_secret_access_key=acces s_secret_key)
created_after = datetime.datetime.today() - datetime.timedelta(hours=24)
print created_after
jobflows = conn.describe_jobflows(None, None, created_after, None )
for jobflow in jobflows:
print jobflow.jobflowid
print " " + jobflow.name
print " " + jobflow.loguri
print " " + jobflow.state
print
表示される結果は、先のRuby版の記事の内容とだいたい同じです。
#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk'
emr=AWS::EMR.new
created_after = Time.at(Time.now().to_i - (24 * 60 * 60)).iso8601
p created_after
resp = emr.client.describe_job_flows({:created_after => created_after})
resp.data[:job_flows].map{ |job|
p job[:job_flow_id]
p " " + job[:name]
p " " + job[:log_uri]
p " " + job[:execution_status_detail][:state]
p
}
実行結果例
"hogehoge" " hogejob.name" " s3n://hoge-log/emr/logs/" " COMPLETED"
# 現在時刻をunixtimeで表示 $ date +%s 1376285909
# 指定したunixtimeを日付情報で表示 $ date --date @1376285909 2013年 8月 12日 月曜日 14:38:29 JST
#全削除 redis-cli KEYS "*" | xargs redis-cli DEL
#前方一致 redis-cli KEYS "prefix*" | xargs redis-cli DEL
#後方一致 redis-cli KEYS "*suffix" | xargs redis-cli DEL
gem install aws-sdk
以下のようなruby srouceを実行すると、spot instanceのpricing historyが取得出来ます。export AWS_ACCESS_KEY_ID='...' export AWS_SECRET_ACCESS_KEY='...' export AWS_REGION='ap-northeast-1'
#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk'
ec2=AWS::EC2.new
resp = ec2.client.describe_spot_price_history(
:instance_types => ['m1.small', 'm1.medium', 'm1.large', 'm1.xlarge'],
:start_time => (Time.now - 60 * 60 * 24).iso8601,
:availability_zone => 'ap-northeast-1b')
resp.data[:spot_price_history_set].map{ |history|
if history[:product_description] == "Linux/UNIX"
p history[:instance_type] + " => " + history[:spot_price] + " (" + history[:timestamp].to_s + ")"
end
}
実行結果。"m1.small => 0.017000 (2013-08-01 22:52:34 UTC)" "m1.large => 0.067000 (2013-08-01 22:48:47 UTC)" "m1.medium => 0.035000 (2013-08-01 22:48:44 UTC)" "m1.xlarge => 0.134000 (2013-08-01 22:48:43 UTC)" "m1.small => 0.000100 (2013-08-01 22:47:34 UTC)" "m1.xlarge => 0.134000 (2013-08-01 13:12:40 UTC)" "m1.medium => 0.035000 (2013-08-01 06:47:28 UTC)" "m1.small => 0.017000 (2013-08-01 02:42:36 UTC)" "m1.large => 0.067000 (2013-08-01 00:04:50 UTC)" "m1.xlarge => 0.134000 (2013-07-31 13:11:39 UTC)" "m1.medium => 0.035000 (2013-07-31 06:44:00 UTC)"