pcp
[Top] [All Lists]

[PATCH] ds389log: fixes to match updated logconv.pl

To: pcp developers <pcp@xxxxxxxxxxx>
Subject: [PATCH] ds389log: fixes to match updated logconv.pl
From: Marko Myllynen <myllynen@xxxxxxxxxx>
Date: Fri, 12 Jun 2015 09:52:58 +0300
Delivered-to: pcp@xxxxxxxxxxx
Organization: Red Hat
Reply-to: myllynen@xxxxxxxxxx
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
Hi,

logconv.pl was recently updated to handle timestamps not present in
logs, this change now allows ds389log to work reliably with 389 DS:

https://fedorahosted.org/389/changeset/b0213c118dabb17b1c97a68ef8179093d3be5ca7/

This patch updates the ds389log PMDA to match with the latest logconv.pl
and also fixes few related issues found with the new logconv.pl as well:

- always use the C locale to match 389 DS log time stamps
- tweak log parsing error message
- fix timestamp handling
- logconv.pl prints Binds twice, count it only once
- zero metrics initially as they're being added up during PMDA lifetime

---
 src/pmdas/ds389log/pmdads389log.pl | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/pmdas/ds389log/pmdads389log.pl 
b/src/pmdas/ds389log/pmdads389log.pl
index af39343..0f94d35 100644
--- a/src/pmdas/ds389log/pmdads389log.pl
+++ b/src/pmdas/ds389log/pmdads389log.pl
@@ -18,6 +18,9 @@ use PCP::PMDA;
 use Date::Manip;
 use POSIX;
 
+# 389 DS is not locale aware
+setlocale(LC_ALL, "C");
+
 our $lc_opts = '-D /dev/shm -s all';
 our $lc_ival = 30; # minimal query interval in seconds, must be >= 30
 our $ds_alog = ''; # empty - guess; ok if only one DS instance in use
@@ -62,7 +65,7 @@ sub ds389log_set_ds_access_log {
        $ds_alog = `ls -1 $ds_logd/slapd-*/access 2>/dev/null | tail -n 1`;
        my $un = `id -un`;
        chomp($ds_alog); chomp($un);
-       die "$un can't read access log file \"$ds_alog\"" unless -f $ds_alog;
+       die "$un can't read access log file \"$ds_logd/slapd-*/access\"" unless 
-f $ds_alog;
        $pmda->log("Using access log file $ds_alog");
 }
 
@@ -86,15 +89,17 @@ sub ds389log_fetch {
        my $prev_log = `ls -1rt $ds_alog.2* 2>/dev/null | tail -n 1`;
        if ($prev_log ne '') {
                my $lastline = `tail -n 1 $prev_log`;
-               $lastline =~ tr/\[//d; $lastline =~ s/\].*//;
+               $lastline =~ s/\[//;
+               $lastline =~ s/\].*//;
+               $lastline =~ s/:/ /;
                my $log_ts = UnixDate($lastline, "%s");
                if (strftime("%s", @lc_prev) > $log_ts) {
                        $prev_log = '';
                }
        }
 
-       my $lc_start = strftime("[%d/%m/%Y:%H:%M:%S %z]", @lc_prev);
-       my $lc_end   = strftime("[%d/%m/%Y:%H:%M:%S %z]", @lc_curr);
+       my $lc_start = strftime("[%d/%b/%Y:%H:%M:%S %z]", @lc_prev);
+       my $lc_end   = strftime("[%d/%b/%Y:%H:%M:%S %z]", @lc_curr);
        @lc_prev = @lc_curr;
 
        my $ds_stats = "logconv.pl -cpe $lc_opts -S $lc_start -E $lc_end 
$ds_alog $prev_log 2>/dev/null";
@@ -104,6 +109,7 @@ sub ds389log_fetch {
        close(STATS);
 
        my $errors = 0; # combined
+       my $nobind = 0; # no dupes
        foreach my $line (@stats) {
                my $key;
 
@@ -119,6 +125,12 @@ sub ds389log_fetch {
 
                if (defined($key) && defined $data{$key}) {
                        $key = 'err=' if $key eq 'err=X';
+
+                       if ($key eq "Binds:") {
+                               next if $nobind;
+                               $nobind = 1;
+                       }
+
                        if ($line =~ /($key)\s+(\d+)/ || $line =~ 
/($key\d+)\s+(\d+)/) {
                                my $value = $2;
 
@@ -158,14 +170,14 @@ sub ds389log_fetch_callback {
 
 $pmda = PCP::PMDA->new('ds389log', 131);
 
-# Add and init metrics
+# Add and zero metrics
 foreach my $key (keys %data) {
        my $name = 'ds389log.' . $data{$key}->[1] . '.' . $data{$key}->[0];
        $pmda->add_metric(pmda_pmid($data{$key}->[2], $data{$key}->[3]),
                        PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
                        pmda_units(0,0,1,0,0,PM_COUNT_ONE),
                        $name, '', '');
-       $metrics{$name} = PM_ERR_AGAIN;
+       $metrics{$name} = 0;
 }
 
 $pmda->set_refresh(\&ds389log_fetch);

Thanks,

-- 
Marko Myllynen

<Prev in Thread] Current Thread [Next in Thread>
  • [PATCH] ds389log: fixes to match updated logconv.pl, Marko Myllynen <=