[[inputs.systemd_units]] add ActiveEnterTimestamp as field to metric
Use Case
We want to know when a systemd service has been restarted. So knowing unix timestamp of this "event" would be very usefull.
Expected behavior
[[inputs.systemd_units]] should add ActiveEnterTimestamp as metric field. It is available via D-Bus API
Actual behavior
[[inputs.systemd_units]] does not output "ActiveEnterTimestamp" information, not even with details = true
Additional info
No response
Next step: determine if we already query this information or what we need to do to get it.
I would recommend just fetching everything systemd exposes via dbus else tomorrow somebody else needs the one value you didn't fetch. If I read it correctly, that shouldn't really produce any more load, because you get them all, anyway.
https://github.com/influxdata/telegraf/blob/master/plugins/inputs/systemd_units/systemd_units_linux.go#L389 Here you choose some specifically, but you could just iterate over them and add them all, couldn't you? (ok, might be a problem they're renamed...)
What we might do is to add a setting where the user can specify additional information to collect. The only thing is the different naming conventions. I have to look into converting CamelCase to snake_case...
I have this in my ~/.emacs.d:
;; stolen from https://stackoverflow.com/questions/9288181/converting-from-camelcase-to-in-emacs
(defun toggle-camelcase-snakecase ()
"Toggle between camelcase and underscore notation for the symbol at point."
(interactive)
(save-mark-and-excursion
(let* ((bounds (bounds-of-thing-at-point 'symbol))
(start (car bounds))
(end (cdr bounds))
(currently-using-underscores-p (progn (goto-char start)
(re-search-forward "_" end t))))
(if currently-using-underscores-p
(progn
(upcase-initials-region start end)
(replace-string "_" "" nil start end)
(downcase-region start (1+ start)))
(replace-regexp "\\([A-Z]\\)" "_\\1" nil (1+ start) end)
(downcase-region start (cdr (bounds-of-thing-at-point 'symbol)))))))
@1tft and @knollet please test the binary in PR #16287, available as soon as CI finished the tests, and let me know if that fixes the issue.
With this new telegraf build I could produce new field "active_enter_timestamp_us" for desired services. So it looks very good for us - thank you!