Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(input): add upsd implementation #9890

Merged
merged 20 commits into from
Jul 6, 2022
Merged

Conversation

Malinskiy
Copy link
Contributor

Required for all PRs:

Fixes #6316

Added an input plugin to gather upsd metrics using a forked golang library Malinskiy/go.nut from robbiet480/go.nut. Fork is needed to support network timeouts. The metrics are mimicking the apcupsd input plugin as close as possible to allow users to reuse existing dashboards.

@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Oct 8, 2021

Thanks so much for the pull request!
🤝 ✒️ Just a reminder that the CLA has not yet been signed, and we'll need it before merging. Please sign the CLA when you get a chance, then post a comment here saying !signed-cla

@telegraf-tiger telegraf-tiger bot added fix pr to fix corresponding bug new plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Oct 8, 2021
@Malinskiy
Copy link
Contributor Author

!signed-cla

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Malinskiy, thanks for this nice plugin! I have some comments in the code... Please think about querying only a single server with the plugin as this will reduce the complexity quite dramatically. You can still collect multiple servers by duplicating the plugin entry in the config file.

go.mod Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd_test.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd_test.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd_test.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd_test.go Outdated Show resolved Hide resolved
@srebhan srebhan added area/system and removed fix pr to fix corresponding bug labels Oct 11, 2021
@srebhan srebhan self-assigned this Oct 11, 2021
@Malinskiy Malinskiy requested a review from srebhan October 12, 2021 08:59
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick adaptation! Some more comments from my side, the biggest question being why you are not using the upstream version of go.nut?

plugins/inputs/upsd/README.md Outdated Show resolved Hide resolved
plugins/inputs/upsd/README.md Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
"serial": fmt.Sprintf("%v", metrics["device.serial"]),
"ups_name": name,
//"variables": variables.Status not sure if it's a good idea to provide this
"model": fmt.Sprintf("%v", metrics["device.model"]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use fmt.Sprintf if not necessary. This way we will notice if the protocol changes (which should never happen actually).

plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd_test.go Outdated Show resolved Hide resolved
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice update @Malinskiy! This only leaves us with the fmt.Sprintfs and the restructuring of the tests. Furthermore, I want to ask you to split the status flags and add them as separate tags instead of a field...

plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
@srebhan
Copy link
Member

srebhan commented Oct 18, 2021

@Malinskiy any chance to work on this? I'm eagerly waiting for this plugin to use with my UPS... :-)

@Malinskiy
Copy link
Contributor Author

I will resume work on this when I have more time: have a conference talk to prepare to.
Might have time during the weekend (fingers crossed)

@srebhan
Copy link
Member

srebhan commented Oct 19, 2021

@Malinskiy perfect. Just wanted to let you know your PR is appreciated. :-)

@Malinskiy
Copy link
Contributor Author

With the fmt.Sprintf - it's either this or a type cast. If you really want to break in case there is a protocol change - let me know, otherwise I'd leave the fmt.Sprintf call and the breaking behaviour becomes just an incorrect metric

@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Nov 8, 2021

@Malinskiy Malinskiy requested a review from srebhan November 11, 2021 01:13
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Malinskiy thanks for the nice update. I think the code is pretty close now, however, I think the remaining fmt.Sprintfs should be removed and replace by proper "casting".

Furthermore, depending on your fork for this plugin is not something we should do as telegraf would then rely on a single person maintaining an external library. Therefore we try to avoid using forked version of libraries wherever possible. I want to ask you to either upstream your changes or to not rely on your modifications and switch to the upstream go.nut library.

plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
@Malinskiy
Copy link
Contributor Author

Removed timeout handling as requested, upstream version is used. Keep in mind that upstream version does 2 additional network requests each time it connects, namely VER and NETVER, the result of those requests is completely ignored by the upstream library so it's an unnecessary overhead.

Sidenote: I am running the forked version of go.nut since October without any issues.

@AdamLeyshon
Copy link

Exciting! 🎉

@kiwimato
Copy link

kiwimato commented Jul 1, 2022

@srebhan @Malinskiy any update on this one ? I can't wait to get rid of the python scripts I currently use and send UPS data with Telegraf instead :)
Thanks for all the work btw, super cool stuff.

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I only have one comment about the naming of the ups.status field. Can you please solve this and I think we are ready to go...

