Ankündigung

Einklappen
Keine Ankündigung bisher.

Influx: MQTT einlesen Problem

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    Influx: MQTT einlesen Problem

    nachdem ich langsam in HAOS einsteige möchte ich die Daten die ich länger benötige in Influx speichern.

    Die ersten Daten funktionieren schon (HAOS-> Influx) bzw MQTT->Influx (wenn die Daten als int oder float vorhanden sind).

    Wo ich seit Tagen herumwurschtel: die Daten sind als String vorhanden und ich kann sie nicht importieren

    MQTT: Topic: SHRDZM/807D3A37863A/807D3A37863A/sensor
    {
    "timestamp":"2025-10-31T10:39:50",
    "32.7.0":"236.10",
    "52.7.0":"234.70",
    "72.7.0":"235.30",
    "31.7.0":"2.50",
    "51.7.0":"2.00",
    "71.7.0":"1.12",
    "1.7.0":"0",
    "2.7.0":"17",
    "1.8.0":"9929432",
    "2.8.0":"19417831",
    "3.8.0":"692170",
    "4.8.0":"7045923",
    "16.7.0":"-17",
    "uptime":"0003:09:38:02",
    "UTC":"2025-10-31T09:39:53"
    }​
    # Configuration for telegraf agent
    [agent]
    interval = "10s"
    round_interval = true
    metric_batch_size = 1000
    metric_buffer_limit = 10000
    collection_jitter = "0s"
    flush_interval = "10s"
    flush_jitter = "0s"
    precision = ""
    hostname = ""
    omit_hostname = false
    debug = true

    [[outputs.influxdb_v2]]
    urls = ["http://localhost:8086"]
    token = "xxxxxxxxxxxxxxxxxxxxxxxxx"
    organization = "Hoe"
    bucket = "Smartmeter"
    # Read metrics from MQTT topic(s)
    [[inputs.mqtt_consumer]]
    servers = ["tcp://192.168.10.214:1883"]
    topics = [
    "SHRDZM/807D3A37863A/807D3A37863A/sensor",
    ]

    ## Username and password to connect MQTT server.
    #username = "KNX"
    password = "KNX"
    ## Data format to consume.
    #data_format = "json"# Read metrics from MQTT topic(s)
    ## The message topic will be stored in a tag specified by this value. If set
    ## to the empty string no topic tag will be created.
    # topic_tag = "topic"
    # qos = 0
    # client_trace = true
    # data_format = "xpath_json"
    username = "KNX"
    password = "KNX"

    ## Data format to use for messages
    #name_override = "Smartmeter"
    data_format = "json"
    data_type = "int"
    [[processors.converter]]
    [processors.converter.tags]
    measurement = []
    string = []
    integer = []
    unsigned = []
    boolean = []
    float = []
    [processors.converter.fields]
    measurement = []
    tag = []
    string = []
    integer = ["1,7,0","2.7.0"]
    float = ["31.7.0","51.7.0"]
    unsigned = []
    boolean = []
    timestamp = ["timestamp"]
    timestamp_format = "2006-01-02T15:04:05"​
    Output auf der Konsole:
    Code:
    telegraf --config http://192.168.50.133:8086/api/v2/telegrafs/0fb9500b80a11000
    2025-10-31T09:41:52Z I! Loading config: http://192.168.50.133:8086/api/v2/telegrafs/0fb9500b80a11000
    2025-10-31T09:41:52Z I! Starting Telegraf 1.36.3 brought to you by InfluxData the makers of InfluxDB
    2025-10-31T09:41:52Z I! Available plugins: 239 inputs, 9 aggregators, 35 processors, 26 parsers, 65 outputs, 6 secret-stores
    2025-10-31T09:41:52Z I! Loaded inputs: mqtt_consumer
    2025-10-31T09:41:52Z I! Loaded aggregators:
    2025-10-31T09:41:52Z I! Loaded processors: converter
    2025-10-31T09:41:52Z I! Loaded secretstores:
    2025-10-31T09:41:52Z I! Loaded outputs: influxdb_v2
    2025-10-31T09:41:52Z I! Tags enabled: host=influxdb
    2025-10-31T09:41:52Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"influxdb", Flush Interval:10s
    2025-10-31T09:41:52Z W! [agent] The default value of 'skip_processors_after_aggregators' will change to 'true' with Telegraf v1.40.0! If you need the current default behavior, please explicitly set the option to 'false'!
    2025-10-31T09:41:52Z D! [agent] Initializing plugins
    2025-10-31T09:41:52Z D! [agent] Connecting outputs
    2025-10-31T09:41:52Z D! [agent] Attempting connection to [outputs.influxdb_v2]
    2025-10-31T09:41:52Z D! [agent] Successfully connected to outputs.influxdb_v2
    2025-10-31T09:41:52Z D! [agent] Starting service inputs
    2025-10-31T09:41:52Z I! [inputs.mqtt_consumer] Connected [tcp://192.168.10.214:1883]
    2025-10-31T09:42:02Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics​
    Daten sind aber keine im Bucket....

    wo mache ich den Fehler?
    Ich habe alle möglichen Versionen (json_2) usw probiert, aber überall das gleiche Dilemma....
    EPIX
    ...und möge der Saft mit euch sein...
    Getippt von meinen Zeigefingern auf einer QWERTZ Tastatur

    #2
    Code:
    #"timestamp":"2025-10-30T14:37:10",
    #"32.7.0":"235.20",
    #"52.7.0":"234.70",
    #"72.7.0":"234.10",
    #"31.7.0":"2.40",
    #"51.7.0":"0.46",
    #"71.7.0":"1.16",
    #"1.7.0":"5",
    #"2.7.0":"0",
    #"1.8.0":"9908035",
    #"2.8.0":"19417825",
    #"3.8.0":"691269",
    #"4.8.0":"7033757",
    #"16.7.0":"5",
    #"uptime":"0002:13:35:22",
    #"UTC":"2025-10-30T13:37:14"
    ## Data format to use for messages
    #name_override = "Smartmeter"
      persistent_session = false
      data_format = "json_v2"
     #[[inputs.mqtt_consumer.topic_parsing]]
     #   topic =  "SHRDZM/807D3A37863A/807D3A37863A/sensor"
      
      [[inputs.mqtt_consumer.json_v2]]
    #    measurement_name = "sensor"
        timestamp_path = "timestamp"
        timestamp_format = "2006-01-02T15:04:05"
                    [[inputs.mqtt_consumer.json_v2.field]]
                            path = "31.7.0"
                            type = "float"
                    [[inputs.mqtt_consumer.json_v2.field]]
                            path = "51.7.0"
                            type = "float"
                    [[inputs.mqtt_consumer.json_v2.field]]
                            path = "1.7.0"
                            type = "int"​
    EPIX
    ...und möge der Saft mit euch sein...
    Getippt von meinen Zeigefingern auf einer QWERTZ Tastatur

    Kommentar


      #3
      Hallo,

      das klingt nach 'nem nervigen Telegraf-Parser-Kampf – kenn ich von meinen ersten Influx-Versuchen, Strings sind da echt zickig. Hast du mal den [[processors.strings]] oder einen custom JSON-Parser mit "string_fields" probiert? So was wie:

      [[processors.parser]] parse_fields = ["timestamp", "uptime", "UTC"] data_format = "json_string_fields"

      Könnte die Strings als fields packen. Oder liegt's am timestamp_format? Zeig mal 'ne Konfig-Variante, dann guck ich mit.

      Viel Erfolg, du schaffst das!


      Kommentar


        #4
        Zeig mal 'ne Konfig-Variante, dann guck ich mit.
        wie meinst du das?
        Sorry, bin echt neu bei Influx/telegraf...

        die restlichen prozessor-zeilen sind auskommentiert

        Code:
        [[processors.parser]] parse_fields = ["timestamp", "uptime", "UTC"] data_format = "json_string_fields"​
        bringt:
        loading config file http://192.168.50.133:8086/api/v2/te...b9500b80a11000 failed: error parsing parser, adding parser failed: undefined but requested parser: json_string_fields

        die Änderung auf data_format = "unix"​

        bringt den Fehler ->undefined but requested parser: unix, also liegt das Problem in der Anweisung data_format = "json_string_fields"​....

        das Beispiel in der Doku (https://docs.influxdata.com/telegraf...lugins/parser/) weist allerdings auf die Version v1.8 hin, ich habe
        InfluxDB v2.7.12Server: ec9dcdeFrontend: 5c07739​ InfluxDB v2.7.12Server: ec9dcdeFrontend: 5c07739 zz0.mpfi71dxbq9zz Telegraf 1.36.3
        da sollte ich telegraf updaten, oder?
        Code:
        root@influxdb:~# sudo apt-get update
        Hit:1 http://deb.debian.org/debian bookworm InRelease
        Get:2 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]    
        Get:3 http://security.debian.org bookworm-security InRelease [48.0 kB]      
        Get:4 https://repos.influxdata.com/debian stable InRelease [6,907 B]        
        Get:5 http://security.debian.org bookworm-security/main amd64 Packages [284 kB]
        Get:6 https://repos.influxdata.com/debian stable/main amd64 Packages [20.7 kB]
        Fetched 415 kB in 2s (170 kB/s)    
        Reading package lists... Done
        root@influxdb:~# sudo apt-get install telegraf
        Reading package lists... Done
        Building dependency tree... Done
        Reading state information... Done
        telegraf is already the newest version (1.36.3-1)​
        telegraf is already the newest version (1.36.3-1) ??
        Zuletzt geändert von EPIX; 01.11.2025, 11:22.
        EPIX
        ...und möge der Saft mit euch sein...
        Getippt von meinen Zeigefingern auf einer QWERTZ Tastatur

        Kommentar


          #5
          Code:
          [[processors.converter]]
            [processors.converter.fields]
              integer = ["1.7.0"]
              float = ["71.7.0"]​
          funktioniert auch nicht....
          EPIX
          ...und möge der Saft mit euch sein...
          Getippt von meinen Zeigefingern auf einer QWERTZ Tastatur

          Kommentar


            #6
            ich glaube ich habe das Problem eingegrenzt:

            telegraf akzeptiert ein Punkt (.) nicht als gültigen Tag.... obwohl der Punkt im Tag (zumindest laut https://jsonlint.com/) zulässig ist.

            einfache Testmöglichkeit:
            Code:
            # Configuration for telegraf agent
            
            [[outputs.file]]
              files = ["stdout", "/root/.testdata/test.out"]
              data_format = "influx"
              influx_max_line_bytes = 0
              influx_sort_fields = false
              influx_uint_support = false
            
            # Example taken from: https://github.com/influxdata/telegraf/issues/7097
             [[inputs.file]]
                files = ["/root/.testdata/input.json"]
                data_format = "json_v2"
                [[inputs.file.json_v2]]
            # Parse int types from JSON
            [[inputs.file]]
                files = ["/root/.testdata/input.json"]
                data_format = "json_v2"
                [[inputs.file.json_v2]]
                    [[inputs.file.json_v2.field]]
                    rename = "explicitinttypeName"
                    path = "explicitinttype"
                    type = "int"
                    [[inputs.file.json_v2.field]]
                    rename = "convertstringtointName"
                    path = "convertstringtoint"
                    type = "int"
                    [[inputs.file.json_v2.field]]
                    rename = "converttesttointName"
                    path = "1_1"
                    type = "int"
            Input.conf
            Code:
            {
                "convertinttostring": 1,
                "explicitinttype": 1,
                "defaultinttype": 2,
                "convertstringtoint": "4",
                "1_1": "5",
                "1.1": "6"
            }​
            erzeigt das korrekte Ergebnis:
            Code:
            Loading config: http://192.168.50.133:8086/api/v2/telegrafs/0fbe34fe86283000
            file,host=influxdb explicitinttypeName=1i,convertstringtointName=4i,converttesttointName=5i 1762165918000000000​
            wenn derpath in der config von path = "1_1" auf path = "1.1" geändert wird:
            could not parse "/root/.testdata/input.json": the path "1.1" doesn't exist
            kann ich das Problem irgendwie "umgehen", den MQTT Output kann ich leider nicht ändern...
            Zuletzt geändert von EPIX; 03.11.2025, 11:52.
            EPIX
            ...und möge der Saft mit euch sein...
            Getippt von meinen Zeigefingern auf einer QWERTZ Tastatur

            Kommentar

            Lädt...
            X