ArthurMitchell42 / nutcase

A NUT and APCd UPS data conversion bridge and graphic UI to link to both Prometheus metrics and JSON format for HomePage/Uptime Kuma etc.
https://arthurmitchell42.github.io/nutcase/
GNU General Public License v3.0
25 stars 2 forks source link

New GUI #23

Closed adm2k closed 8 months ago

adm2k commented 8 months ago

Hello Arthur,

Well after a bit of work expanding the disk size of my NUT/NUTCase VM (was out of space) I have got NUTCase 0.3.0 Beta 4 installed.

And, I apologize if I am not understanding but, how do I access the new GUI? I am assuming it must be in the config file somewhere.

Thanks, Al

adm2k commented 8 months ago

OK, I have it operational - I read the docs a little more in depth :)

No data being displayed so I'm working on that now...

adm2k commented 8 months ago

Well no success yet: image

nutcase.yml settings: log_level: info order_metrics: True coloured_log: True default_log_lines: 20 server_port: 9995

servers:

ArthurMitchell42 commented 8 months ago

Hi Al, As a first step, try browsing to http://(nutcase-ip)?addr=192.168.86.24&dev=apcmain and see if it reads the UPS. The message and yellow triangle indicate that it's not picking up the server information from the config file, but lets go step by step first.

adm2k commented 8 months ago

http://192.168.86.24/?addr=192.168.86.24&dev=apcmain

give me the default Apache page

ArthurMitchell42 commented 8 months ago

Sorry, I missed the port out: http://(nutcase-ip):9995?addr=192.168.86.24&dev=apcmain

adm2k commented 8 months ago

That gives me this: image

adm2k commented 8 months ago

