Skip to content

Commit

Permalink
Import rrdtool as needed instead of globally
Browse files Browse the repository at this point in the history
  • Loading branch information
conorbranagan committed Apr 10, 2012
1 parent 75914e9 commit afd5420
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions checks/cacti.py
Expand Up @@ -2,7 +2,6 @@
from checks import Check, gethostname
from fnmatch import fnmatch
import os
import rrdtool
import time

class Cacti(Check):
Expand Down Expand Up @@ -93,8 +92,10 @@ def _format_metric_name(self, m_name, cfunc):
except KeyError:
return "cacti.%s.%s" % (m_name.lower(), aggr)

def _consolidation_funcs(self, rrd_path):
def _consolidation_funcs(self, rrd_path, rrdtool):
''' Determine the available consolidation functions for this rrd '''
import rrdtool

info = rrdtool.info(rrd_path)
funcs = []
for k,v in info.items():
Expand All @@ -103,8 +104,10 @@ def _consolidation_funcs(self, rrd_path):
return funcs

def _read_rrd(self, rrd_path, host_name, device_name):
import rrdtool

metrics = []
c_funcs = self._consolidation_funcs(rrd_path)
c_funcs = self._consolidation_funcs(rrd_path, rrdtool)
start = self.last_ts.get(rrd_path, 0)

for c in c_funcs:
Expand Down Expand Up @@ -155,7 +158,7 @@ def check(self, agentConfig):

try:
import rrdtool
except:
except ImportError:
self.logger.exception("Cannot import rrdtool")
return False

Expand Down

0 comments on commit afd5420

Please sign in to comment.