Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch: add test to datasources to see if service to be graphed is available #59

Open
Mrten opened this issue May 14, 2013 · 2 comments
Open

Comments

@Mrten
Copy link

Mrten commented May 14, 2013

This patch adds an extra feature for the datasources, check_ds, that decides whether a datasource is to be graphed or not.

It needs to move collect_data() call to outside the if because the data should be available for the config mode of the plugin. If you care about the number of statistics-gathering queries collect_data() should cache the data it retrieves, I haven't because this is really on the edge of my Perl hacking abilities 😃.

It moves the print multigraph..-statement because it should not be printed for graphs that won't be there later on, munin gets rather confused if you do.

--- mysql   2013-05-06 18:26:07.000000000 +0200
+++ mysql.new   2013-05-14 22:29:32.317507777 +0200
@@ -227,13 +228,10 @@
     if ($command eq 'autoconf') {
         return $command_map{$command}->();
     }
     else {
-        if ($command eq 'show') {
-            collect_data();
-        }
+        collect_data();
         for my $graph (sort keys %graphs) {
-            print "multigraph mysql_$graph$instance\n";
             $command_map{$command}->($graph);
         }
     }
     return 0;
@@ -270,8 +268,21 @@

     my %conf = (%{$defaults{global_attrs}}, %{$graph->{config}{global_attrs}});
     $conf{args} .=  ' --no-gridfit --slope-mode';

+    # see if there needs to be some datasource defined
+    if ( defined ($graph->{config}{check_ds})) {
+
+        # if the datasource isn't in the data, skip this graph (query cache not enabled or smt)
+        for my $f ($graph->{config}{check_ds}) {
+            if ( !defined ($data->{$f})) {
+                return;
+            }
+        }
+    }
+
+    print "multigraph mysql_$graph_name$instance\n";
+
     while (my ($k, $v) = each %conf) {
         print "graph_$k $v\n";
     }
     print "graph_category mysql$instance\n";
@@ -301,8 +312,10 @@
 sub show {
     my $graph_name = shift;

     my $graph = $graphs{$graph_name};
+
+    print "multigraph mysql_$graph_name$instance\n";

     die "Can't show data for '$graph_name' because InnoDB is disabled."
         if $graph_name =~ /innodb_/ && $data->{_innodb_disabled};

@kjellm
Copy link
Owner

kjellm commented May 21, 2013

Thanks. Need to think about it. I don't have any time right now, but I will come back to it.

You can use the CHI module (https://metacpan.org/module/JSWARTZ/CHI-0.56/lib/CHI.pm) with the FastMmap driver to cache the results in collect_data().

@kjellm
Copy link
Owner

kjellm commented May 21, 2013

You can see how I used Cache::Cache to achieve this before I changed the plugin to use the multigraph feature: 9c1ed41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants