Skip to content

Commit

Permalink
omd top: improve pattern performance
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Jan 29, 2025
1 parent 0b44e5b commit 0125228
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
38 changes: 19 additions & 19 deletions plugins/plugins-available/omd/lib/Thruk/Controller/omd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,25 @@ sub index {
if($ENV{'OMD_SITE'}) {
my $site = $ENV{'OMD_SITE'};
$c->stash->{'omd_top_pattern'} = [
'\d+\s+'.$site.'\s+.*thruk_fastcgi.pl = '.$site.' thruk cgi',
'\d+\s+'.$site.'\s+.*/bin/thruk = '.$site.' thruk cli',
'\d+\s+'.$site.'\s+.*/script/thruk = '.$site.' thruk cli',
'\d+\s+'.$site.'\s+.*/usr/sbin/httpd = '.$site.' apache',
'\d+\s+'.$site.'\s+.*/usr/sbin/apache2 = '.$site.' apache',
'\d+\s+'.$site.'\s+.*lmd = '.$site.' lmd',
'\d+\s+'.$site.'\s+.*mod_gearman_worker-go = '.$site.' mod_gearman',
'\d+\s+'.$site.'\s+.*gearmand = '.$site.' gearmand',
'\d+\s+'.$site.'\s+.*/bin/naemon = '.$site.' naemon',
'\d+\s+'.$site.'\s+.*/lib/monitoring-plugins = '.$site.' monitoring plugins',
'\d+\s+'.$site.'\s+.*lib/nagios/plugins/ = '.$site.' monitoring plugins',
'\d+\s+'.$site.'\s+.*/bin/mysqld_safe = '.$site.' mysql',
'\d+\s+'.$site.'\s+.*/usr/libexec/mysqld = '.$site.' mysql',
'\d+\s+'.$site.'\s+.*bin/mariadbd = '.$site.' mysql',
'\d+\s+'.$site.'\s+.*bin/influxd = '.$site.' influxd',
'\d+\s+'.$site.'\s+.*bin/prometheus = '.$site.' prometheus',
'\d+\s+'.$site.'\s+.*bin/grafana = '.$site.' grafana',
'\d+\s+'.$site.'\s+.*bin/victoria-metrics = '.$site.' victoriametrics',
'\d+\s+'.$site.'\s+ = '.$site.' other',
'^\d+\s+'.$site.'\s+.*thruk_fastcgi.pl = '.$site.' thruk cgi',
'^\d+\s+'.$site.'\s+.*/bin/thruk = '.$site.' thruk cli',
'^\d+\s+'.$site.'\s+.*/script/thruk = '.$site.' thruk cli',
'^\d+\s+'.$site.'\s+.*/usr/sbin/httpd = '.$site.' apache',
'^\d+\s+'.$site.'\s+.*/usr/sbin/apache2 = '.$site.' apache',
'^\d+\s+'.$site.'\s+.*lmd = '.$site.' lmd',
'^\d+\s+'.$site.'\s+.*mod_gearman_worker-go = '.$site.' mod_gearman',
'^\d+\s+'.$site.'\s+.*gearmand = '.$site.' gearmand',
'^\d+\s+'.$site.'\s+.*/bin/naemon = '.$site.' naemon',
'^\d+\s+'.$site.'\s+.*/lib/monitoring-plugins = '.$site.' monitoring plugins',
'^\d+\s+'.$site.'\s+.*lib/nagios/plugins/ = '.$site.' monitoring plugins',
'^\d+\s+'.$site.'\s+.*/bin/mysqld_safe = '.$site.' mysql',
'^\d+\s+'.$site.'\s+.*/usr/libexec/mysqld = '.$site.' mysql',
'^\d+\s+'.$site.'\s+.*bin/mariadbd = '.$site.' mysql',
'^\d+\s+'.$site.'\s+.*bin/influxd = '.$site.' influxd',
'^\d+\s+'.$site.'\s+.*bin/prometheus = '.$site.' prometheus',
'^\d+\s+'.$site.'\s+.*bin/grafana = '.$site.' grafana',
'^\d+\s+'.$site.'\s+.*bin/victoria-metrics = '.$site.' victoriametrics',
'^\d+\s+'.$site.'\s+ = '.$site.' other',
];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ sub top_graph_details {

if($pid) {
$pattern = [
[$pid, "Pid: $pid"],
[qr/^$pid\s+/mx, "Pid: $pid"],
];
}

Expand Down Expand Up @@ -485,9 +485,9 @@ sub _extract_top_data {
next if $filter && $filter != $proc[0];
next if $proc[0] !~ m/^\d+/mx;
my $key = 'other';
for my $p (@{$pattern}) {
if($line =~ m|$p->[0]|mxo) {
$key = $p->[1];
for (@{$pattern}) {
if($line =~ $_->[0]) {
$key = $_->[1];
last;
}
}
Expand All @@ -497,14 +497,14 @@ sub _extract_top_data {
$procs->{cpu} += $proc[8];
my $virt;
if($proc[4] =~ m/^[\d\.]+$/mxo) {
$virt += int($proc[4]/1024); # inline is much faster than million function calls
$virt += int($proc[4]/1024);
} else {
$virt += &_normalize_mem($proc[4]);
}
$procs->{virt} += $virt;
my $res;
if($proc[5] =~ m/^[\d\.]+$/mxo) {
$res += int($proc[5]/1024); # inline is much faster than million function calls
$res += int($proc[5]/1024);
} else {
$res += &_normalize_mem($proc[5]);
}
Expand Down Expand Up @@ -562,10 +562,10 @@ sub _get_pattern {
my $pattern = [];
if($c && $c->stash->{'omd_top_pattern'}) {
for my $regex (@{$c->stash->{'omd_top_pattern'}}) {
my($k,$p) = split(/\s*=\s*/mx, $regex, 2);
my($p,$k) = split(/\s*=\s*/mx, $regex, 2);
&Thruk::Base::trim_whitespace($p);
&Thruk::Base::trim_whitespace($k);
push @{$pattern}, [$k,$p];
push @{$pattern}, [qr/$p/mx, $k];
}
}
return($pattern);
Expand Down

0 comments on commit 0125228

Please sign in to comment.