plugins/inputs/upsd/upsd.go Outdated Show resolved Hide resolved
@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Jul 5, 2022

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you very much @Malinskiy for keeping this PR alive!

I will fix the sample.conf once this is merged...

@srebhan srebhan added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Jul 5, 2022
@reimda reimda merged commit fbccc71 into influxdata:master Jul 6, 2022
@reimda
Copy link
Contributor

reimda commented Jul 6, 2022

Thanks @Malinskiy!

@ostueker
Copy link

ostueker commented Jul 7, 2022

@srebhan

Isn't da5fdad missing the

[[inputs.upsd]]

Header?

#11463

@srebhan
Copy link
Member

srebhan commented Jul 7, 2022

@ostueker you are right. This is due to the changed way of how the sample configuration is handled now. Can you please open an issue and assign it to me or at least mention me? I'll fix the plugin today then...

@srebhan
Copy link
Member

srebhan commented Jul 7, 2022

@ostueker please check #11471 and let me know (there) if this fixes the issue!

@karelkryda
Copy link

Hi,
I'm using docker version 1.23.3. According to the date of merging this PR, the plugin should already be available, but it is not.
Am I doing something wrong, or will the plugin only be available in the next version?

Thank you in advance

@AdamLeyshon
Copy link

AdamLeyshon commented Aug 2, 2022 via email

@karelkryda
Copy link

karelkryda commented Aug 2, 2022

It doesn't look like it's been released yet unless you build your own from master

Aug 2, 2022 13:11:06 Karel Krýda @.***>:

Hi,
I'm using docker version 1.23.3. According to the date of merging this PR, the plugin should already be available, but it is not.
Am I doing something wrong, or will the plugin only be available in the next version?

Thank you in advance

the sample telegraf configuration contains a sample of this plugin, but for some reason the plugin itself is not part of the current version 1.23.3 despite the fact that it was released 8 days ago and this plugin was merged 28 days ago.

@amigthea
Copy link

amigthea commented Aug 2, 2022

It doesn't look like it's been released yet unless you build your own from master
Aug 2, 2022 13:11:06 Karel Krýda @.***>:

Hi,
I'm using docker version 1.23.3. According to the date of merging this PR, the plugin should already be available, but it is not.
Am I doing something wrong, or will the plugin only be available in the next version?
Thank you in advance

the sample telegraf configuration contains a sample of this plugin, but for some reason the plugin itself is not part of the current version 1.23.3 despite the fact that it was released 8 days ago and this plugin was merged 28 days ago.

If I have to guess the documentation is updated between minor release and plugins like this between main release like a 1.24 maybe? I'm waiting too for this to be implemented

@powersj
Copy link
Contributor

powersj commented Aug 2, 2022

New plugins are generally not added to bug-fix releases. This will be released in v1.24.0.

We have nightly packages, archives, and docker images for users who want to jump-start on what is available. We appreciate when users do run these nightly images to catch issues earlier, but the typical warnings about the fact that they are nightlies apply.

@calebj
Copy link

calebj commented Nov 16, 2022

I'm having an issue with mixed types on battery_charge_percent and load_percent. It would seem my APC rack UPSes (Smart-UPS X 2000) which are polled via SNMP report both as float, but the USB HID driver for my Eatons (5S LCD) pass them as integers. Not exactly sure where to report this since it seems to be a NUT behavior that go.nut just passes on to the plugin. But honestly, I don't see a reason not to cast most of the parameters pulled by this plugin to float.

Also, I'm considering a patch to report power draw, but since both vendors also report that differently, I want to test the waters here for whether that's in the scope of the plugin. The APCs give me output voltage and current, and don't distinguish between reactive and apparent power, even though load% for both is available in the web UI. The Eaton, however, gives ups.power, ups.realpower and output voltage, but no current. I'm curious if anyone has different models to compare, because this already seems like a mess.

@srebhan
Copy link
Member

srebhan commented Nov 16, 2022

@calebj can you please open an issue (best is one per topic) to discuss on how to go on from here!?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/system new plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NUT - Network UPS Tools Plug-in