| 1 |  |  | # -*- coding: utf-8 -*- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | __author__ = 'Kenny Freeman' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | __email__ = '[email protected]' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | __license__ = "ISCL" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | __docformat__ = 'reStructuredText' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | from collections import deque | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | import plumd | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | import plumd.plugins | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | from plumd.plugins.readers.linux.proc.conntrack import Conntrack | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | from plumd.plugins.readers.linux.proc.diskstats import DiskStats | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | from plumd.plugins.readers.linux.proc.loadavg import LoadAverage | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | from plumd.plugins.readers.linux.proc.mem import Mem | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | from plumd.plugins.readers.linux.proc.netdev import NetDev | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | from plumd.plugins.readers.linux.proc.netsnmp import NetSnmp | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | from plumd.plugins.readers.linux.proc.netstat import Netstat | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | from plumd.plugins.readers.linux.proc.sockstat import SockStat | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | from plumd.plugins.readers.linux.proc.stat import Stat | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | from plumd.plugins.readers.linux.proc.swap import Swap | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | from plumd.plugins.readers.linux.proc.uptime import Uptime | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | from plumd.plugins.readers.linux.proc.vmstat import VmStat | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | classes = [Conntrack, DiskStats, LoadAverage, Mem, NetDev, NetSnmp, Netstat, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |            SockStat, Stat, Swap, Uptime, VmStat] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | class Proc(plumd.plugins.Reader): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     """Plugin to measure various kernel metrics from /proc.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     defaults = { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         'poll.interval': 10, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         'disabled_readers': [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     def __init__(self, log, config): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         """Plugin to measure various kernel metrics from /proc. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         :param log: A logger | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         :type log: logging.RootLogger | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         :param config: a plumd.config.Conf configuration helper instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         :type config: plumd.config.Conf | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         """ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         super(Proc, self).__init__(log, config) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         config.defaults(Proc.defaults) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         self.readers = deque() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         disabled = config.get('disabled_readers') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         for cls in classes: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             if cls.__name__ in disabled: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 msg = "Proc: skipping disabled reader: {0}" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 self.log.warn(msg.format(cls.__name__)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                 continue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             self.log.debug("Proc: initializing reader: {0}".format(cls.__name__)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             self.readers.append(cls(log, config)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |     def poll(self): | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |         """Poll for kernel metrics under /proc. | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |         :rtype: ResultSet | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |         """ | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |         ret = plumd.ResultSet([]) | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |         for rdr in self.readers: | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |             ret.add_list(rdr.check()) | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |         return ret | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |  |