Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Thomas Herrmann

    NEWS

    • Wir empfehlen: Node.js 22.x

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 3
    • Best 0
    • Groups 1

    Thomas Herrmann

    @Thomas Herrmann

    Starter

    0
    Reputation
    4
    Profile views
    3
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Thomas Herrmann Follow
    Starter

    Latest posts made by Thomas Herrmann

    • RE: Frage : Migrate MySQL nach Influxdb

      @ullij Danke, aber das habe ich vorher natürlich schon versucht.
      Die Änderung stammt von @JackGruber [https://forum.iobroker.net/topic/12482/frage-migrate-mysql-nach-influxdb/36]

      posted in ioBroker Allgemein
      Thomas Herrmann
      Thomas Herrmann
    • RE: Frage : Migrate MySQL nach Influxdb

      @ullij
      Wünsch dir ebenso ein frohes Neues.
      Es bezieht sich auf das Skript in deinem Post vom 14. Apr. 2020, 20:42: [https://forum.iobroker.net/topic/12482/frage-migrate-mysql-nach-influxdb/26](Link Adresse)

      Aber vielleicht hat ja noch jemand eine Idee, woran es liegen kann.

      posted in ioBroker Allgemein
      Thomas Herrmann
      Thomas Herrmann
    • RE: Frage : Migrate MySQL nach Influxdb

      @ullij Erstmal vielen Dank..

      Ich musste das Skript leicht anpassen auf sqlite, hab jetzt aber einen Fehler, der mit der Anpassung selbst eigentlich nichts zu tun hat:

      ### MySQL DB info ###
      #import MySQLdb
      #conn = MySQLdb.connect(host="localhost",  # your host, usually localhost
      #                     user="john",         # your username
      #                     passwd="megajonhy",  # your password
      #                     db="jonhydb")        # name of the data base
       
       
      ### PostgreSQL DB info ###
      #import psycopg2
      #import psycopg2.extras
      import sqlite3
       
      #####
      # connection data for PostgreSQL
      #conn = psycopg2.connect("dbname=xxx user=xxx password=xxx host=xxx.xxx.xxx.xxx port =5432")
      #####
      
      conn = sqlite3.connect('/opt/iobroker/iobroker-data/sqlite/sqlite.db')
      
      # InfluxDB info #
      from influxdb import InfluxDBClient
      #
      #####connection data for InfluxDB#####
      influxClient = InfluxDBClient(host='localhost', port=8086, username='xxxx', password='xxxx!', database='xxxx')
      #####
      #influxClient.delete_database(influx_db_name)
      #influxClient.create_database(influx_db_name)
       
      # dictates how columns will be mapped to key/fields in InfluxDB
      schema = {
          "time_column": "time", # the column that will be used as the time stamp in influx
          "columns_to_fields" : ["ack","q", "from","value"], # columns that will map to fields 
          # "columns_to_tags" : ["",...], # columns that will map to tags
          "table_name_to_measurement" : "name", # table name that will be mapped to measurement
          }
       
      '''
      Generates an collection of influxdb points from the given SQL records
      '''
      def generate_influx_points(records):
          influx_points = []
          for record in records:
              #tags = {}, 
              fields = {}
              #for tag_label in schema['columns_to_tags']:
              #   tags[tag_label] = record[tag_label]
              for field_label in schema['columns_to_fields']:
                  if field_label == "ack":
                      record[field_label] = bool(record[field_label])
                  fields[field_label] = record[field_label]
              influx_points.append({
                  "measurement": record[schema['table_name_to_measurement']],
                  #"tags": tags,
                  "time": record[schema['time_column']],
                  "fields": fields
              })
          return influx_points
       
      # query relational DB for all records
      curr = conn.cursor()
      # curr = conn.cursor(dictionary=True)
      #####
      # SQL query for PostgreSQL, syntax for MySQL differs
      # query provide desired columns as a view on the sql server
       
      # request data from SQL, adjust ...from <view name>
      curr.execute("Select * from xxx;")
      #####
      row_count = 0
      # process 1000 records at a time
      while True:
          print("Processing row #" + str(row_count + 1))
          selected_rows = curr.fetchmany(1000)
          influxClient.write_points(generate_influx_points(selected_rows))
          row_count += 1000
          if len(selected_rows) < 1000:
              break
      conn.close()
      

      Fehler:

      user@UbuntuHomeAutomation2:~$ python3 sql2influx3.py
      Processing row #1
      Traceback (most recent call last):
        File "sql2influx3.py", line 75, in <module>
          influxClient.write_points(generate_influx_points(selected_rows))
        File "sql2influx3.py", line 50, in generate_influx_points
          record[field_label] = bool(record[field_label])
      TypeError: tuple indices must be integers or slices, not str
      user@UbuntuHomeAutomation2:~$
      
      

      Vielleicht hat ja jemand ne Lösung.

      posted in ioBroker Allgemein
      Thomas Herrmann
      Thomas Herrmann
    Community
    Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
    The ioBroker Community 2014-2023
    logo