Giter Site home page Giter Site logo

nmaggioni / r710-fan-controller Goto Github PK

View Code? Open in Web Editor NEW
133.0 10.0 38.0 30 KB

A Python script and SystemD service to control Dell PowerEdges' fans depending on CPU(s) temperatures.

License: MIT License

Python 81.93% Shell 14.21% Dockerfile 3.86%

r710-fan-controller's People

Contributors

barrowsys avatar bradpower7 avatar lefinal avatar nmaggioni avatar nullx76 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

r710-fan-controller's Issues

cannot get it to run, without failure

cannot get it to run, without failure, so i have made sure dependencies are installed,
i CAN run sensors on command line, and i get the CPU temps listed...
when i check with systemctl status fan-control.service
i get an error of;
Process: 157776 ExecStart=/opt/fan_control/venv/bin/python3 -u /opt/fan_control/fan_control.py (code=exited,status=1/FAILURE)

if i try to run just the fan_control.py on its own from command line i get;
root@pve2:/opt/fan_control# python3 fan_control.py Traceback (most recent call last): File "/opt/fan_control/fan_control.py", line 7, in <module> import sensors # https://github.com/bastienleonard/pysensors.git ModuleNotFoundError: No module named 'sensors'
i have made sure that libsensors4-dev is installed as well...

this is under ProxMox version 8.0.9

**FEATURE**Adding Linear fan speed control between the thresholds

Hey guys,
I have been running your software for a while now and it works flawlessly, but I couldn't help but wonder what it would be like if we added in linear fan control that operated between the 3 thresholds, or increase the threshold limits to that we can add more fan states.

Fan control should be reset to "automatic" when script receives SIGTERM

Currently, when stopping the systemd service fan control remains in whatever mode the script was last in. If this is "manual" mode, and the fans are running at at low RPM, CPU temperatures may reach critical levels during boot / inside BIOS, where low-power states are not maintained. The script should probably make a best effort to return to "automatic" mode when it exits.

I can submit a PR when I get a chance, just logging this for the time being. Thank you!

Does not work in Proxmox 7

I recently updated Proxmox and tried to re-run this. I have not had any issues with this previously. The first time I ran it post-update, I got:

