pvl/rrd/hosts.py
changeset 425 4e828d47421a
parent 235 a34e7260568b
child 428 956b3d4918bb
equal deleted inserted replaced
424:e77e967d59b0 425:4e828d47421a
    51             # host-spec?
    51             # host-spec?
    52             if '=' in host :
    52             if '=' in host :
    53                 host, node = host.split('=')
    53                 host, node = host.split('=')
    54             else :
    54             else :
    55                 node = host
    55                 node = host
       
    56 
       
    57             if '@' in node :
       
    58                 node, node_domain = node.split('@')
       
    59             else:
       
    60                 # as for collectd host
       
    61                 node_domain = domain
    56             
    62             
    57             # host has domain in collectd?
    63             # host has domain in collectd?
    58             if domain :
    64             if domain :
    59                 host = hostjoin(host, domain)
    65                 host = hostjoin(host, domain)
    60 
    66 
    61         if not parts :
    67         if not parts :
    62             # keep host for following lines
    68             # keep host for following lines
    63             continue
    69             continue
    64 
    70 
    65         iface = parts.pop(0)
    71         instance = parts.pop(0)
    66  
    72  
    67         # possibly multiple tags..
    73         # possibly multiple tags..
    68         for tag in parts :
    74         for tag in parts :
    69             yield host, node, iface, tag
    75             yield host, instance, (node_domain, node, tag)
    70 
    76 
    71 def map_interfaces (options, file):
    77 def map_interfaces (options, file):
    72     """
    78     """
    73         Read (hostname, interface}: (nodename, tag) pairs from file.
    79         Read (hostname, instance}: (nodename, tag) pairs from file.
    74     """
    80     """
    75 
    81 
    76     for host, node, iface, tag in load(file) :
    82     for host, instance, node_info in load(file) :
    77         log.debug("%s/%s -> %s/%s", host, iface, node, tag)
    83         log.debug("%s/%s -> %s", host, instance, node_info)
    78         yield (host, iface), (node, tag)
    84         yield (host, instance), node_info
    79 
    85 
    80 def collectd_interfaces (options, file, collectd_domain, collectd_plugin) :
    86 def collectd_interfaces (options, file, collectd_domain, collectd_plugin) :
    81     """
    87     """
    82         Read collectd (host, type-instance, name) items, and yield (collectd-rrd, out-rrd) tuples.
    88         Read collectd (host, instance, (domain, node, tag)) items, and yield (collectd-rrd, node_info) tuples.
    83             
    89             
    84             file                - read host/ports from file
    90             file                - read host/ports from file
    85             collectd_domain     - append given domain to collectd hostname
    91             collectd_domain     - append given domain to collectd hostname
    86             collectd_plugin     - use given collectd plugin's type-instances
    92             collectd_plugin     - use given collectd plugin's type-instances
    87     """
    93     """
    88 
    94 
    89     log.info("scanning %s/<host>.%s/%s/%s-<port>.rrd", options.collectd_rrd, collectd_domain, collectd_plugin, options.collectd_type)
    95     log.info("%s/${host}.%s/%s/%s-${instance}.rrd", options.collectd_rrd, collectd_domain, collectd_plugin, options.collectd_type)
    90 
    96 
    91     for collectd_host, interface_host, port, tag in load(file, domain=collectd_domain) :
    97     for host, instance, node_info in load(file, domain=collectd_domain) :
    92         # flip from DNS-ordering -> path-ordering
       
    93         if options.reverse_host :
       
    94             interface_host = hostreverse(interface_host)
       
    95 
       
    96         if options.collectd_instance == 'type' :
    98         if options.collectd_instance == 'type' :
    97             type = options.collectd_type + '-' + port
    99             type = options.collectd_type + '-' + instance
    98         else :
   100         else :
    99             type = options.collectd_type
   101             type = options.collectd_type
   100 
   102 
   101         if options.collectd_instance == 'plugin' :
   103         if options.collectd_instance == 'plugin' :
   102             plugin = collectd_plugin + '-' + port
   104             plugin = collectd_plugin + '-' + instance
   103         else :
   105         else :
   104             plugin = collectd_plugin
   106             plugin = collectd_plugin
   105 
   107 
   106         collectd_rrd = os.path.join(options.collectd_rrd, collectd_host, plugin, type) + '.rrd'
   108         rrd = os.path.join(options.collectd_rrd, host, plugin, type) + '.rrd'
   107 
   109 
   108         if not os.path.exists(collectd_rrd) :
   110         if not os.path.exists(rrd) :
   109             log.warn("%s/%s: missing collectd rrd: %s", collectd_host, port, collectd_rrd)
   111             log.warn("%s/%s: missing collectd rrd: %s", host, instance, rrd)
   110             continue
   112             continue
   111 
   113 
   112         # out
   114         # out
   113         interface_rrd = os.path.join(interface_host, tag + '.rrd')
   115         log.debug("%s: %s", rrd, node_info)
   114 
   116 
   115         log.debug("%s: %s", interface_rrd, collectd_rrd)
   117         yield rrd, node_info
   116 
       
   117         yield collectd_rrd, interface_rrd