ZabbixのUserParameter
特定のフォルダのサイズを取得する
UserParameter=custom.vfs.dir.size[*],du -c $1 | grep total | awk '{print $$1}'
Permissioに気を付けよう。
正常に取得できているかチェック
# zabbix_get -s 127.0.0.1 -k "custom.vfs.dir.size[/hoge/foo]"
空行が返ってくる場合は、zabbix agentがアクセスを拒否している場合がある。
Server=hogehoge.com
/etc/zabbix/zabbix_agentd.conf のServer設定は上記のようになっている場合
hogehoge.com以外のサーバーからの値の取得要求は拒否されるようになっている。
Server設定は複数設定出来るようになっているので、localhostからも取得したい場合は以下のようにしておく。
Server=hogehoge.com,127.0.0.1
MarshalByRefObjectのLifeTime
MarshalByRefObjectはLifeTimegが設定されており、InitializeLifetimeServiceにて時間が制御されている。
(デフォルトでは2~3分)
無限に生きててほしい場合は、Overrideし return null するとよい。
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.Infrastructure)] public override Object InitializeLifetimeService() { return null; }
WindowsにおけるMongoDBのサービス化
これだけ。
mongod.exe --config
POSTに対してリダイレクトされた場合に、次にブラウザが試すのは…GET?POST?
POSTリクエストを出して、サーバーがリダイレクトを望んだ場合
ブラウザによって、その次の行動が変わる。
http://hakobe932.hatenablog.com/entry/20090707/1246985195
ユーザーの情報を勝手に別のサーバーにPOSTされたらかなわん!って言うのが主な理由なんだけど、まぁ確かに納得できる。
C#のWebClient等でPOSTしようとした場合は、適切にReturnコードをみてもう一度POSTするなりなんなりしないといけない。WebClientは単純に使う分には申し分ないんだけど、本当にちゃんと使おうと思ったら、やっぱりHTTPの使用は知っておかないと設計がおかしくなるな。
Pythonで[1k](キロ)とか[1G](ギガ)とかを整数の値にする
[1k](キロ)とか[1G](ギガ)とかを整数の値に直す。
import re def StrSizeToByteSize(str): r = re.compile(r"(?P<value>^([1-9]\d*|0)(\.\d+)?)(?P<fig>[kKmMgGtTpP]?)") res = r.search(str) if res != None: mag = 1 if res.group("fig") == "k" or res.group("fig") == "K": mag = 1024 if res.group("fig") == "m" or res.group("fig") == "M": mag = 1024 * 1024 if res.group("fig") == "g" or res.group("fig") == "G": mag = 1024 * 1024 * 1024 if res.group("fig") == "t" or res.group("fig") == "T": mag = 1024 * 1024 * 1024 * 1024 if res.group("fig") == "p" or res.group("fig") == "P": mag = 1024 * 1024 * 1024 * 1024 * 1024 return int(float(res.group("value")) * mag) return None
一応[P](ペタ)まで。
少数以下切り捨て。
「1kg」とかは一番最初の文字優先
1kg -> 1024
1gk -> 1048576
指定のフォルダ以下のファイルをatime(アクセスタイム)でソート
find <DIR> -type f -exec stat --format="%X %n" {} \; | sort
もちろん[--format]オプションでatime以外でもSort出来るよ。
Usage: stat [OPTION]... FILE... Display file or file system status. -L, --dereference follow links -Z, --context print the SELinux security context -f, --file-system display file system status instead of file status -c --format=FORMAT use the specified FORMAT instead of the default; output a newline after each use of FORMAT --printf=FORMAT like --format, but interpret backslash escapes, and do not output a mandatory trailing newline. If you want a newline, include \n in FORMAT. -t, --terse print the information in terse form --help display this help and exit --version output version information and exit The valid format sequences for files (without --file-system): %a Access rights in octal %A Access rights in human readable form %b Number of blocks allocated (see %B) %B The size in bytes of each block reported by %b %C SELinux security context string %d Device number in decimal %D Device number in hex %f Raw mode in hex %F File type %g Group ID of owner %G Group name of owner %h Number of hard links %i Inode number %n File name %N Quoted file name with dereference if symbolic link %o I/O block size %s Total size, in bytes %t Major device type in hex %T Minor device type in hex %u User ID of owner %U User name of owner %x Time of last access %X Time of last access as seconds since Epoch %y Time of last modification %Y Time of last modification as seconds since Epoch %z Time of last change %Z Time of last change as seconds since Epoch Valid format sequences for file systems: %a Free blocks available to non-superuser %b Total data blocks in file system %c Total file nodes in file system %d Free file nodes in file system %f Free blocks in file system %C SELinux security context string %i File System ID in hex %l Maximum length of filenames %n File name %s Block size (for faster transfers) %S Fundamental block size (for block counts) %t Type in hex %T Type in human readable form NOTE: your shell may have its own version of stat, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports. Report stat bugs to bug-coreutils@gnu.org GNU coreutils home page: <http://www.gnu.org/software/coreutils/> General help using GNU software: <http://www.gnu.org/gethelp/> For complete documentation, run: info coreutils 'stat invocation'
速度制限を付けつつ、フォルダの同期コピーを行う
よく忘れるので。
rsync -avr --delete --bwlimit=62 <SRC> <DEST>