Ticket #499 (closed patch: fixed)

Opened 5 years ago

Last modified 3 months ago

SysV IPC locking in munin-cgi-graph and correct handling of expired graphs

Reported by: Fox Assigned to: nobody
Priority: low Milestone:
Component: web-interface Version: 1.3.3
Severity: minor Keywords: munin-cgi-graph cgi lock graph
Cc:

Description

I played a little with munin-cgi-graph. It was too slow too my taste. So i took a hint in munin-cgi-graph and changed the locking scheme to SysV IPC and fixed graph expiration mechanism.

(I'm not a perfect coder and I'm using munin for a few days, so please excuse my code)

Tomas

--- ../build/server/munin-cgi-graph     2007-05-12 14:34:20.571040495 +0200
+++ /home/_www/ssl/cgi-bin/munin-cgi-graph      2007-05-12 14:44:32.672602375 +0200
@@ -25,6 +25,7 @@
 use IO::Handle;
 use Date::Manip;
 use POSIX qw(strftime);
+use IPC::SysV qw(IPC_CREAT);

 my $GRAPHER = "/usr/libexec/munin/munin-graph";
 my $conffile = "/etc/munin/munin.conf";
@@ -49,6 +50,7 @@
 my $serv  = "";
 my $dom   = "";
 my $lock  = "";
+my $IPC_KEY = 89340;

 my $config = &munin_readconfig ($conffile);

@@ -112,19 +114,30 @@

 my $max_cgi_graph_jobs = &munin_get ($config, "max_cgi_graph_jobs" , 6, $dom);

-until ( $lock ) {
-    foreach my $n ( 1 .. $max_cgi_graph_jobs ) {
-       if (&munin_getlock ("$config->{rundir}/munin-cgi-graph-$n.lock")) {
-           $lock = "munin-cgi-graph-$n.lock";
-           last;
-       }
-    }
-    sleep 1;
+#until ( $lock ) {
+#    foreach my $n ( 1 .. $max_cgi_graph_jobs ) {
+#       if (my $x = &munin_getlock ("$config->{rundir}/munin-cgi-graph-$n.lock")) {
+#         $lock = "munin-cgi-graph-$n.lock";
+#           last;
+#       }
+#    }
+#    sleep 1;
+#}
+my $semid = semget($IPC_KEY, 0, 0 );
+if(!$semid)
+{
+       $semid = semget($IPC_KEY, 1 , 0666 | IPC_CREAT ) || die "$!";
+       my $opstring = pack("s!s!s!",0, $max_cgi_graph_jobs,0);
+       semop($semid,$opstring) || die "$!";
 }
+my $opstring = pack("s!s!s!",0, -1, 0);
+semop($semid,$opstring);

 &graph ($filename);
+$opstring = pack("s!s!s!",0, 1, 0);
+semop($semid,$opstring);

-munin_removelock($lock);
+#munin_removelock($lock);

 sub graph
 {
@@ -230,19 +243,22 @@
 {
     my $filename = shift;
     my $time     = shift;
-
+
     if (-f $filename)
     {
        my @stats = stat (_);
-       if (($stats[9]) > ($time - $time%$period{$scale}))
+       my $expire = ($stats[9] - $time%$period{$scale}+$period{$scale})-$time;
+#print STDERR "Expires in: $expire\n";
+
+       if ($expire >= 0)
        {
 #print STDERR "Skipping munin-graph-run for \"$filename\".\n";
-#print STDERR ("Graph unexpired for $scale. ($stats[9] , $time, ", ($time%$period{$scale}), ", ", ($time - $time%$period{$scale}), ").\n");
+#print STDERR ("Graph unexpired for $scale. ($stats[9] , $time, ". ($time%$period{$scale}). ", ". ($time - $time%$period{$scale}). ").\n");
            return 1;
        }
        else
        {
-#print STDERR ("Graph expired for $scale. ($stats[9] , $time, ", ($time%$period{$scale}), ", ", ($time - $time%$period{$scale}), ").\n");
+#print STDERR ("Graph expired for $scale. ($stats[9] , $time, ". ($time%$period{$scale}). ", ". ($time - $time%$period{$scale}). ").\n");
            return 0;
        }
     }
@@ -260,7 +276,7 @@

     my @params = ($GRAPHER);
     push @params, @$scale;
-    push @params, "--skip-locking", "--skip-stats";
+    push @params, "--skip-locking", "--skip-stats", "--nolazy";
     push @params, "--host", $host, "--service", $serv;
     push @params, "STDERR>&STDOUT";

Change History

21/09/07 15:06:37 changed by janl

Folded into r1323

Thanks a lot!

Nicolai

25/09/07 21:11:28 changed by janl

  • status changed from new to closed.
  • resolution set to fixed.

27/10/11 11:23:25 changed by quoluowiven1986

Anybody who loves motion pictures is more likely to love movie downloads, too. The fact is this trend is changing into an enormous one and it's nice for individuals who want to create large collections with out having to dole out high dollar or premium house space to do so. How to download video from vimeo at the moment are accessible legally from all kinds of big film studios and even tv networks, as well. A video collection created digitally has an a variety of benefits over regular disk purchases, too. The most important perks of video downloads contain the storage issues and pricing. But, why? Video downloads are usually just a few dollars or extra lower than an everyday DVD purchase because there is no such thing as a packaging points to contend with. Plus, there's the easy fact supply is not a problem either. For the reason that corporations that promote downloads save on transport and the film studios save on packaging, they will move on some of these savings directly to buyers. In regard to storage, it is a simple fact of space. It is a complete lot simpler to retailer films on a pc drive or a backup drive than it's to hold a hundred videos in a room. There isn't any need for shelf after shelf or tons of DVD towers when a set is created via video download. Administration of movies and tv downloads can be a complete lot easier, too. It is fairly easy to create folders on the computer to store movies by genre and it is an entire lot faster, too. Video downloads are becoming the favorites of many for a motive beyond storage or pricing. This purpose is variety. The very fact is the kinds of downloads obtainable can be actually thoughts boggling. Let's look at what sorts of video downloads can be found legally: Hit motion pictures Just about every new movie that hits the theaters will find yourself in a authorized download format shortly after release. This means there is not any need to run to the video store, or worse, pay high dollar at a theater to see a brand new release. Tv programs video downloading Because the film studios jump on the bandwagon, so too are the tv studios. Hit reveals from all decades might be discovered by the season or by the episode by way of video download.Classics Because the film download business turns into more fashionable, many studios are video via their catalogues and offering downloads of their older movies. From the classics of the Twenties to vacation favorites of the 1980s, they can all be discovered by way of video download. And, if a title cannot be discovered right now, it's seemingly it will be added quickly as every major movie studio falls into place offering downloads via numerous totally different sites. Video downloads provide their users with an on demand facet, value savings and storage concern reduction that common DVD buys cannot. As this new format turns into increasingly more accepted, it's becoming the strategy of alternative for getting and watching movies. Original works There are tons of places to get video downloads from novice or little known creators. These movies may not have the monetary backing of some of the major motion pictures in history, however that doesn't mean there is not some good entertainment out there. Indie works are getting a complete new audience because of video downloads and the Internet.