[Logwatch-Devel] CPU info / Mem info for logwatch

laurent.dufour at havas.com laurent.dufour at havas.com
Mon Jan 23 10:25:03 MST 2006



Hi guys,

Here is a new year , here is a new patch. Hope you will find it useful.

The main  aim of this patch is to bring more info on the cpu, mem, and
machine type to the logwatch report

It is to apply to logwatch 7.2.1

It uses some new modules Sys:CPU and Sys::MemInfo both are installable from
CPAN using the following command

perl -MCPAN -e 'install Sys::CPU'
perl -MCPAN -e 'install Sys::MemInfo'

New informations are available even if those two modules are not installed
, but it's better to have them.


Once installed here is some example :

################### Logwatch 7.2.1 (01/18/06) ####################
        Processing Initiated: Mon Jan 23 18:45:05 2006
        Date Range Processed: yesterday
                              ( 2006-Jan-22 )
                              Period is day.
      Detail Level of Output: 0
              Type of Output: unformatted
           Logfiles for Host: ns1.eurorsg.fr
                     Release: Linux 2.6.13.4
                         CPU: 2 Intel(R) Xeon(TM) CPU 2.40GHz at 2392 Mhz
                Total Memory: 1008 Mo
  ##################################################################




 ################### Logwatch 7.2.1 (01/18/06) ####################
        Processing Initiated: Mon Jan 23 17:59:51 2006
        Date Range Processed: yesterday
                              ( 2006-Jan-22 )
                              Period is day.
      Detail Level of Output: 0
              Type of Output: unformatted
           Logfiles for Host: termx
                     Release: Linux 2.6.14-1.1656_FC4
                         CPU: 1 Pentium III (Coppermine) at 797 Mhz
                Total Memory: 248 Mo
  ##################################################################





No Sys::CPU installed , use perl -MCPAN -e 'install Sys::CPU' to install it
No Sys::MemInfo installed , use perl -MCPAN -e 'install Sys::MemInfo' to
install it
################### Logwatch 7.2.1 (01/18/06) ####################
        Processing Initiated: Mon Jan 23 17:58:51 2006
        Date Range Processed: yesterday
                              ( 2006-Jan-22 )
                              Period is day.
      Detail Level of Output: 0
              Type of Output: unformatted
           Logfiles for Host: ordinateur-de-laurent-dufour.local
                     Release: Darwin 7.9.0
                         CPU: Power Macintosh
  ##################################################################


No Sys::CPU installed , use perl -MCPAN -e 'install Sys::CPU' to install it
 ################### Logwatch 7.2.1 (01/18/06) ####################
        Processing Initiated: Mon Jan 23 18:14:19 2006
        Date Range Processed: yesterday
                              ( 2006-Jan-22 )
                              Period is day.
      Detail Level of Output: 0
              Type of Output: unformatted
           Logfiles for Host: obsd-g3.eurorscg.fr
                     Release: OpenBSD 3.8
                         CPU: macppc
                Total Memory: 64 Mo
  ##################################################################







and now here is the patch :



--- logwatch.pl-7.2.1   2006-01-23 12:58:24.000000000 +0100
+++ logwatch.pl 2006-01-23 17:59:30.000000000 +0100
@@ -1,5 +1,6 @@
 #!/usr/bin/perl -w
 use strict;
+
 ##########################################################################
 # $Id: logwatch.pl,v 1.162 2006/01/19 05:33:04 kirk Exp $
 ##########################################################################
@@ -51,6 +52,28 @@
 use POSIX qw(uname);
 use File::Temp qw/ tempdir /;

+my $syscpu_module = "0";
+my $sysmeminfo_module = "0";
+
+eval "require Sys::CPU";
+   if ($@) {
+      print STDERR "No Sys::CPU installed , use perl -MCPAN -e 'install
Sys::CPU' to install it\n";
+      $syscpu_module = "0";
+    } else {
+       import Sys::CPU;
+        $syscpu_module = "1";
+   }
+
+eval "require Sys::MemInfo";
+   if ($@) {
+      print STDERR "No Sys::MemInfo installed , use perl -MCPAN -e
'install Sys::MemInfo' to install it\n";
+        $sysmeminfo_module = "0";
+    } else {
+       import Sys::MemInfo qw(totalmem freemem);
+        $sysmeminfo_module = "1";
+   }
+
+
 eval "use lib \"$BaseDir/lib\";";
 eval "use Logwatch \':dates\'";