from the log: 2024-01-21 10:32:01,567 DEBUG cache_control: In cache but expired 2024-01-21 10:32:01,609 DEBUG nut_server_handler: List_State NUT_Query_List_State.ENDED 2024-01-21 10:32:01,619 DEBUG nut_server_handler: List_State NUT_Query_List_State.ENDED 2024-01-21 10:32:01,660 DEBUG nut_server_handler: List_State NUT_Query_List_State.ENDED 2024-01-21 10:32:01,661 DEBUG nut_server_handler: Scrape successful. 2024-01-21 10:32:01,662 DEBUG scrape: Get_Scrape_Data: Scrape_Data {'nutcase_version': 'NUTCase 0.3.0 Beta 4', 'server_version': '2.8.0', 'server_address': '192.168.86.24', 'server_port': 3493, 'mode': 'nut', 'ups_list': [{'name': 'apcmain', 'description': 'Description unavailable', 'variables': [{'name': 'battery.charge', 'value': '100'}, {'name': 'battery.charge.low', 'value': '10'}, {'name': 'battery.charge.warning', 'value': '50'}, {'name': 'battery.date', 'value': '2001/09/25'}, {'name': 'battery.mfr.date', 'value': '2022/04/30'}, {'name': 'battery.runtime', 'value': '2500'}, {'name': 'battery.runtime.low', 'value': '120'}, {'name': 'battery.type', 'value': 'PbAc'}, {'name': 'battery.voltage', 'value': '13.6'}, {'name': 'battery.voltage.nominal', 'value': '12.0'}, {'name': 'device.mfr', 'value': 'American Power Conversion'}, {'name': 'device.model', 'value': 'Back-UPS ES 600M1'}, {'name': 'device.serial', 'value': '4B2217P05773 '}, {'name': 'device.type', 'value': 'ups'}, {'name': 'driver.name', 'value': 'usbhid-ups'}, {'name': 'driver.parameter.bus', 'value': '002'}, {'name': 'driver.parameter.pollfreq', 'value': '30'}, {'name': 'driver.parameter.pollinterval', 'value': '1'}, {'name': 'driver.parameter.port', 'value': 'auto'}, {'name': 'driver.parameter.product', 'value': 'Back-UPS ES 600M1 FW:928.a9 .D USB FW:a9'}, {'name': 'driver.parameter.productid', 'value': '0002'}, {'name': 'driver.parameter.serial', 'value': '4B2217P05773'}, {'name': 'driver.parameter.synchronous', 'value': 'auto'}, {'name': 'driver.parameter.vendor', 'value': 'American Power Conversion'}, {'name': 'driver.parameter.vendorid', 'value': '051D'}, {'name': 'driver.version', 'value': '2.8.0'}, {'name': 'driver.version.data', 'value': 'APC HID 0.98'}, {'name': 'driver.version.internal', 'value': '0.47'}, {'name': 'driver.version.usb', 'value': 'libusb-1.0.26 (API: 0x1000109)'}, {'name': 'input.sensitivity', 'value': 'medium'}, {'name': 'input.transfer.high', 'value': '139'}, {'name': 'input.transfer.low', 'value': '92'}, {'name': 'input.voltage', 'value': '120.0'}, {'name': 'input.voltage.nominal', 'value': '120'}, {'name': 'ups.beeper.status', 'value': 'enabled'}, {'name': 'ups.delay.shutdown', 'value': '20'}, {'name': 'ups.firmware', 'value': '928.a9 .D'}, {'name': 'ups.firmware.aux', 'value': 'a9 '}, {'name': 'ups.load', 'value': '18'}, {'name': 'ups.mfr', 'value': 'American Power Conversion'}, {'name': 'ups.mfr.date', 'value': '2022/04/30'}, {'name': 'ups.model', 'value': 'Back-UPS ES 600M1'}, {'name': 'ups.productid', 'value': '0002'}, {'name': 'ups.realpower.nominal', 'value': '330'}, {'name': 'ups.serial', 'value': '4B2217P05773 '}, {'name': 'ups.status', 'value': 'OL'}, {'name': 'ups.test.result', 'value': 'No test initiated'}, {'name': 'ups.timer.reboot', 'value': '0'}, {'name': 'ups.timer.shutdown', 'value': '-1'}, {'name': 'ups.vendorid', 'value': '051d'}, {'name': 'nutcase.battery.runtime', 'value': '00:41'}, {'name': 'nutcase.ups.load.watts', 'value': '59.4'}, {'name': 'nutcase.ups.status', 'value': 'On-Line'}], 'clients': [], 'server_address': '192.168.86.24', 'server_port': 3493}], 'debug': ['VER\n', 'Network UPS Tools upsd 2.8.0 - http://www.networkupstools.org/\n', 'LIST UPS', 'BEGIN LIST UPS', 'UPS apcmain "Description unavailable"', 'END LIST UPS', 'LIST VAR apcmain', 'BEGIN LIST VAR apcmain', 'VAR apcmain battery.charge "100"', 'VAR apcmain battery.charge.low "10"', 'VAR apcmain battery.charge.warning "50"', 'VAR apcmain battery.date "2001/09/25"', 'VAR apcmain battery.mfr.date "2022/04/30"', 'VAR apcmain battery.runtime "2500"', 'VAR apcmain battery.runtime.low "120"', 'VAR apcmain battery.type "PbAc"', 'VAR apcmain battery.voltage "13.6"', 'VAR apcmain battery.voltage.nominal "12.0"', 'VAR apcmain device.mfr "American Power Conversion"', 'VAR apcmain device.model "Back-UPS ES 600M1"', 'VAR apcmain device.serial "4B2217P05773 "', 'VAR apcmain device.type "ups"', 'VAR apcmain driver.name "usbhid-ups"', 'VAR apcmain driver.parameter.bus "002"', 'VAR apcmain driver.parameter.pollfreq "30"', 'VAR apcmain driver.parameter.pollinterval "1"', 'VAR apcmain driver.parameter.port "auto"', 'VAR apcmain driver.parameter.product "Back-UPS ES 600M1 FW:928.a9 .D USB FW:a9"', 'VAR apcmain driver.parameter.productid "0002"', 'VAR apcmain driver.parameter.serial "4B2217P05773"', 'VAR apcmain driver.parameter.synchronous "auto"', 'VAR apcmain driver.parameter.vendor "American Power Conversion"', 'VAR apcmain driver.parameter.vendorid "051D"', 'VAR apcmain driver.version "2.8.0"', 'VAR apcmain driver.version.data "APC HID 0.98"', 'VAR apcmain driver.version.internal "0.47"', 'VAR apcmain driver.version.usb "libusb-1.0.26 (API: 0x1000109)"', 'VAR apcmain input.sensitivity "medium"', 'VAR apcmain input.transfer.high "139"', 'VAR apcmain input.transfer.low "92"', 'VAR apcmain input.voltage "120.0"', 'VAR apcmain input.voltage.nominal "120"', 'VAR apcmain ups.beeper.status "enabled"', 'VAR apcmain ups.delay.shutdown "20"', 'VAR apcmain ups.firmware "928.a9 .D"', 'VAR apcmain ups.firmware.aux "a9 "', 'VAR apcmain ups.load "18"', 'VAR apcmain ups.mfr "American Power Conversion"', 'VAR apcmain ups.mfr.date "2022/04/30"', 'VAR apcmain ups.model "Back-UPS ES 600M1"', 'VAR apcmain ups.productid "0002"', 'VAR apcmain ups.realpower.nominal "330"', 'VAR apcmain ups.serial "4B2217P05773 "', 'VAR apcmain ups.status "OL"', 'VAR apcmain ups.test.result "No test initiated"', 'VAR apcmain ups.timer.reboot "0"', 'VAR apcmain ups.timer.shutdown "-1"', 'VAR apcmain ups.vendorid "051d"', 'END LIST VAR apcmain', 'LIST CLIENT apcmain', 'BEGIN LIST CLIENT apcmain', 'END LIST CLIENT apcmain']} 2024-01-21 10:32:01,662 WARNING gui_data_format: Could not find device ups scrape data