*** Installing packaged dependencies...
Hit:1 http://ftp.us.debian.org/debian bullseye InRelease
Get:2 http://ftp.us.debian.org/debian bullseye-updates InRelease [36.8 kB]
Hit:3 http://security.debian.org bullseye-security InRelease
Hit:4 http://download.proxmox.com/debian/pve bullseye InRelease
Fetched 36.8 kB in 1s (43.7 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
#!/bin/bash
Reading state information... Done
Package python-virtualenv is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'python-virtualenv' has no installation candidate

So I edited the .sh file to remove python-virtualenv as a candidate since python3-virtualenv should be used as default now and then got:

*** Installing packaged dependencies...
Hit:1 http://ftp.us.debian.org/debian bullseye InRelease
Hit:2 http://ftp.us.debian.org/debian bullseye-updates InRelease
Hit:3 http://security.debian.org bullseye-security InRelease
Hit:4 http://download.proxmox.com/debian/pve bullseye InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
build-essential is already the newest version (12.9).
ipmitool is already the newest version (1.8.18-10.1).
libsensors4-dev is already the newest version (1:3.6.0-7).
python3-virtualenv is already the newest version (20.4.0+ds-2).
python3-dev is already the newest version (3.9.2-3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
*** Creating folder '/opt/fan_control'...
*** Creating and activating Python3 virtualenv...
*** Installing Python dependencies...
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fee84932740 (most recent call first):
./install.sh: line 36: 536229 Aborted                 pip3 install -r requirements.txt

Any idea how to fix this?

Python 3.9 support

Python 3.7 is end of life (with bugfix released) in mid 2023. Many rolling-release distributions (and my Gentoo) will drop it earlier however. So I ask to port that script to latest python 3.9.

HDD and Nvme temp

Hi

Is it possible for fans to ramp up then HDD and NVME disk is higher than 40 degrees Celsius? I dont like when they are 46 degrees over time with load. Been looking for a cript that will solve this issue for 4 years.

CPU temperature command, Kg key for IPMIv2 authentication, RPi Service and Additional Speeds/Temps

Hi there! So this tool has been great but I had to make a few tweaks to get it to work and while I was at it I improved a bit as well(at least I think so). I wanted to share my process to get this to work on a Raspberry Pi 4b host running Raspberry Pi OS to control a Dell Poweredge R710 running Proxmox 7.1-12.

First Proxmox would not show cpu values from the suggested "sysctl -a" command. Instead I needed to install im-sensors on the Dell server and run "sensors -u" through ssh. The entire command being:

ssh root@dell_hostname 'sensors -u | grep input | grep -E -o "[0-9]+\.[0-9]+"'

Next the ipmitool would not work and would return an error: "RAKR 4 message has invalid integrity check value". No matter where I looked I could not find this specific error, at least nothing that wasn't behind a paywall. I then came across a different tutorial here: https://jacobjangles.com/hushing-the-dell-r710-fans/ that had an additional flag on the ipmitool. After looking into it, it made sense that I needed to define the Kg key using the "-y " flag. So adding that flag and hex key to the config file and subprocess.check_output allowed the commands to go through.

    cmd = ["ipmitool"]
    if state[host['name']]['is_remote']:
        cmd += ['-I', 'lanplus']
        cmd += ['-H', host['remote_ipmi_credentials']['host']]
        cmd += ['-U', host['remote_ipmi_credentials']['username']]
        cmd += ['-P', host['remote_ipmi_credentials']['password']]
        cmd += ['-y', host['remote_ipmi_credentials']['hexkey']]
    cmd += (args.split(' '))

The last issue that I had while running this was that because Raspberry Pi OS runs the systemctl service as root the service would fail. I needed to add both "User=pi" and "WorkingDirectory=/opt/fan_control" to the /etc/systemd/system/fan-control.service to get it to work after that.

[Unit]
Description=Temperature-based fan speed controller
After=network.target

[Service]
User=pi
Type=simple
WorkingDirectory=/opt/fan_control
ExecStart=/opt/fan_control/venv/bin/python3 -u /opt/fan_control/fan_control.py
Restart=always
RestartSec=15

[Install]
WantedBy=multi-user.target

Then I ran the following for the change to take effect:

sudo systemctl daemon-reload
sudo systemctl enable fan-control.service
sudo systemctl start fan-control.service

Once I got the tool running I updated it to use some recommended commands for Python3 and changed it to use more speed/temp combos.

I saw it is recommended now to use "subprocess.run" instead of "subprocess.check_output", but I am not sure the difference or why. I update it though which makes line 41 of fan_control.py:

subprocess.run(cmd, check=True, capture_output=True, text=True)

There is also a hex conversion in python that simplified some of the code on line 74:

        wanted_percentage_hex = hex(wanted_percentage)

For my own use case I also included another command to get the ambient temperature from the Dell server just to help average the temperature for the entire server using the following command:

ipmitool -I lanplus -H idrac_hostname -U ipmi-user -P password -y hex_key sdr type temperature | grep Ambient | grep -Po '\| ([0-9]+) degrees' | grep -Po '[0-9]+'

The last change I made was adding a for loop for temp/speed checks instead of a set 3. Just so I could have a finer control over the speeds. So after removing lines 107-110 I updated the code originally on lines 172-195 to the following:

    for idx, x in enumerate(host['temperatures']):
        idx_under = idx - 1
        idx_over = idx + 1
        if idx == 0:
            if (
                temp_average <= x and
                checkHysteresis(temp_average, idx, host)
            ):
                set_fan_speed(idx, host)
                return True
        elif idx_over == len(host['temperatures']):
            if x < temp_average:
                set_fan_control("automatic", host)
                return True
        elif (
            host['temperatures'][idx_under] < temp_average <= x and
            checkHysteresis(temp_average, idx_under, host)
        ):
            set_fan_speed(idx_under, host)
            return True
        elif (
            x < temp_average <= host['temperatures'][idx_over] and
            checkHysteresis(temp_average, idx, host)
        ):
            set_fan_speed(idx, host)
            return True

I know this may not be the best way to do this and I am not an expert in Python but maybe it will help someone else or help improve the development of the tool as it really has been great so far!

fail to start service after install

On Proxmox VE 8.1
Dell r720xd

Had to disable the Proxmox repos in order to get it to install, but after doing so the service fails to start. Any help would be greatly appreciated.

Out of running install.sh:
root@proxmox:~/r710-fan-controller# ./install.sh
*** Installing packaged dependencies...
Hit:1 http://ftp.us.debian.org/debian bookworm InRelease
Hit:2 http://ftp.us.debian.org/debian bookworm-updates InRelease
Hit:3 http://security.debian.org bookworm-security InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
build-essential is already the newest version (12.9).
python3-virtualenv is already the newest version (20.17.1+ds-1).
python3-dev is already the newest version (3.11.2-1+b1).
libsensors4-dev is already the newest version (1:3.6.0-7.1).
ipmitool is already the newest version (1.8.19-4).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
*** Creating folder '/opt/fan_control'...
*** Creating and activating Python3 virtualenv...
*** Existing venv found, purging it.
created virtual environment CPython3.11.2.final.0-64 in 180ms
creator CPython3Posix(dest=/opt/fan_control/venv, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
added seed packages: pip==23.0.1, setuptools==66.1.1, wheel==0.38.4
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
*** Installing Python dependencies...
Collecting git+https://github.com/bastienleonard/pysensors.git@e1ead6b73b2fa14e7baaa855c3e47b078020b4f8 (from -r requirements.txt (line 1))
Cloning https://github.com/bastienleonard/pysensors.git (to revision e1ead6b73b2fa14e7baaa855c3e47b078020b4f8) to /tmp/pip-req-build-orqhtmyp
Running command git clone --filter=blob:none --quiet https://github.com/bastienleonard/pysensors.git /tmp/pip-req-build-orqhtmyp
Running command git rev-parse -q --verify 'sha^e1ead6b73b2fa14e7baaa855c3e47b078020b4f8'
Running command git fetch -q https://github.com/bastienleonard/pysensors.git e1ead6b73b2fa14e7baaa855c3e47b078020b4f8
Resolved https://github.com/bastienleonard/pysensors.git to commit e1ead6b73b2fa14e7baaa855c3e47b078020b4f8
Preparing metadata (setup.py) ... done
Collecting pyyaml==6.0
Using cached PyYAML-6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (757 kB)
Building wheels for collected packages: sensors
Building wheel for sensors (setup.py) ... done
Created wheel for sensors: filename=sensors-0.1-cp311-cp311-linux_x86_64.whl size=47194 sha256=24068e971304dc7454df4a29ef88d9693644804ba917b0c702a5118aaafd7e18
Stored in directory: /root/.cache/pip/wheels/d8/8e/b1/857648ac4c50570024c8e8653b76f91a55c627282423249796
Successfully built sensors
Installing collected packages: sensors, pyyaml
Successfully installed pyyaml-6.0 sensors-0.1
*** Deactivating Python3 virtualenv...
*** Copying script and configuration in place...
*** Creating, (re)starting and enabling SystemD service...
*** Waiting for the service to start...
*** All done! Check the service's output below:

โ— fan-control.service - Temperature-based fan speed controller
Loaded: loaded (/etc/systemd/system/fan-control.service; enabled; preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Wed 2024-02-28 22:19:40 CST; 3s ago
Process: 251080 ExecStart=/opt/fan_control/venv/bin/python3 -u /opt/fan_control/fan_control.py (code=exited, status=1/FAILURE)
Main PID: 251080 (code=exited, status=1/FAILURE)
CPU: 57ms
root@proxmox:~/r710-fan-controller#

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.