Ejemplo n.º 1
0
 def write_data(self, points):
     try:
         self.influxdb_client.write_points(points, protocol='line')
         self.influxdb_client.close()
         return True
     except requests.exceptions.ConnectionError:
         log.error(':: Entry was not recorded, Influx connection error')
         log.eprint(
             ':: Infpyng :: Entry was not recorded, Influx connection error'
         )
         log.info(':: Sleep time to %s sec' % str(20))
         time.sleep(20)
         return False
Ejemplo n.º 2
0
 def set_logger(self):
     # set globs of all TOML files
     globs = glob.glob(os.path.dirname(self.path) + "/config/*.toml")
     if any("config.toml" in f for f in globs):
         self.config = toml.load(
             os.path.dirname(self.path) + "/config/config.toml")
         logs = self.config['logging']
         if 'path' in logs:
             self.logfile = str(logs['path'])
         # create file if it's not exist
         file_exists = os.path.isfile(self.logfile)
         if not file_exists:
             with open(self.logfile, 'a'):
                 pass
         os.chmod(self.logfile, 0o644)
         # init logging
         log.init_logger(self.logfile)
     else:
         log.error(':: No config file found...exiting')
         log.eprint(':: Infpyng :: No config file found...exiting')
         sys.exit()
Ejemplo n.º 3
0
                round(t_2 - t_1, 2)))
            log.info(':: ---------------------------------------')


if __name__ == "__main__":
    # process pool executor shutdown on signal
    # --> https://stackoverflow.com/a/44163801
    signal.signal(signal.SIGTERM, exit_infpyng)
    signal.signal(signal.SIGINT, exit_infpyng)

    # init Class Infpyng
    core = Infpyng()
    # init Infpyng conf
    core.init_infpyng()
    log.info(':: Settings loaded successfully')
    # init InfluxDB
    influx = Influx()
    # check if InfluxDB is reachable
    if not influx.init_db():
        log.error(":: Can't connect to InfluxDB...exiting")
        log.eprint(":: Infpyng :: Can't connect to InfluxDB...exiting")
        sys.exit()
    log.info(':: Init InfluxDB successfully')
    # start Infpyng poller
    log.info(':: Starting Infpyng Multiprocessing v%s' % core.version)
    log.info(':: Polling time every %ds' % core.poll)
    start_time = time.time()
    while True:
        main()
        time.sleep(core.poll - ((time.time() - start_time) % core.poll))