def connect():
    try:
        global client
        client = InfluxDBClient(host='influxdb', port=8086, database="MyTData")
        loggerHelper.getLogger().info("Connected to InfluxDB")
    except:
        loggerHelper.getLogger().info("Error Connecting to InfluxDB")
Example #2
0
def connect():
    try:
        global client
        client = MongoClient('mongodb', 27017)

    except:
        loggerHelper.getLogger().info("Error Connecting to MongoDB")

    if client is None:
        loggerHelper.getLogger().info("Error Connecting to MongoDB")
def main(data):
    # Perform data processing here
    loggerHelper.getLogger().info("Processing")

    # All data in the dict data will be saved to the database
    return data

####--Main Function--####

####--Add Custom Functions Below--####
def do_work(connection, channel, delivery_tag, body):
    thread_id = threading.get_ident()
    fmt1 = 'Thread id: {} Delivery tag: {} Message body: {}'
    loggerHelper.getLogger().info(fmt1.format(thread_id, delivery_tag, body))

    body = json.loads(body)
    body["data"] = dp.main(body["data"])
    db.writeData(body)

    cb = functools.partial(ack_message, channel, delivery_tag)
    connection.add_callback_threadsafe(cb)
def writeData(body):
    global client
    json_body = [{
        "measurement": body["measurement"],
        "tags": {
            "device": body["sensor"],
        },
        "time": datetime.datetime.now(),
        "fields": {}
    }]

    json_body[0]["fields"] = body["data"]
    loggerHelper.getLogger().info("Inserting Data:" + str(json_body))
    client.write_points(json_body)
Example #6
0
def writeData(body):
    
    global client
    db = client["MyTData"]
    col = db[body["measurement"]]

    json_body = {
            "device" : body["sensor"],
            "date" : datetime.datetime.now(),
            "data": body["data"]
    }

    loggerHelper.getLogger().info("Inserting Data:" + str(json_body))
    col.insert_one(json_body)
Example #7
0
def connect():
    global client
    try:
        client = psycopg2.connect(host="timescaledb", user="******", password="******", database="mytdata")
    except Exception as e:
        loggerHelper.getLogger().info(e)
        loggerHelper.getLogger().info("Error Connecting to Timescale")

    if client is None:
        loggerHelper.getLogger().info("Error Connecting to Timescale")
Example #8
0
def connect():
    global client
    try:
        client = mysql.connector.connect(host="mysqldb",
                                         user="******",
                                         passwd="",
                                         database="MyTData")
    except Exception as e:
        loggerHelper.getLogger().info(e)
        loggerHelper.getLogger().info("Error Connecting to MySQL")

    if client is None:
        loggerHelper.getLogger().info("Error Connecting to MySQL")
Example #9
0
def writeData(body):
    global client
    data=body["data"]
    date=datetime.datetime.now()
    varnames = ""
    formatting = ""
    vals = ()
    for key, value in data.items():
        varnames = varnames + key + ","
        formatting = formatting + "%s,"
        vals = vals + (value,)
    varnames = varnames + "ts"
    formatting = formatting + "%s"
    vals = vals + (date,)
    loggerHelper.getLogger().info(varnames)
    loggerHelper.getLogger().info(vals)

    command = "INSERT INTO sensordata (" + varnames + ") VALUES (" + formatting + ")"
    loggerHelper.getLogger().info(command)

    client.cursor().execute(command, vals)

    client.commit()
def main(data):
    # Perform data processing here
    loggerHelper.getLogger().info("Processing")

    # All data in the dict data will be saved to the database
    return data