ArthurMitchell42 commented 8 months ago

Could you post the whole logfile as an attached file please? Thanks

adm2k commented 8 months ago

attached... nutcase log.txt

ArthurMitchell42 commented 8 months ago

That log file seems to come from 1st January and only has a few entries in it, is there another one maybe?

adm2k commented 8 months ago

I will check. I need to step away for a bit. I will send another as soon as I can

adm2k commented 8 months ago

I just checked the log for today Jan 21 12:57 nutcase.log and there is nothing for today in it.

adm2k commented 8 months ago

also, see this in the GUI image

adm2k commented 8 months ago

latest log attached nutcase.log

ArthurMitchell42 commented 8 months ago

Morning, I see a couple of issues here, firstly I see that the config file in use isn't the one you intended. The log shows that the config file contents contains only a rework section:

rework:
  - from: battery.runtime
    to: nutcase.battery.runtime
    style: time
    control: "%H:%M"
  -from: ups.status
   to: nutcase.ups.status
   style: simple-enum
   control:
    - from: [ "OL CHRG", "OL", "OB", "LB", "CHRG", "RB", "FSD", "BYPASS", "SD", "CP", "BOOST", "OFF" ]
      to: [ "Charging", "On-Line", "On-Bat", "Low-Bat", "Charging", "Replace-Bat", "Force-Shutdown", "Bypass", "Shutdown", "On-Line", "Boost", "Off" ]
      default: Other
  - from: ups.load
    to: nutcase.ups.load.watts
    style: ratio
    control: ups.realpower.nominal

Could you check and make sure the contents in use are this please:

rework:
  - from: battery.runtime
    to: nutcase.battery.runtime
    style: time
    control: "%H:%M"
  -from: ups.status
   to: nutcase.ups.status
   style: simple-enum
   control:
    - from: [ "OL CHRG", "OL", "OB", "LB", "CHRG", "RB", "FSD", "BYPASS", "SD", "CP", "BOOST", "OFF" ]
      to: [ "Charging", "On-Line", "On-Bat", "Low-Bat", "Charging", "Replace-Bat", "Force-Shutdown", "Bypass", "Shutdown", "On-Line", "Boost", "Off" ]
      default: Other
  - from: ups.load
    to: nutcase.ups.load.watts
    style: ratio
    control: ups.realpower.nominal
settings:
  log_level: debugvv
  order_metrics: True
  coloured_log: True
  default_log_lines: 20
