question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Help with influxdb service.....

See original GitHub issue

I’ve been contributing to yet another service…somethign that takes all my docker containers and pushes them out via mqtt…specifically it has the memory used and cpu of each container. (https://github.com/psyciknz/docker2mqtt)

Now I’d like to get than in influx, and though about using the mqttwarn influxdb service.

Here’s the example of a bunch of topics that I generate:

sensors/d2m/Melkor/logspout/name logspout
sensors/d2m/Melkor/logspout/image micahhausler/logspout:gelf
sensors/d2m/Melkor/logspout/status running
sensors/d2m/Melkor/logspout/state on
sensors/d2m/Melkor/logspout/memoryused 6.738
sensors/d2m/Melkor/logspout/memorylimit 10.0
sensors/d2m/Melkor/logspout/netinput 0.93359375
sensors/d2m/Melkor/logspout/netoutput 223.0
sensors/d2m/Melkor/logspout/blockinput 18.4
sensors/d2m/Melkor/logspout/blockoutput 0.0
sensors/d2m/Melkor/logspout/memory 6.738MiB / 10MiB
sensors/d2m/Melkor/logspout/cpu 0.84%
sensors/d2m/Melkor/logspout/netio 956kB / 223MB

Of note is that Melkor is a server…this will change depending on the docker host. logspout is the container. This is an example of a container on each hose.

Ideally I’d want the memory used and cpu to go into an influx db with the server,container the measurement and the value.

I can’t quite rememember what I should have for fields and tags for this. Field is the cpu, and the tags are the server and container?

Anyway, not specifically an mqttwatrn issue, but might be a fun exercise…if I have to I’ll write to influx directly from the new service.

I’ve got the following for the config:

; -----------------------------------------
;             Docker2mqtt
; -----------------------------------------
; Docker 2 mqtt
[docker 2 mqtt]
;sensors/d2m/Melkor/d2mqtt/cpu 2.15%
topic = sensors/d2m/Melkor/#
targets = log:info, influxdb:docker2mqtt
format = server=Melkor,container= value=

Where I’m specifically setting the server, but if I could pull from sensors/d2m/# it would be better.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jpmenscommented, Sep 30, 2021

If a srv can be the 2nd parameter the we might need to update some documentation to show that

I believe there are examples in our documentation.

Glad you got it all going with @jacques42’s help. I’ll now close.

1reaction
jacques42commented, Jun 24, 2021

I don’t really see why the topic matches from your mqttwarn.ini config, so I am a bit puzzled. I think what it should look like see below (but please adjust to exactly match, in case needed).

I also notice you want to take on key / values from the payload, so we need to slightly change the approach to use the alldata function, please notice this change:

[sensors/d2m/+/+]
alldata= docker2mqtt_alldata()
targets = log:info, influxdb:docker2mqtt
format = container={name},server={host} cpu={cpu},memory={memoryused}

and the alldata function - you need to change the mqttwarn logging settings to DEBUG in the ini file, in order to see output from that in the logs:

def docker2mqtt_alldata(topic, data, srv):
    if type(topic) == str:
        try:
            # sensors/d2m/Melkor/paradoxpaiv2
            parts = topic.split('/')
            host = parts[2]
            srv.logging.debug("*** docker2mqt_alldata(): host %s", host)
        except:
            host = 'unknown'
            container = 'unknown'
            return dict(host=host, container=container)

   jsondata = json.loads(data["payload"])
   cpu = jsondata["cpu"]
   container = jsondata["name"]
   memoryused = jsondata["memoryused"]
   srv.logging.debug("*** docker2mqt_alldata(): cpu %s container name %s memoryused %s", cpu, container, memoryused)

   return dict(host=host, name=container, cpu=cpu, memoryused=memoryused)

Note that I adjusted the config right here in Github and did not try this out so apologize if there is syntax errors or anything.

Read more comments on GitHub >

github_iconTop Results From Across the Web

InfluxData Support
Need further assistance? If you weren't able to find what you were looking for, you can contact us via our Community page or...
Read more >
InfluxData Services and Support Program
InfluxData services team is available to help ; InfluxData Support. Assistance using and troubleshooting InfluxDB ; InfluxData Training. Find all the resources ...
Read more >
InfluxData Support
InfluxData offers a full range of Support options across our product portfolio, each with different capabilities and service levels. Get self-service help ......
Read more >
Support Policy - InfluxData
VP of Customer Success and Technical Services: 415-295-1901 x22. 2. Support Services specific to Software. 2.1 InfluxDB Enterprise certified ...
Read more >
Get started with InfluxDB | InfluxDB OSS 2.6 Documentation
Start collecting, querying, processing, and visualizing data in InfluxDB OSS. ... The UI is packaged with InfluxDB and runs as part of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found