Can't monitor services properly using [[inputs.systemd_units]]

Hello, i have experienced some strange behavior while trying to monitor services on another server. I have created tick script named systemd_units_task.tick to monitor status of systemd services.

I am using Influxdb 1.8.6 with Kapacitor OSS 1.5.9 on same Debian 10 machine. On host1 is installed Telegraf 1.20.2 .

When i start kapacitor task systemd_units_task i get one series with current state of ntp.service unit:


and i get slack message. But when i stop ntp.service (with command “systemctl stop ntp”) second series appear:



As i understood how streams on kapacitor works, second series should not appear. It should change first series, not add another for different status.
Kapacitor is able to catch that new line and send me a slack notification, but when i start service again it won’t alert me that service is started.
Only thing that is changed is value of “time” field in series like this:



And every time i start or stop service only “time” field is updated and both series remain even if there is no value for one of them.

I am not sure if this is issue for Telegraf but i have tested another tick script which measures cpu load on host1 and it worked perfectly fine.
Also i have tested batch and saw same behavior.


dbrp "telegraf"."autogen"

                .where(lambda: "load" != 'not-found')
                .where(lambda: "host" == 'host1')
                .where(lambda: "name" == 'ntp.service')
                .id('{{ index .Tags "host" }}-{{ index .Tags "name" }}')
                .message('{{ .ID }} - has status: {{ index .Tags "active" }}.')
                .warn(lambda: "active_code" == 2)
                .crit(lambda: "active_code" == 3)

Telegraf configuration on host “host1”:


flush_interval = "10s"
flush_jitter = "10s"
interval = "10s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
precision = ""
debug = false
quiet = false
logfile = "/var/log/telegraf/telegraf.log"
hostname = ""
omit_hostname = false

urls = ["https://influx"]
database = "telegraf"
retention_policy = ""
write_consistency = "any"
timeout = "5s"
username = "user"
password = "password"
user_agent = "telegraf"
ssl_ca = "/etc/telegraf/ca.pem"
ssl_cert = "/etc/telegraf/cert.pem"
ssl_key = "/etc/telegraf/key.pem"
insecure_skip_verify = false
content_encoding = "gzip"

ignore_fs = ["tmpfs", "devtmpfs", "devfs", "squashfs"]
timeout = "5s"
unittype = "service"
pattern = "nginx* ntp* ssh* logrotate* influx* syncflux* kapacitor* snap* mysql*"