servers:
  - server: "192.168.86.24"
    port: 3493
    device: 'apcmain'
    default: true
    power: 550
    name: 'APC BE600M1'

You can check the config in use by clicking the logs icon (clipboard with pulse just right of the house icon on the tool bar, selecting nutcase.yml (or .yaml) from the File drop down menu and selecting All on the Lines drop down.

Finally looking closely this might be an issue with the browser or settings. I'm not sure which one you are using but could you look at the console output (in FireFox and Chrome this can be accessed with F12) select console and press control-F5 to reload. If there are any warnings shown, could you screen shot the whole line or copy-paste it please?

It should look a bit like this: image

ArthurMitchell42 commented 8 months ago

Could I also suggest stopping the container, removing all log or unwanted config files and re-starting the container as this will help give a base line with all known information? Regards, Arthur

adm2k commented 8 months ago

Morning,

One quick question, where should the nutcase.yml be located? /docker/nutcase or /docker/nutcase/config

adm2k commented 8 months ago

For some reason I am seeing this now: image

and on the Hompage getting this: image

adm2k commented 8 months ago

OK, I removed all the logs, restarted Docker and the log shows this: 2024-01-22 07:08:02,131 ERROR configuration: Error loading Control YAML while parsing a block collection in "/app/app/../../config/nutcase.yml", line 2, column 3 expected , but found '?' in "/app/app/../../config/nutcase.yml", line 6, column 3 2024-01-22 07:08:02,131 INFO init: nutcase starting. version 0.3.0 beta 4, logging level debug

ArthurMitchell42 commented 8 months ago

Yes, my error, the YAML wasn't quite aligned correctly:

rework:
  - from: battery.runtime
    to: nutcase.battery.runtime
    style: time
    control: "%H:%M"
  - from: ups.status
    to: nutcase.ups.status
    style: simple-enum
    control:
      from: [ "OL CHRG", "OL", "OB", "LB", "CHRG", "RB", "FSD", "BYPASS", "SD", "CP", "BOOST", "OFF" ]
      to: [ "Charging", "On-Line", "On-Bat", "Low-Bat", "Charging", "Replace-Bat", "Force-Shutdown", "Bypass", "Shutdown", "On-Line", "Boost", "Off" ]
      default: Other
  - from: ups.load
    to: nutcase.ups.load.watts
    style: ratio
    control: ups.realpower.nominal
settings:
  log_level: debugvv
  order_metrics: True
  coloured_log: True
  default_log_lines: 20
servers:
  - server: "192.168.86.24"
    port: 3493
    device: 'apcmain'
    default: true
    power: 550
    name: 'APC BE600M1'
adm2k commented 8 months ago

Still working on this.

There were minor issues in the yml file you sent me indentions etc. I have corrected them and run it through a yml checker, no errors. However after stopping and restarting docker I am still getting this: 2024-01-22 07:35:43,183 INFO configuration: Config file not found as either .yml or .yaml /app/app/../../config/nutcase.yml 2024-01-22 07:35:43,184 INFO init: nutcase starting. version 0.3.0 beta 4, logging level debug

the file is located at docker/nutcase/config image

ArthurMitchell42 commented 8 months ago

The config file lives at the directory which is mapped to the container path /config so if you run the container with:

-v /some/path/nutcase:/config

then it goes in the host path /some/path/nutcase and if you run it with

-v /some/path/nutcase/config:/config

then it lives in the host machine at some/path/nutcase/config

ArthurMitchell42 commented 8 months ago

The 502 error was caused by the configuration, I'll add checks to the configuration loader to trap that.

adm2k commented 8 months ago

This is my docker run command, which shows pointing to the correct config file location I believe

docker run -d --name NUTCase -v /docker/nutcase:/config -e TZ=America/New_York -p 9995:9995 --restart always kronos443/nutcase:V0.3.0Beta4

ArthurMitchell42 commented 8 months ago

In that case the file must be placed in the host computer directory /docker/nutcase

adm2k commented 8 months ago

It's working now!

Many thanks for your patience as I am somewhat new with Linux and Docker.

Your project is great! The ability to use with Homepage and now the new GUI make for an excellent tool for monitoring NUT.

I wish there was a convenient way to promote this to the NUT community.

Thank you again!

al

ArthurMitchell42 commented 8 months ago

Thanks Al, this has been a useful exchange, I've caught several bugs while looking at this. Sorry for the delay in answering, we had a big storm come through the country last night and I didn't want to risk having computers on when the power was flickering out! The fixes from this are worth pushing out so I'll do a beta 5 tonight. In future you can pull the tag latest-beta to keep up to date with fixes.

adm2k commented 8 months ago

Yes, we have freezing cold weather here in the Southeast, was down to 14 degrees F the other night and 20 right now at 9am in Atlanta, GA. Not typical weather for us here. Stay warm and dry!

ArthurMitchell42 commented 8 months ago

Thanks Al, do you have a screen shot of it going? (Just for satisfaction)

adm2k commented 8 months ago

Here you go. Renders nicely on a small screen (cell phone) as well. image

Question, what is the "sounder" for? I have no speakers on the computer I use at the moment. The option to turn on or off is not available.

adm2k commented 8 months ago

Arthur,

Some observations on this great new GUI!

1 - Is this something I need to address? image

2 - When hovering over items in the toolbar should there be any "tool tips"? image

3 - When looking at the file drop down it might be nice to see a time stamp next to the file - if possible. image

4 - Can new pages open in a new tab? Maybe be a configurable option. image

A couple of questions:

1 - How often is data refreshed? Is this configurable?

2 - As you can see from the above image I now have ten logs, is there some sort of log rotation in play?

3 - I may have mentioned this earlier (and I know you are busy) but what is the "Sounder" In my case it shows as enabled but the options to disable are not available. The PC I am using has no speakers. image

4 - Does the page do any sort of auto refresh?

By the way, I have linked the GUI page to my Homepage NUT widget so I can go directly to the new GUI. JUst clicking on the top section of the widget above the details. image

None of this is urgent, whenever you find you have nothing to do (ha ha) you can review . No rush on my end.

Many thanks! Al

ArthurMitchell42 commented 8 months ago

Al, What a great set of observations, that you for those. Taking them in order:

  1. There is nothing to be concerned about. When I initially coded the GUI I wanted to go for consistency between the GUI, JSON and metrics end points, which always require parameters, and the thinking was that would be a better user experience. Now I've used it for a while I think this warning is miss placed. The GUI functions as a stand-alone feature and if a default server is specified in the config file then that should just be used silently. I think this warning should only appear if incorrect parameters are used to load the GUI. The other practical issue is that I anticipate 90% of users to have only a single UPS device and therefore the default action should be to work directly with that one device without complicating the URL.

  2. At the moment there aren't any tool tips for the tool bar icons the way there are on icons in the status block and gauges/charts. There were two reasons for this decision, first the helper system I use (bootstrap) does support tool tips but they aren't very configurable. This results in rather large, clunky, pop ups which I feel get in the way on small items. The other factor is that tool tips aren't touch friendly. Let me look at this again and see if I can get a visually workable solution.

  3. Times are a good idea, I do have a concern that a date/time stamp will be too long and clutter the menu so for now I'll look at using human readable info (such '4 hours', 'yesterday', 'last week' etc.)

  4. Good catch, opening in a new tab should be the default behaviour.

Other things,

  1. The data refreshes at 30 second intervals. Right now that is fixed, giving a history of 30 minutes for the charts. I decided to leave this as-is for now since the logic and code to add more flexibility is heavily tied up with the next stage of development, which is to free up from the limitation of being request-event driven, only being a data provider on demand and start logging the data internally without needing an end point to be called such as /json or /metrics. This change is approximately the same amount of effort as adding the GUI and it makes a lot of sense to break the development path into more achievable mile stones rather than shoot for the moon in one step. (My project manager side coming out!)

  2. There is log rotation in place, each file is allowed to grow to 250KB before being rotated and the limit of old copies is 10. While it wouldn't be difficult to add a configuration option to change this I wasn't sure if there was a demand to do so. That's one of those things I might do in the back ground. Do you feel the default settings are problematic?

  3. The sounder displays whether the speaker in the UPS enclosure, not the viewing computer, is enabled, disabled or (if your device supports it) muted. The only way to change this setting is on the front panel of the UPS or by using the NUT-tools upscmd utility or other manufacturer provided software. Theoretically I could add a feature to change this setting from NUTCase however it would require holding login credentials for the NUT server to allow a remote SSH link into it which is a potential security issue and also reasonably complex to set up on the server side for some users. Another concern is the degree of control you can have over the device using this command utility. In many cases you could trigger situations such as battery tests which could impair system performance or instantly shut off the power outlets. Even if this were inadvertently done there may be legal implications of loss and damages. This is an area I need to steer clear of.

  4. The data is reloaded every 30 seconds, I'm not sure what other refresh would be required?

I've done the same thing, linking the homepage href to NUTCase GUI, that’s pretty sweet! I wish the homepage team would engage with the idea of styling the label text though, it just makes sense as they already have a method to provide custom CCS.

adm2k commented 8 months ago

Good day,

Thanks for the detailed response.

1 I understand and no problem.

2 No problem on the "tool tips" I think after using it for awhile now I know what they all are anyway. :)

