Ejemplo n.º 1
0
sys.stderr.write("connected to kafka\n")

killer = KillerMonitor(args.timeout)
killer.setDaemon(True)
killer.start()
sys.stderr.write("Monitor will kill application if unable to process a message for %d seconds\n" % args.timeout)

webserver = WebServer(args.http_port)
webserver.setDaemon(True)
webserver.start()
sys.stderr.write("Web server running on port %d\n" % args.http_port)

if args.verbose:
    sys.stdout.write("\n")
for message in consumer:
   if message is not None:
        (timestamp,source,data) = message.value.split('|',3)
        values = data.split()
        if(len(values) == 6) and all(is_number(i) for i in values[0:5]):

            (Press,Temp,Cond,Sal,SoundV,Time) = values
            session.execute(
                prepared_insert,(source,timestamp,lat,lon,depth,float(Press),float(Temp),float(Cond),float(Sal),float(SoundV),Time)
            )
            killer.ping()
            webserver.update(message.value)
            if args.verbose:
                sys.stdout.write("\r{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}".format(source,timestamp,Press,Temp,Cond,Sal,SoundV,Time))
                sys.stdout.flush()
Ejemplo n.º 2
0
killer = KillerMonitor(args.timeout)
killer.setDaemon(True)
killer.start()
sys.stderr.write("Monitor will kill application if unable to process a message for %d seconds\n" % args.timeout)

webserver = WebServer(args.http_port)
webserver.setDaemon(True)
webserver.start()
sys.stderr.write("Web server running on port %d\n" % args.http_port)

if args.verbose:
    sys.stdout.write("\n")
for message in consumer:
   if message is not None:
        values = message.value.split(',')
        if(len(values) >= 11) and all(is_number(i) for i in values[2:10]):

            (clock_date, clock_time, temp, cond, salinity, depth, ph, ph_mv, turbidity, do_mgl, battery,dummy) = values
            (dd,mm,yyyy) = clock_date.split('/')
            timestamp = "{0}-{1}-{2}T{3}Z".format(yyyy,mm,dd,clock_time)
            with conn.cursor() as cursor:
                try:
                  cursor.execute("""
                     INSERT INTO mestech (instrument_id, time, site_id, lat, lon, clock_date, clock_time, temp, cond, salinity, depth, ph, ph_mv, turbidity, do_mgl, battery)
                     VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
                            """,
                     (instrument_id,timestamp,site_id,lat,lon,clock_date,clock_time,float(temp),float(cond),float(salinity),
                                 float(depth), float(ph), float(ph_mv), float(turbidity), float(do_mgl), float(battery))
                 )
                except pymssql.IntegrityError:
                  cursor.execute("""
Ejemplo n.º 3
0
killer = KillerMonitor(args.timeout)
killer.setDaemon(True)
killer.start()
sys.stderr.write("Monitor will kill application if unable to process a message for %d seconds\n" % args.timeout)

webserver = WebServer(args.http_port)
webserver.setDaemon(True)
webserver.start()
sys.stderr.write("Web server running on port %d\n" % args.http_port)

if args.verbose:
    sys.stdout.write("\n")
for message in consumer:
   if message is not None:
        (timestamp,source,data) = message.value.split('|',3)
        values = data.split()
        if(len(values) == 7) and all(is_number(i) for i in values[2:]):

            (Date,Time,FluorescenceWavelength,CHLCount,TurbidityWavelength,NTUCount,Thermistor) = values
            CHL = round(0.0181 * (float(CHLCount)-49.0),4);
            NTU = round(0.0483*(float(NTUCount) - 50.0),4);
            session.execute(
                prepared_insert,(source,timestamp,lat,lon,depth,Date,Time,int(FluorescenceWavelength),int(CHLCount),int(TurbidityWavelength),int(Thermistor),int(NTUCount),CHL,NTU)
            )
            killer.ping()
            webserver.update(message.value)
            if args.verbose:
                sys.stdout.write("\r{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}".format(source,timestamp,Date,Time,FluorescenceWavelength,CHLCount,TurbidityWavelength,Thermistor,NTU))
                sys.stdout.flush()