Self developed metricbeat module throws in docker a strange error

I developed a metricbeat module and metricset. I ran "mage update" and "mage build" and tested it in my VM and it ran perfectly.
I then zipped the following files, copied dit to another VM (Ubuntu as well) and started it and it ran perfectly:

tar zcvf my_module.tar.gz module/my_module \
   fields.yml metricbeat.reference.yml \
   metricbeat.yml modules.d/my_module.yml metricbeat

Btw. my module has the name "My_module" and my metricset has the name file_mon.

Ok, then I wanted to containerize it, to deploy it with the following dockerfile:

FROM ubuntu:18.04 

RUN mkdir -p /metricbeat/modules.d
RUN apt update
RUN apt -y upgrade

COPY metricbeat /metricbeat
COPY metricbeat.yml /metricbeat
COPY metricbeat.reference.yml /metricbeat
COPY fields.yml /metricbeat
COPY modules.d/my_module.yml /metricbeat/modules.d/my_module.yml

CMD cd /metricbeat && ./metricbeat -e -d "*"

Now this is the strange part:

I always get this error message:

{"log.level":"error","@timestamp":"2022-04-04T20:44:10.000Z","log.origin":{"":"runtime/panic.go","file.line":221},"message":"recovered from panic while fetching 'my_module/file_mon' for host 'localhost'. Recovering, but please report this.","":"metricbeat","error":{"message":"runtime error: invalid memory address or nil pointer dereference"},"stack":"\n\\nruntime.gopanic\n\truntime/panic.go:1038\nruntime.panicmem\n\truntime/panic.go:221\nruntime.sigpanic\n\truntime/signal_unix.go:735\*MetricSet).Fetch\n\\*metricSetWrapper).fetch\n\\*metricSetWrapper).startPeriodicFetching\n\\*metricSetWrapper).run\n\\*Wrapper).Start.func1\n\","ecs.version":"1.6.0"}

The crazy part is this: when I copy the system.yml module configfile and enable it and when i disable "my_module", the error does not appear.

Has anyone experience with self written metricbeat modules and discovered the same error? Again, i can deploy the zip file to any machine and it runs smoothly. Even if i use another docker base image like centos:7 or i am running into the same problem. the current version of metricbeat for the development environment is

./metricbeat version
metricbeat version 8.3.0 (amd64), libbeat 8.3.0 [7e22a97892a86d42a2d8966e70b942d564a32d69 built 2022-04-04 18:46:01 +0000 UTC]

Help is very appreciated


I close the topic, since the problem has been solved.
The panic was caused by a call on Go object, that was nil.
To be more precise, i tried to read statistics of a file that was not existing.

See my journey here.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.