3 I think the "human readable info (such '4 hours', 'yesterday', 'last week' etc." might be helpful if not too much work to implement. It would give some indication as to the time frame of the file.

4 Implementing opening in a new tab would be great.

As far as "the other things" -

I understand your responses but do have one concern. I have disabled the beeper on my APC UPS but the page shows as Sounder as enabled. Thoughts?

Thanks again! al...

ArthurMitchell42 commented 8 months ago

Al,

Looking back through the diagnostic data you've sent I see that your device is sending this variable:

VAR apcmain ups.beeper.status "enabled",

This would explain why NUTCase says it's enabled. I think there are two possibilities, first the beeper might not have been disabled or got re-enabled by some other software or secondly it could be a bug in the UPS software causing it to be miss-reported.

This isn't the first time I've seen this, my own CyberPower CP900 has a really annoying bug where the reported output voltage is clearly wrong and jumps up and down at random. This is obviously a glitch in how some register value is being read and sent but the fact they didn't catch that during their V&V phase or offer a firmware upgrade after release is very disappointing. I feel it speaks negatively about their product quality.

adm2k commented 8 months ago

I will into this further, thanks again.

al

ArthurMitchell42 commented 8 months ago

I've added the features we discussed about and pushed it as Beta 6. Let me know what you think of the tool tips.

