snmp/mrtgでプロセスの開いているファイルディスクリプタ数を監視

してみる
PLAIN TEXT
PERL:

#!/usr/bin/perl

 

use strict;

use warnings;

use Unix::Lsof;

use Unix::PID;

 

my $pid = Unix::PID->new();

my $red5_pid = $pid->get_pidof('search for a process by this string');

unless ( $red5_pid ) {

  print '0';

  exit;

}

 

my ( $output, $error ) = lsof( '-p', $red5_pid, '-w' );

my @vals = values %{$output};

print scalar @{ $vals[0]{files} };

snmpd.conf に
PLAIN TEXT
CODE:

exec fd_mon   /path/to/fd_mon.pl

mrtg.cfg に
PLAIN TEXT
CODE:

Target[fd]: .1.3.6.1.4.1.2021.8.1.101.1&.1.3.6.1.4.1.2021.8.1.101.1:public@localhost

MaxBytes[fd]: 2000

YLegend[fd]: File Descriptors

ShortLegend[fd]:

LegendI[fd]: [...]

WindowsでC++からlibxml2を使う

環境は
VisualC++2005ExpressEdition
http://www.zlatkovic.com/pub/libxml/
こちらからWindows用バイナリをDL
今のバージョンは libxml2-2.6.32+.win32.zip
C/C++ 追加のインクルードディレクトリに libxml2/include を追加
リンカ 追加のライブラリディレクトリに libxml2/lib を追加
こんなRSSを
PLAIN TEXT
XML:

<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0">

  <channel>

    <copyright>Copyright 2007-2008, ...</copyright>

snip..

こんな感じでパースできる
PLAIN TEXT
C++:

#include <libxml /xmlmemory.h>

#include </libxml><libxml /parser.h>

 

int XMLParser::parse( string filename ) {

 

    xmlDocPtr doc = xmlParseFile( filename.c_str() );

    if (doc == NULL ) {

        fprintf(stderr,"Document not parsed successfully. \n");

        return 0;

    [...]