OpenIDでテキストを共有できます
- 新規作成
- OpenIDで認証してエントリーを新規作成します
- 共有
- エントリーにはOpenIDで閲覧と編集に制限かけることができます
- 変更履歴
- 編集履歴もあるので、コラボレーションにも活用できます
新着エントリー
Squid SNMP versionなど
これが参考になる
http://www.oidview.com/mibs/3495/SQUID-MIB.html
% snmpwalk -v 2c -c public localhost:3401 1.3.6.1.4.1.3495.1.2.2.0 SNMPv2-SMI::enterprises.3495.1.2.2.0 = STRING: "squid" % snmpwalk -v 2c -c public localhost:3401 1.3.6.1.4.1.3495.1.2.3.0 SNMPv2-SMI::enterprises.3495.1.2.3.0 = STRING: "2.6.STABLE21" % snmpwalk -v 2c -c public localhost:3401 1.3.6.1.4.1.3495.1.1.3.0 SNMPv2-SMI::enterprises.3495.1.1.3.0 = Timeticks: (95647283) 11 days, 1:41:12.83
SNMP::ipAdEntIfIndex
% snmpwalk -v2c vs1-2 -c public ifDescr IF-MIB::ifDescr.1 = STRING: lo IF-MIB::ifDescr.2 = STRING: eth0 % snmpwalk -v2c vs1-2 -c public ipAdEntIfIndex IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1 IP-MIB::ipAdEntIfIndex.192.168.x.x = INTEGER: 2
eth0などのインターフェイス => IPアドレスの解決はこの辺でできる?
SNMP::uptime
% snmpwalk -v2c vs1-2 -c public hrSystemUptime HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (427689510) 49 days, 12:01:35.10 % snmpwalk -v2c vs1-2 -c public sysUpTimeInstance DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (296795680) 34 days, 8:25:56.80
上はOSのuptime。下はSNMPが動いている時間
SNMP::gettable
$ perl -MSNMP -MData::Dumper -e 'my $s=SNMP::Session->new(DestHost=>"localhost",Version=>2);print Dumper($s->gettable("ifTable",columns=>[qw/ifIndex ifDescr ifHCOutOctets ifOutOctets ifHCInOctets ifInOctets/]));'
$VAR1 = {
'1' => {
'ifDescr' => 'lo',
'ifInOctets' => '4199142881',
'ifHCOutOctets' => '8494110177',
'ifOutOctets' => '4199142881',
'ifHCInOctets' => '8494110177',
'ifIndex' => '1'
},
'2' => {
'ifDescr' => 'eth0',
'ifInOctets' => '3663765691',
'ifHCOutOctets' => '10938002551',
'ifOutOctets' => '2348067959',
'ifHCInOctets' => '3663765691',
'ifIndex' => '2'
}
};
SNMPv1しかない環境でもテストする
mod_perlだとなぜか落ちる
perl単体だと通るけど、mod_perlで動かすと
Attempt to free unreferenced scalar: SV 0x7f95049fd100, Perl interpreter: 0x7f9504015450 at -e line 2.
で落ちる
core.pl
#!/usr/bin/perl use Readonly; Readonly my $r => 3; require Foo foreach ($r); print <<"END;"; Content-type: text/html <html></html> END;
Foo.pm
package Foo; use Bar; 1;
Bar.pm
package Bar; 1;
net-snmp-perlのpatch
net-snmpが通常のlibに入っていない場合にライブラリが見つからなくてmakeできない件
--- net-snmp-5.5.orig/perl/agent/Makefile.PL 2007-05-31 07:53:09.000000000 +0900 +++ net-snmp-5.5/perl/agent/Makefile.PL 2010-06-08 10:14:35.000000000 +0900 @@ -89,10 +89,11 @@ if (lc($opts->{'insource'}) eq "true") { $Params{'LIBS'} = "-L../../snmplib/.libs -L../../snmplib/ -L../../agent/.libs -L../../agent/ -L../../agent/helpers/.libs -L../../agent/helpers/ " . $Params{'LIBS'}; $Params{'CCFLAGS'} = "-I../../include " . $Params{'CCFLAGS'}; + } # } else { $Params{'LIBS'} = `$opts->{'nsconfig'} --libdir` . $Params{'LIBS'}; # $Params{'PREREQ_PM'} = {'NetSNMP::OID' => '0.1'}; - } +# } $Params{'CCFLAGS'} =~ s/ -W(all|inline|strict-prototypes|write-strings|cast-qual|no-char-subscripts)//g; # ignore developer warnings if ($Params{'LIBS'} eq "" || $Params{'CCFLAGS'} eq "") { die "You need to install net-snmp first (I can't find net-snmp-config)";
Cross Site URL Hijacking(XSUH)を防ぐ
HTML全体を
<!-- /* -->
と
<!-- */ -->
で囲む
最新版のcurl + WWW::Curlのインストールメモ
AnyEvent::Curlで、サーバ側がkeepaliveに対応しているとkeepaliveのtimeoutまでレスポンスが返らない問題あるので最新にあげる。
まずcurlは適当なディレクトリにいれる
$ wget http://curl.haxx.se/download/curl-7.20.1.tar.gz $ tar zxf curl-7.20.1.tar.gz $ cd curl-7.20.1 $ ./configure --prefix=/usr/local/curl $ make $ sudo make install
WWW::Curlのインストール
$ wget http://search.cpan.org/CPAN/authors/id/S/SZ/SZBALINT/WWW-Curl-4.11.tar.gz $ tar zxf WWW-Curl-4.11.tar.gz $ cd WWW-Curl-4.11 $ CURL_CONFIG=/usr/local/curl/bin/curl-config perl Makefile.PL $ make $ make test $ sudo make install
make test時にubuntu 9.04では https://www.verisign.com/ に正しくアクセスできないようでテスト失敗しました。ちなみに、最初から入っているcurlコマンドでもverisignにアクセス失敗した。むー
ubuntu 9.04のcurlの不思議
libcurlとcurlのコマンドでbuildのされかたが違うのかな
libcurl
perl -MWWW::Curl::Easy -le 'print &WWW::Curl::Easy::version' libcurl/7.18.2 GnuTLS/2.4.2 zlib/1.2.3.3 libidn/1.10
curlコマンド
% curl --version curl 7.18.2 (x86_64-pc-linux-gnu) libcurl/7.18.2 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.10 Protocols: tftp ftp telnet dict ldap ldaps http file https ftps Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz
WWW::Curl + AnyEvent
追記: githubにあげた。
http://subtech.g.hatena.ne.jp/mala/20100420/1271742056
http://github.com/mala/AnyEvent-Curl
一年半ぐらい遅れのWWW::Curlブーム!とりあえずGETだけだけど、上手く動かせそう。WWW::Curl::Multiのfdsetでアクティブなfd番号が取れるので、それをAEで監視して変化があればperformを呼んでやればcurl_multiのイベントループが動く。
package AnyEvent::WWW::Curl; use strict; use warnings; use AnyEvent; use WWW::Curl::Easy; use WWW::Curl::Multi; use Data::Dumper; sub new { my $class = shift; my $curlm = WWW::Curl::Multi->new; my $self; $self = { req_id => 1, active => 0, curlm => $curlm, result => {}, watch => {}, }; # $self->{w} = AE::timer 0, 1, sub { warn Dumper $self->{watch} }; bless $self, $class; } sub gen_id { my $self = shift; $self->{req_id}++; } sub add { my $self = shift; my ($url, $cb) = @_; my $id = $self->gen_id; my $body = ""; open (my $fh, ">", \$body); my $curl = WWW::Curl::Easy->new; $curl->setopt( CURLOPT_URL, $url ); $curl->setopt( CURLOPT_PRIVATE, $id ); $curl->setopt( CURLOPT_WRITEDATA, $fh ); $self->{result}->{$id} = +{ curl => $curl, body => \$body, cb => $cb }; $self->{active}++; $self->{curlm}->add_handle($curl); return $id; } sub start { my $self = shift; my $cv = $self->{cv} = AE::cv; $self->check_fh; $cv; } sub check_fh { my $self = shift; my $curlm = $self->{curlm}; $curlm->perform; my ($rio, $wio, $eio) = $curlm->fdset; my %exists = map { ($_ => 1) } @{$rio}; for (keys %{ $self->{watch} }) { delete $self->{watch}->{$_} unless $exists{$_}; } for my $fd (@{$rio}) { $self->{watch}->{$fd} ||= AE::io $fd, 0, sub { my $remain = $self->on_read; $self->{cv}->send unless $remain; }; } unless (@{$rio}) { my $remain = $self->on_read; $self->{cv}->send; } } sub on_read { my $self = shift; my $curlm = $self->{curlm}; my $active = $curlm->perform; if ( $active != $self->{active} ) { while ( my ( $id, $rval ) = $curlm->info_read ) { $self->_complete($id) if ($id); } $self->check_fh; } $active; } sub _complete { my ($self, $id) = @_; $self->{active}--; my $res = $self->{result}->{$id}; $res->{cb}->($res->{body}); delete $self->{result}->{$id}; } 1;
ベンチ
use strict; use warnings; use AnyEvent; use LWP::Simple qw(get); use Time::HiRes qw(tv_interval gettimeofday); use Benchmark qw(timethese); my $url = shift @ARGV; sub stopwatch(&){ my $start = [gettimeofday]; shift->(); tv_interval($start, [gettimeofday]) } sub curl_multi { my $req = AnyEvent::WWW::Curl->new; for ( 1 .. 50 ) { $req->add( $url, sub { my $body_ref = shift; $$body_ref; } ); } my $cv = $req->start; $cv->wait; } sub lwp { get $url for 1..50 } timethese 5, { curl => sub { warn stopwatch { curl_multi() } }, lwp => sub { warn stopwatch { lwp() }; }, };
ローカルのhttpdから1350bytesの画像を取得してみた。
WWW::Curl::Multi+AnyEventで50並列で取得とLWP::Simpleで並列化しないで50回取得した場合だと、取得にかかる時間が1/3程度で、CPU負荷が1/10ぐらいになるっぽい。
いきなり置き換えるには不安なので内部RPCクライアント用に使ってみる。HTTP経由のRPCは管理が楽+クライアントの依存が少なくて嬉しいが、オーバーヘッドが気になる。
WWW::Curl+Data::MessagePack使うと実用に十分な速度が出せそう。
Benchmark: timing 5 iterations of curl, lwp...
0.128279 at curl.pl line 144.
0.112127 at curl.pl line 144.
0.11288 at curl.pl line 144.
0.121604 at curl.pl line 144.
0.113406 at curl.pl line 144.
curl: 1 wallclock secs ( 0.08 usr + 0.02 sys = 0.10 CPU) @ 50.00/s (n=5)
(warning: too few iterations for a reliable count)
0.451503 at curl.pl line 145.
0.302419 at curl.pl line 145.
0.317793 at curl.pl line 145.
0.299637 at curl.pl line 145.
0.276819 at curl.pl line 145.
lwp: 1 wallclock secs ( 1.02 usr + 0.07 sys = 1.09 CPU) @ 4.59/s (n=5)