最大値自体はdescribe-cache-parametersで取れるのでファイルに書き出しておいて、node_exporterのtextfile collectorで読み込ませることにした。
ファイルは下のような感じのスクリプトで生成した。 あらかじめ取得した値を列挙したけど、めったにノード追加しないので都度取得でもよかったかもしれない。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
出力はこんな感じ。
1
|
|
これをnode_exporter経由で取得した値と、cloudwatch_exporterで取得した値ではラベルが違うので、metric_relabel_configs
を使って同じになるように調整する必要がある。
exporter側でjobとinstanceを設定してもprometheusで読み込むときにprefixを付けてリネームしてしまうのでこうせざるを得なかった。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
あとはアラートのruleを設定するだけ。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
はじめはredis,memcached共通で使えるaws_elasticache_freeable_memory_average
を使って設定したら1.4とかふざけた値になったので、使用量を元に計算するように変更した。
これって自分の環境だけなのかな…
外形監視にはblackbox_exporterを使う。
komachi_heartbeatを導入しているので、レスポンスとしてheartbeat:ok
が返ってくるかチェックできればよい。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
1 2 3 4 5 6 7 8 |
|
複数あるwebサーバーそれぞれに対してリクエストを投げるのは以下のような感じ。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
1 2 3 4 5 6 7 8 9 10 |
|
監視したいドメインが複数ある場合、ドメインごとにblackbox.ymlの設定を増やしていかないといけないのが微妙かもしれない。
]]>試したバージョンは2.3.3と2.4.0で、このあたりを参考にした。
同じmoduleをincludeしているクラスに対して共通のrefinementsを適用したかったが、2.3ではmoduleに対してrefineは使えないのでrefineブロック内でincludeしてみたが…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
どうもそう単純にはいかないらしい。ぐぬぬ。
いろいろこねくり回した結果、思った通りの動きをするコードは一応何通りか書けた。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
うーん…どれもなんかやだな。 もうちょっとうまいやり方はないものか。
]]>まずrdbファイルを取得する。バックアップのエクスポートで今日のバックアップをS3にエクスポートした。1.8GBぐらい。
ファイルがでかいのでAWS上で作業する。 本番ウェブサーバーのコピーを使って適当に立てたインスタンスにrdbtoolsをインストール。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
これでOKなはずだったが・・・
1 2 3 4 5 6 7 8 9 10 11 |
|
あれ?
1 2 |
|
??
以前やったときはこんなことにはならなかったが???
よく見るとどうやら最新は9日前にリリースされたバージョンで、前回使ったのは古いやつだったらしい。
1 2 |
|
これでとりあえず動いた。pythonのバージョンの問題な気がするが、よくわからんので放置。
CSVの生成には20分ぐらいかかった。 次は出力されたCSVを加工していく。
1 2 3 4 5 6 7 |
|
出力されたCSVの中身はこんな感じ。 redis-objects gem使ってるとこういうキーのやつがいっぱいできちゃうよなー。 まとめやすいようにidっぽい部分を雑に置換する。
1
|
|
1 2 3 4 5 6 7 |
|
こいつを合計するスクリプトをざっと書いた。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
1 2 3 4 5 6 |
|
余計なものがたくさんありそうなことはわかったけど、こいつらを消してもまだ足りなさそうな気がするなあ。
定期的に削除する/できるようにする前のデータが残っていたのでまとめて削除した。 実装に手を入れたタイミングで消したつもりだった…。
]]>とりあえずcloneしてsourceブランチに切り替える。
1 2 3 |
|
もろもろ必要なgemをinstallする。bundle execとか付けたくないので雑にgemsetに突っ込む。
1 2 |
|
デプロイするには_deployディレクトリにmasterブランチが必要なのでworktreeを作る。
1
|
|
これでOK。
]]>使用しているfishのバージョンは2.4.0で、プラグインなどは入れてない。 oh-my-fishを使うと便利っぽいけど、困ったときに入れたらいいかなと思ってまだ困ってないので使ってない。
とりあえず~/.zshrc
をベースに~/.config/fish/config.fish
を作った。
alias
とかexport
とかは大体そのままコピペで動くが、なぜかPATHのexportだけはうまくいかなかったのでset
を使うように変更した。
他はif
をend
で閉じるとか、&&
のかわりに; and
を使うとか、$( )
は( )
にするとか、気をつけないといけないポイントはいくつかあるけどそのへんは適当に。
サーバーにログインするときはsshrcを使っていて、sshコマンドと同じようにタブでホスト名を補完してほしい。そういうときの設定は以下。
1
|
|
complete - edit command specific tab-completions
例えばzshの場合だとこんな感じのコマンドを実行することがあるけど
1
|
|
fishだとこれではダメで、env
をつける必要がある。
1
|
|
How do I set an environment variable for just one command?
{ }
の中身が展開されるため、展開を抑制したいときはエスケープが必要。
1
|
|
とか、
1
|
|
とか。ちょっと面倒。gitの引数の場合はタブ補完でバックスラッシュをちゃんとつけてくれる。
コマンド実行結果をファイルのように扱うやつ。zshだとこんな感じ。
1
|
|
fishの場合はpsub
を使う。
1
|
|
psub - perform process substitution
zshのshare_history相当のものが無いため最初は戸惑ったが、普段使っているコマンドのパターンはそれほど多くなかったので履歴が育てば不要だった。
それでもtmuxの別のwindow/paneで少し前に打ったコマンドがほしくなることはたまにあって、そういうときはhistory merge
を実行して履歴を再読込している。
自動でmergeするのを試してみたけどコマンド実行のたびに微妙に待たされてストレスたまるので手動運用のほうがよいと思う。
]]>1
|
|
.gitattributesファイルに以下の一行を書く。
1
|
|
これでcsファイルをUTF-8に変換してからdiffを取るようになった。
ググるとiconvを使うのが見つかるけど、UnityアセットのソースコードがUTF-8のものとUTF-16のものが混在しているので、入力をよしなに判別してくれるnkfを使うようにした。
]]>IRKitを使って、ChatOpsやってみたよっていう話を先週の社内LT大会で話しました。 ChatOpsしたい、rubotyとhubot使いたいっていうのが目的なので、わざとまわりくどいことをやってます。
]]>9日目は@hiracyさんによるサーバが増えた時にインフラ担当者がやってきたことです。
Unityを始めた当初はMonoDevelopを使っていたのですが、どうにも手になじまず腹が立ったので、普段サーバ側の開発で使っているemacsを使うことにしました。
以下はいろいろハマりながらも、インターネット上の先人の力を借りてまとめた自分の設定です。
これがなくては始まらないC#用のメジャーモード。
1 2 |
|
1 2 3 4 5 6 7 8 9 |
|
C#のコードをパースしたりいろいろやってくれる(らしい)サーバです。 他のエディタでも使えるらしいです。
monoが必要なのでインストールして、
1
|
|
あとはREADME通りにビルド。
1 2 3 4 |
|
するとOmniSharp/bin/Debug
にOmniSharp.exe
ができているはず。
試しに起動してみる。
1
|
|
するとずらずらっとLoadingほげほげと出てきて、Solution has finished loading
で起動完了。無事起動が確認できたらCtrl+Cで止めておく(このあとemacsから起動するので)
OmniSharpServerをemacsから使うためのものです。
1 2 |
|
1 2 3 |
|
csファイルを開いた時にslnファイルを選べと言われるので、選んであげるとバックグラウンドで起動してくれます。
M-x omnisharp-auto-complete
で候補表示、M-x omnisharp-go-to-definition
で定義にジャンプできます。
適当なキーバインドを設定しておくと便利。
omnisharp-emacsにcheckerが含まれていて、OmniSharpサーバと連携してチェックをしてくれます。
1 2 |
|
1 2 3 4 |
|
Unity上でcsファイルをダブルクリックして開きたくなったときのための設定(あまりしないけど)
Unityの設定で外部エディタに指定できるのはMacのアプリ(*.app)だけなので、emacsclientを起動するアプリを作ります。 vim用にやっている人がいたのでその設定を参考にしました。
アプリを作るのにはAutomatorを使います。手順は以下のとおり。
1 2 3 |
|
作ったappをUnity上で指定してあげると、外部エディタとしてemacsが使えるようになります。 あとはserverとして起動するのを忘れずに。
1 2 3 4 |
|
rubyの開発でも使っているDashを使えるようにします。
1
|
|
1 2 3 4 |
|
カーソル位置の単語で検索します。 上記設定ではcsharp-modeのときはキーワード “cs” が設定されたdocsetの中から検索します。
Dash側で画像のようにキーワードを設定しておくと、.NET FrameworkとUnity 3Dのドキュメントを同時に検索できます。
doxygenを使えばDash用のdocsetを作れます。 コードを含むアセットを購入した時に(たまに)やってます。
1
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
こんな感じの設定ファイルを作って、まずはHTMLドキュメントを生成。
1
|
|
htmlディレクトリに移動してmakeをたたくとdocsetが作られます。
1 2 3 |
|
日本語を含むときはBOM付きで保存しないと化けます。C-x RET f
でutf-8-with-signature
に変更。
以上、MonoDevelopを使わずにemacsでUnity開発するための設定を紹介しました。
明日はみっきーさんです。
zshだとrake new_post
のときにglob展開しようとして怒られるので、noglobをつける。
1 2 3 4 5 |
|
面倒なのでaliasを書いてしまった。
1
|
|
http://guides.rubyonrails.org/migrations.html
On databases that support transactions with statements that change the schema (such as PostgreSQL or SQLite3), migrations are wrapped in a transaction. If the database does not support this (for example MySQL) then when a migration fails the parts of it that succeeded will not be rolled back. You will have to rollback the changes that were made by hand.
なんだってー
postgresはデフォルトで対応しているが、mysqlはサポートされてなくて非対応。知らなかった…。
一応mysqlのドキュメントにもあたってみる。
http://dev.mysql.com/doc/refman/5.6/en/cannot-roll-back.html
Some statements cannot be rolled back. In general, these include data definition language (DDL) statements, such as those that create or drop databases, those that create, drop, or alter tables or stored routines.
DDLはロールバックできない、と。
開発環境だけDBサーバ変えるとかしたくないし、どうしたらいいかなあ。
という日記。
change_table
でbulk: true
オプションを付けてあげればいいらしい。
ひとつのALTERでまとめてカラム追加・削除されるので中途半端な状態は作られない。
https://github.com/blowmage/minitest-rails
Gemfile に追加。
gem "minitest-rails"
必要なファイルを生成。
$ rails generate mini_test:install
test/minitest_helper.rb が生成される。
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require "minitest/autorun"
require "minitest/rails"
# Add `gem "minitest/rails/capybara"` to the test group of your Gemfile
# and uncomment the following if you want Capybara feature tests
# require "minitest/rails/capybara"
# Uncomment if you want awesome colorful output
# require "minitest/pride"
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
各testファイルでこれを読み込むために下の一行が必要。
require 'minitest_helper'
動作確認。
$ ruby -Itest test/foo/bar_test.rb
https://github.com/semaperepelitsa/spork-minitest
Gemfile に追加。
gem "spork", "~> 1.0rc"
gem "spork-minitest", "~> 1.0.0.beta1"
下記コマンドを実行し、minitest_helper に spork 向けの設定を追加する。
$ spork minitest --bootstrap
test/minitest_helper.rb に追記されるので適宜編集する。
$LOAD_PATH << "test"
require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require "minitest/autorun"
require "minitest/rails"
require 'simplecov'
require 'simplecov-rcov'
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
SimpleCov.start 'rails'
# Add `gem "minitest/rails/capybara"` to the test group of your Gemfile
# and uncomment the following if you want Capybara feature tests
# require "minitest/rails/capybara"
# Uncomment if you want awesome colorful output
# require "minitest/pride"
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
end
Spork.each_run do
# This code will be run each time you run your specs.
end
# --- Instructions ---
# Sort the contents of this file into a Spork.prefork and a Spork.each_run
# block.
#
# The Spork.prefork block is run only once when the spork server is started.
# You typically want to place most of your (slow) initializer code in here, in
# particular, require'ing any 3rd-party gems that you don't normally modify
# during development.
#
# The Spork.each_run block is run each time you run your specs. In case you
# need to load files that tend to change during development, require them here.
# With Rails, your application modules are loaded automatically, so sometimes
# this block can remain empty.
#
# Note: You can modify files loaded *from* the Spork.each_run block without
# restarting the spork server. However, this file itself will not be reloaded,
# so if you change any of the code inside the each_run block, you still need to
# restart the server. In general, if you have non-trivial code in this file,
# it's advisable to move it into a separate file so you can easily edit it
# without restarting spork. (For example, with RSpec, you could move
# non-trivial code into a file spec/support/my_helper.rb, making sure that the
# spec/support/* files are require'd from inside the each_run block.)
#
# Any code that is left outside the two blocks will be run during preforking
# *and* during each_run -- that's probably not what you want.
#
# These instructions should self-destruct in 10 seconds. If they don't, feel
# free to delete them.
sporkの動作確認をする。
$ spork
sporkを立ち上げた状態のまま、別窓を開いて testdrb でテスト実行してみる。
$ testdrb test/**/*.rb
https://github.com/guard/guard-minitest
本家のものを使いたいところではあるが、sporkと組み合わせた時に動かないので一旦他の人が作ったブランチを使わせてもらう。 (ref. https://github.com/guard/guard-minitest/pull/41)
sporkを使わないのであれば本家のものでもおそらく問題ない。
Gemfile に追加。
gem "guard-minitest", github: "itrcdevs/guard-minitest", branch: "fix_for_spork-minitest"
設定ファイルを生成する。すでにファイルが存在する場合は内容が追記される。
$ guard init minitest
生成された Guardfile を編集する。
# More info at https://github.com/guard/guard#readme
guard 'minitest' do
# with Minitest
watch(%r|^test/(.*)_test\.rb|)
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
watch(%r|^test/test_helper\.rb|) { "test" }
# Rails
watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/controllers/#{m[1]}_test.rb" }
watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
watch(%r|^app/models/(.*)\.rb|) { |m| "test/models/#{m[1]}_test.rb" }
end
guard の動作確認。
$ guard
適当にファイルをtouchしてみるとテストが走るはず。 何も起こらない場合はちゃんと監視対象に入っているか記述を見なおしてみる。
Gemfile に追加。
gem "guard-spork"
Guardfile に設定を追加する。
$ guard init spork
Guardfile に追加された spork の箇所の編集と、minitest で drb を使うように変更する。
guard 'spork', minitest: true, minitest_env: { 'RAILS_ENV' => 'test' }, bundler: true do
watch('config/application.rb')
watch('config/environment.rb')
watch('config/environments/test.rb')
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('test/minitest_helper.rb') { 'test' }
end
guard 'minitest', drb: true do
# (省略)
end
実行。
$ guard
これだけで spork が自動的に起動する。 先と同じようにファイルを編集したときに動けばOK
$ brew install openssl
$ brew link openssl
$ brew install readline
$ brew link readline
プロジェクトのディレクトリ作る。
$ mkdir hoge && cd hoge
ruby 2.0.0-devを入れる。
$ CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl` --with-readline-dir=`brew --prefix readline`" rbenv install 2.0.0-dev
$ rbenv local 2.0.0-dev
bundlerのバージョンが1.2だと怒られるので1.3を入れる。
$ gem install bundler -v 1.3.0.pre.4
一旦Gemfileにrailsだけ書いてbundle installする。 まだrails 4.0のgemがないのでgithubから取ってくるように指定。
$ cat Gemfile
source :rubygems
gem 'rails', github: 'rails/rails'
bundle installを実行し、まずrails本体だけ入れる。
$ bundle install
rails newしていろいろファイルを生成。Gemfileを上書きするか聞かれるので Y で上書き。
$ bundle exec rails new . -d mysql -T --skip-bundle --edge
再度bundle install
$ bundle install
これで完了。あとはいつもどおりDBを作って…
$ bundle exec rake db:create
起動する。
$ bundle exec rails s
=> Booting WEBrick
=> Rails 4.0.0.beta application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
This poses a security threat. It is strongly recommended that you
provide a secret to prevent exploits that may be possible from crafted
cookies. This will not be supported in future versions of Rack, and
future versions will even invalidate your existing user cookies.
Called from: xxx/ruby/2.0.0/bundler/gems/rails-e63e280bed3a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb:24:in `initialize'.
[2013-01-07 19:35:35] INFO WEBrick 1.3.1
[2013-01-07 19:35:35] INFO ruby 2.0.0 (2013-01-07) [x86_64-darwin11.4.2]
[2013-01-07 19:35:35] INFO WEBrick::HTTPServer#start: pid=76843 port=3000
なにやらWARNING出てるけど、とりあえずwelcome画面が出た。
1 2 3 |
|
1 2 3 4 5 6 7 |
|
installすると上のように言われるので指示に従う。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
上のsudoコマンド2つを叩くだけで使えるようになる(下の方はアップグレードのときに実行するらしい)
]]>