@@ -926,9 +949,23 @@
    return if $printing;

    my $OStitle;
+   my $number_of_cpus;
+   my $cpu_type;
+   my $cpu_clock;
+   my $machine_mem;
    $OStitle = $OSname;
    $OStitle = "Solaris" if ($OSname eq "SunOS" && $release >= 2);

+   if ($syscpu_module eq "1") {
+       $number_of_cpus = Sys::CPU::cpu_count();
+       $cpu_type = Sys::CPU::cpu_type();
+       $cpu_clock = Sys::CPU::cpu_clock();
+   }
+   if ($sysmeminfo_module eq "1") {
+       $machine_mem = ((&totalmem - (&totalmem % (1024*1024))) /
(1024*1024));
+   }
+#   print "  Type  : ",Sys::CPU::cpu_type(),"\n";
+
    if ($Config{'print'} eq 1) {
       *OUTFILE = *STDOUT;
    } elsif ($Config{'save'} ne "") {
@@ -941,7 +978,7 @@
          open(OUTFILE,"|$Config{'mailer'}") or die "Can't execute
$Config{'mailer'}: $!\n";
          print OUTFILE "To: $Config{'mailto'}\n";
          print OUTFILE "From: $Config{'mailfrom'}\n";
-         print OUTFILE "Subject: Logwatch for $Config{'hostname'}
(${OStitle})\n";
+         print OUTFILE "Subject: Logwatch for $Config{'hostname'}
(${OStitle}/$machine)\n";
          #Add MIME
          $out_mime .= "MIME-Version: 1.0\n";
          if ( $Config{encode} == 1 ) {
@@ -996,7 +1033,17 @@
    output( $index_par, "     Detail Level of Output: $Config{'detail'}\n",
"line");
    output( $index_par, "             Type of Output: $Config{'output'}\n",
"line");
    output( $index_par, "          Logfiles for Host:
$Config{'hostname'}\n", "line");
-
+   output( $index_par, "                    Release: $OStitle $release\n",
"line");
+   if ($syscpu_module eq "1") {
+   output( $index_par, "                        CPU: $number_of_cpus
$cpu_type at $cpu_clock Mhz\n", "line");
+   }
+   else
+   {
+   output( $index_par, "                        CPU: $machine\n", "line");
+   }
+   if ($sysmeminfo_module eq "1") {
+   output( $index_par, "               Total Memory: $machine_mem Mo \n",
"line");
+   }
    if ( $outtype_html ) {
       output( $index_par, "\n", "stop");
    } else {




I have also modified the installation script from the logwatch-7.2.1.tar.gz


Here is the patch to apply


--- install_logwatch.sh-7.2.1   Thu Jan  5 20:59:09 2006
+++ install_logwatch.sh Mon Jan 23 18:19:45 2006
@@ -162,6 +162,10 @@
        perl -pi -e "s%/usr/bin/perl%$PERLEXE%"
$BASEDIR/scripts/logwatch.pl
 fi

+perl -MCPAN -e 'install Date::Manip'
+perl -MCPAN -e 'install Sys::CPU'
+perl -MCPAN -e 'install Sys::MemInfo'
+
 #Man page
 if [ -d $MANDIR/man8 ]; then
        #Should exist in BSD and Linux
@@ -191,7 +195,7 @@
        printf "Created /etc/cron.daily/0logwatch \n"
 else
        printf "You need to setup your cron job for logwatch, something
like \n"
-       printf "2 0 * * * /etc/logwatch/scripts/logwatch.pl >/dev/null 2>&1
\n"
+       printf "2 0 * * * /usr/sbin/logwatch >/dev/null 2>&1 \n"

 fi



Cheers,
----------------------------------------------------------------------------------------

Laurent DUFOUR - HAVAS IT
Vice Chief Technical Officer - Directeur Technique Adjoint
2 Allée de Longchamp - 92281 - Suresnes - France
tel: +33 (0)158478830 - fax: +33 (0)1 58478815
mailto:laurent.dufour at havas.com
http://www.havas.com
----------------------------------------------------------------------------------------





More information about the Logwatch-Devel mailing list