telegraf icon indicating copy to clipboard operation
telegraf copied to clipboard

[[inputs.systemd_units]] add ActiveEnterTimestamp as field to metric

Open 1tft opened this issue 1 year ago • 4 comments

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

1tft avatar Sep 27 '24 13:09 1tft

Next step: determine if we already query this information or what we need to do to get it.

srebhan avatar Oct 08 '24 19:10 srebhan

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...)

knollet avatar Oct 21 '24 09:10 knollet

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...

srebhan avatar Oct 24 '24 08:10 srebhan

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)))))))

knollet avatar Oct 29 '24 15:10 knollet

@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.

srebhan avatar Dec 10 '24 14:12 srebhan

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!

1tft avatar Dec 10 '24 20:12 1tft