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

lm_sensors: fix invalid json if specified more than one chip #2226

Merged
merged 1 commit into from
Jan 12, 2024

Conversation

lasers
Copy link
Contributor

@lasers lasers commented Dec 28, 2023

Config chips worked perfectly before we switched from -u Raw output to -j Json output.

The issue is that sensor -j does not always output valid json with multiple chips.

If you specify multiple chips using wildcard, you get valid json.

❯ sensors -j '*-pci-*'
{
   "nvme-pci-0b00":{
      "Adapter": "PCI adapter",
      "Composite":{
         "temp1_input": 27.850,
         "temp1_max": 79.850,
         "temp1_min": -5.150,
         "temp1_crit": 84.850,
         "temp1_alarm": 0.000
      }
   },
   "amdgpu-pci-0c00":{
      "Adapter": "PCI adapter",
      "vddgfx":{
         "in0_input": 1.112
      },
      "vddnb":{
         "in1_input": 0.837
      },
      "edge":{
         "temp1_input": 32.000
      },
      "PPT":{
         "power1_input": 18.000
      }
   },
   "k10temp-pci-00c3":{
      "Adapter": "PCI adapter",
      "Tctl":{
         "temp1_input": 38.875
      }
   }
}

If you specify multiple chips individually, you don't get valid json.

❯ sensors -j asus-isa-0000 k10temp-pci-00c3 nvme-pci-0b00
{
   "asus-isa-0000":{
      "Adapter": "ISA adapter",
      "cpu_fan":{
         "fan1_input": 800.000
      }
   }
}
{
   "k10temp-pci-00c3":{
      "Adapter": "PCI adapter",
      "Tctl":{
         "temp1_input": 40.125
      }
   }
}
{
   "nvme-pci-0b00":{
      "Adapter": "PCI adapter",
      "Composite":{
         "temp1_input": 27.850,
         "temp1_max": 79.850,
         "temp1_min": -5.150,
         "temp1_crit": 84.850,
         "temp1_alarm": 0.000
      }
   }
}

This dirty fix is a workaround to deal with invalid json lm-sensors/lm-sensors#372.

Ought to close #2224.

@mlmatlock
Copy link
Contributor

Patch worked good.

20231228_12h00m37s_grim

Got an added benefit of getting the GPU fan colored:

20231228_12h02m38s_grim

The remaining fans in the whole image are also from the NCT6793 sensor (along with MoBo and CPU temp in first image).

I'm guessing that it doesn't particularly care to call the same sensor twice.

Not a show stopper; this actually fixed my original request (getting drives colorized). anything else is probably out-of-scope.

Thanks, @lasers!!!!

@lasers
Copy link
Contributor Author

lasers commented Dec 28, 2023

You should try putting everything in one config... For starters, go with chips = ["drivetemp-scsi-*", "*-*"] ... this ought to place your drivetemp chips in first before any other chips now...

I might add -i <file> support to this module in order to simplify troubleshooting with other people's sensor json outputs.

Your issue with fans... I think it may be already fixable by fixing up your sensors.conf https://github.com/lm-sensors/lm-sensors/blob/master/etc/sensors.conf.eg.... You need to add min values higher than 0.000.... Otherwise, it just uses default font color.

EDIT: Your issue with fans not being colorized... is due to values. There is nothing to compare against. You can try changing them with color_excl_input = pink or so.

@lasers
Copy link
Contributor Author

lasers commented Dec 28, 2023

This fan have min (over zero) and/or max.... This get auto colorized.

      "fan1":{
         "fan1_input": 2055.000,
         "fan1_min": 0.000,
         "fan1_max": 3600.000
      },

