Exemple #1
0
def load_module(module):
    import zipimport
    for _ in range(3):
        try:
            pkg = importlib.import_module(module)
            return pkg
        except zipimport.ZipImportError:
            log_debug('zlib failure for {0}, try again'.format(module))
            time.sleep(0.1)
            pass
Exemple #2
0
    def collect(self):
        """ collect loadavg statistics """
        mod = load_module('linuxcounters.loadavg_metrics_pb2')
        metrics = mod.loadavg_metrics()
        while True:
            set_info_header(metrics.header)

            log_debug('Collecting data for loadavg')
            metrics.one_min_avg, metrics.five_min_avg, metrics.fifteen_min_avg =\
                os.getloadavg()

            log_debug('Sending {0}'.format(metrics))
            yield metrics.SerializeToString()
Exemple #3
0
    def collect(self):
        """ collect process statistics for topn memory"""
        process = self.create_process()
        while True:
            set_info_header(process.header)

            log_debug('Collecting data for topn memory metric')
            proc_list = sorted(self.proc_list, key=self.sort_key, reverse=True)
            sort_order = sequence_generator(1)
            for proc_stat in proc_list[:self.number]:
                process.sort_order = next(sort_order)
                for key, value in proc_stat.items():
                    if hasattr(process, key):
                        setattr(process, key, value)

                log_debug('Sending {0}'.format(process))
                self.send(process.SerializeToString())

            yield
Exemple #4
0
 def stop(self):
     """ stop the data sensor, try to exit gracefully """
     self._exit = True
     self.join(self.interval)
     log_debug('Finished')
Exemple #5
0
                        help='datasensor to run')
    parser.add_argument('-f',
                        '--interval',
                        dest='interval',
                        type=int,
                        default=60,
                        help='interval')
    parser.add_argument('--proto-src',
                        dest='protoSrc',
                        default='./lh_publications.zip',
                        help='directory or file for proto definitions')

    args = parser.parse_args()

    sensor_class = sensor_dict.get(args.datasensor)

    set_proto_src(args.protoSrc)
    try:
        sensor = sensor_class('.'.join([LINUXCOUNTERS, args.datasensor]),
                              interval=args.interval,
                              handler=print_handler)

        log_info('Starting...')
        #        sensor.run()
        sensor.start()
        time.sleep(10)
        sensor.stop()

    except KeyboardInterrupt:
        log_debug('Control-C pressed, exit ...')