19

adm2k commented 8 months ago

New features are working perfectly and look great! Many thanks again!!

For some reason I lost my "status" after the new install. I will research further. image

al

ArthurMitchell42 commented 8 months ago

Yes, I corrected an error whereby rework statements with problems were not being filtered out. If you restart the container and look at the log I suspect you will find a logged error to reflect this.

I think you posted your rework as:


      from: [ "OL",      "OB",     "LB",      "CHRG",     "RB", "FSD", "BYPASS"]
      to: [   "On-Line", "On-Bat", "Low-Bat", "Charging", "Rep"]

If this is what you have then this isn't quite right, the arrays have to be the same length. Try this instead:

      from: [ "OL CHRG",  "OL",      "OB",     "LB",      "CHRG",     "RB",          "FSD",            "BYPASS", "SD",       "CP",      "BOOST", "OFF" ]
      to: [   "Charging", "On-Line", "On-Bat", "Low-Bat", "Charging", "Replace-Bat", "Force-Shutdown", "Bypass", "Shutdown", "On-Line", "Boost", "Off" ]
adm2k commented 8 months ago

Guess I can't see the forest for all the trees! :)

Yaml checker giving me this: I have looked at it until my eyes are crossing...

image

ArthurMitchell42 commented 8 months ago

In this example the checker is telling you that the indenting is incorrect. The highlighted line should be indented more as should the line below and you will need to add the default keyword also.

adm2k commented 8 months ago

OK, all fixed. Thank you again!!!

Now off to make an eye Doctor appointment :)