This fans doesn't have min (over zero) and/or max.... This doesn't get auto colorized.

      "CHA_FAN1":{
         "fan1_input": 1106.000,
         "fan1_min": 0.000,
         "fan1_alarm": 0.000,
         "fan1_beep": 0.000,
         "fan1_pulses": 2.000
      },
      "CPU_FAN":{
         "fan2_input": 1800.000,
         "fan2_min": 0.000,
         "fan2_alarm": 0.000,
         "fan2_beep": 0.000,
         "fan2_pulses": 2.000
      },
      "M_2_FAN":{
         "fan3_input": 0.000,
         "fan3_min": 0.000,
         "fan3_alarm": 0.000,
         "fan3_beep": 0.000,
         "fan3_pulses": 2.000
      },
      "AIO_PUMP":{
         "fan5_input": 1434.000,
         "fan5_min": 0.000,
         "fan5_alarm": 0.000,
         "fan5_beep": 0.000,
         "fan5_pulses": 2.000
      },
      "CHA_FAN2":{
         "fan6_input": 1162.000,
         "fan6_min": 0.000,
         "fan6_alarm": 0.000,
         "fan6_pulses": 2.000
      },

EDIT: Try color_excl_input = color_good (or good, I don't remember).

@mlmatlock
Copy link
Contributor

Ok. So the machine idled for a couple of hours this afternoon, and no matter what I tried, this is the current output:

20231228_20h49m35s_grim

Here's my updated config:

lm_sensors {
    chips = ["nct6793-*", "*-pci-*", "drivetemp-*"]
    format_sensor = '[\?if=name=motherboard MoBo: ]'
    format_sensor += '[\?if=name=cpu CPU: ]'
    format_sensor += '[\?if=name=edge GPU: ]'
    format_sensor += '[\?if=name=composite NVMe: ]'
    format_chip = '[\?if=name=drivetemp-scsi-0-0 sda: ]'
    format_chip += '[\?if=name=drivetemp-scsi-2-0 sdb: ]'
    format_chip += '[\?if=name=drivetemp-scsi-4-0 sdc: ]'
    format_chip += '{format_sensor}'
    format_sensor += '[\?color=auto.input {input:.0f}°C]'
    sensors = ['samsung*', 'hitachi*', 'input', 'composite', 'edge', 'motherboard', 'cpu']
    }
    lm_sensors {
    format_chip = '{format_sensor}'
    format_sensor = '[\?if=name=fan1 GPU fan: ]'
    format_sensor += '[\?if=name=aio_pump Pump: ]'
    format_sensor += '[\?if=name=cpu_fan CPU Fan: ]'
    format_sensor += '[\?if=name=cha_fan1 Top Fan: ]'
    format_sensor += '[\?if=name=cha_fan2 Rear Fan: ]'
    format_sensor += '[\?color=auto.input {input} RPM ]'
    sensors = ['aio_pump', 'cpu_fan', 'cha_fan1', 'cha_fan2', 'fan1']
    }

If I don't use a chips = line, everything before the fans is jumbled, but colorized (no fan at all).

20231228_21h03m19s_grim

I'll try playing some more tomorrow.

Your issue with fans... I think it may be already fixable by fixing up your sensors.conf https://github.com/lm-sensors/lm-sensors/blob/master/etc/sensors.conf.eg.... You need to add min values higher than 0.000.... Otherwise, it just uses default font color.

Already have one (both for the nct6793 (eg: the aio_pump is actually a header on my mobo, and is called fan5 normally) and drivetemp. Since I set my fan curves in BIOS, the .conf file has no effect for setting a min speed.

EDIT: Your issue with fans not being colorized... is due to values. There is nothing to compare against. You can try changing them with color_excl_input = pink or so.

I'll play around with that tomorrow as well.

Thanks!!!

@lasers
Copy link
Contributor Author

lasers commented Dec 29, 2023

Ok. So the machine idled for a couple of hours this afternoon, and no matter what I tried, this is the current output:

I see two lm_sensors in your updated config. You probably got bit by that bug again. Nom, nom.

I'll put together an updated config for you to try later.

@mlmatlock
Copy link
Contributor

I see two lm_sensors in your updated config.

Yeah; I can't come up with a way to combine

format_sensor += '[\?color=auto.input {input:.0f}°C]' and format_sensor += '[\?color=auto.input {input} RPM ]' so that a temp input would trigger the former, while a fan speed would trigger the latter.

Using the former, I'd get 1191°C, (fan speed) the latter would give me 42 RPM (temp)

I'll put together an updated config for you to try later.

That's cool...

@lasers
Copy link
Contributor Author

lasers commented Dec 29, 2023

Yeah; I can't come up with a way to combine

To give you an answer right now... Something like this.

...
format_sensor += '[\?if=name=edge GPU: [\?color=auto.input {input:.0f} °C] ]'
format_sensor += '[\?if=name=composite NVMe: [\?color=auto.input {input:.0f} °C] ]'
...
format_sensor += '[\?if=name=aio_pump Pump: [\?color=auto.input {input} RPM] ]'
format_sensor += '[\?if=name=cha_fan1 Top Fan: [\?color=auto.input {input} RPM] ]'
...

Crazy, I know.

EDIT: It will look more clean if you specified sda in format_sensor instead of format_chip too.

@lasers
Copy link
Contributor Author

lasers commented Dec 29, 2023

Untested in the config.

lm_sensors {
    format_chip = '{format_sensor}'

    format_sensor = ''
    format_sensor += '[\?if=name=samsung_860_ssd_(sda) SDA [\?color=auto.input {input:.0f}°C]]'
    format_sensor += '[\?if=name=samsung_860_ssd_(sdb) SDB [\?color=auto.input {input:.0f}°C]]'
    format_sensor += '[\?if=name=hitachi_hds72302_(sdc) SDC [\?color=auto.input {input:.0f}°C]]'

    format_sensor += '[\?if=name=motherboard MB [\?color=auto.input {input:.0f}°C]]'
    format_sensor += '[\?if=name=cpu CPU [\?color=auto.input {input:.0f}°C]]'
    format_sensor += '[\?if=name=edge GPU [\?color=auto.input {input:.0f}°C]]'
    format_sensor += '[\?if=name=composite NVMe [\?color=auto.input {input:.0f}°C]]'

    format_sensor += '[\?if=name=fan1 GPU Fan [\?color=auto.input {input} RPM]]'
    format_sensor += '[\?if=name=aio_pump Pump [\?color=auto.input {input} RPM]]'
    format_sensor += '[\?if=name=cpu_fan CPU Fan [\?color=auto.input {input} RPM]]'
    format_sensor += '[\?if=name=cha_fan1 Top Fan [\?color=auto.input {input} RPM]]'
    format_sensor += '[\?if=name=cha_fan2 Rear Fan [\?color=auto.input {input} RPM]]'

    chips = ["drivetemp-scsi-0-0", "drivetemp-scsi-2-0", "drivetemp-scsi-4-0"]
    chips += ["nct6793-*", "*-pci-*"]

    sensors = ['samsung*', 'hitachi*']
    sensors += ['input', 'composite', 'edge', 'motherboard', 'cpu']
    sensors += ['aio_pump', 'cpu_fan', 'cha_fan1', 'cha_fan2', 'fan1']

    format_chip_separator = '\?color=lightblue \|'
    format_sensor_separator = '\?color=lightpink \|'

    color_excl_input = "lightgreen"
}

@mlmatlock
Copy link
Contributor

@lasers, you are the $BEING!!!!!
I changed one thing: color_excl_input = "#1793D1" (Arch Blue).

20231229_15h25m25s_grim

Thank you so much!!

@lasers lasers changed the title lm_sensors: dirty fix invalid json if specified more than one chip lm_sensors: fix invalid json if specified more than one chip Dec 31, 2023
@ultrabug
Copy link
Owner

Well I'm in after the fight and once again @lasers mastered it all, you'll never cease to impress me as you're far way better than me on this formatting things...

So thanks a lot @lasers and thanks @mlmatlock for your nice gesture which I don't feel I deserve :/

@ultrabug ultrabug merged commit 4a15090 into ultrabug:master Jan 12, 2024
5 checks passed
@lasers lasers deleted the lm_sensors-chunks branch January 12, 2024 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Manually determine output order of lm_sensors
3 participants