npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

homebridge-macosx-info

v1.0.3

Published

A homebridge plugin that get macOSX information

Downloads

50

Readme

homebridge-macosx-info

npm npm GitHub license

See changelog

homebridge-macosx-info is homebridge plugin for Apple HomeKit, get and return somes systems informations from macOSX computer.

Such as :

  • updateTime
  • Temperature (C°)
  • Fan speed (rpm)
  • Uptime
    • show how long system has been running
  • Load average (%)
    • the load average of the system over the last 1, 5, and 15 minute
  • Free Mem (Mo)
  • Disk avalable (%)
  • Users (nb)
  • CPU Power consumption (Watt)

You can see below screenshots for illustrate homebridge-macos-info plugin.

homebridge-macos-info, Eve., screenshot

Screenshots are taken from the Elgato Eve.app

Exemple of .json data response file

{
    "updateTime":"Fri May 31 19:35:36 CEST 2019",
    "temperature":31.3,
    "fan":1797,
    "power":1.25,
    "uptime":"up 13:21",
    "load":"2.52 2.17 2.07",
    "freemem":639.96,
    "disk":"50",
    "user":2
}

Prerequisites

  • Install Homebrew (Homebrew installs the stuff you need that Apple didn’t)
  • Install node.js on macOS
  • Install Homebridge on macOS
  • Install Homebridge Config UI X on macOS (optional)
  • Install Eve.app on iOS (for all availables plugin function), or it's possible to used "Home" app, but only on macOSX Majave and iOS (all plugin function aren't availables on this app !)
  • Enable NOPASSWD for user in /etc/sudoers file

Installation

Used npm tool to install homebridge-macosx-info, and execute the command line below

npm i homebridge-macosx-info

Configuration

STEP 1 : homebridge config.json file

Add this lines in config.json

"accessories": [
        {
            "accessory": "MacOSXSysInfo",
            "name": "macOSX Info",
            "file": "/tmp/_homebridge-macosx-info.json",
            "serial": "042-03-000",
            "consumption": true,
            "user": true,
            "updateInterval": 60000
        }
    ],

| Parameter | Note | Optionnal | value | |-----------------|------|-----------|-------| | accessory | Name of accessory|No|MacOSXSysInfo| | name | a human-readable name for your plugin|No|macOSX Info| | file | .json respons file|yes|default : /tmp/_homebridge-macosx-info.json| | updateInterval| is time in ms of data update|yes|default : null| | consumption| true for log CPU Consumption|yes|default : null| | user| true for log Users number|yes|default : null|

Note :

  1. The index.js call <PATH of Node Module>/homebridge-macosx-info/sh/homebridge-macosx-info.sh shell script. You can find this script in the repository in /src/sh directory
  2. It's possible that you can change the path of homebridge-macosx-info.sh in readUptime function on index.js script
async function readUptime() {
    const exec = require('child_process').exec;
    var script = await exec('/usr/local/lib/node_modules/homebridge-macosx-info/src/sh/homebridge-macosx-info.sh',
        (error, stdout, stderr) => {
            if (error !== null) {
                //this.log("exec error: " + ${error});
            }
        }); 
};

STEP 2 : Adapte "homebridge-macosx-info.sh" file in "src/sh" directory

  1. You can change path of temporary .json files -> var JSON_DATA_FILE
  2. You can change path and option of check_osx_smc binary -> var CHECK_OSX_SMC
DIR=$(dirname $0)
JSON_DATA_FILE=/tmp/_homebridge-macosx-info.json # path of .json respons file 
CHECK_OSX_SMC=$DIR/../../bin/check_osx_smc # path of check_osx_smc binary

function sys_mon()
{
    # See the hardware compatibility -> https://github.com/jedda/OSX-Monitoring-Tools/blob/master/check_osx_smc/known-registers.md
    # See README -> https://github.com/jedda/OSX-Monitoring-Tools/blob/master/check_osx_smc/README.md
    read -a fields <<< `$CHECK_OSX_SMC -s c -r TA0P,F0Ac -w 70,5200 -c 85,5800`
    _temp=${fields[7]//,/.}
    _fan=${fields[8]}

    _time=`date`
    read -a fields <<< `sudo powermetrics -i 500 -n1 --samplers cpu_power | grep "CPUs+GT+SA" | sed 's/Intel energy model derived package power (CPUs+GT+SA): //g'`
    _power=${fields[0]//W/}

    _uptime=`uptime`
    _load=$_uptime

    _uptime=${_uptime%users*} ; _uptime=${_uptime%,*} ; _uptime=${_uptime#*up} ; _uptime=${_uptime%,*} ; _uptime=${_uptime#*up} ; _uptime="up ${_uptime# }"
    _load=${_load#*load averages: }

    _user=`who | wc -l`
    _user="${_user// /}"

    read -a fields <<< `vm_stat | perl -ne '/page size of (\d+)/ and $size=$1; /Pages\s+([^:]+)[^\d]+(\d+)/ and printf("%-16s % 16.2f Mi\n", "$1:", $2 * $size / 1048576)' | grep "free:"` ; _freemem=${fields[1]}
    read -a fields <<<  `df -h / | grep /` ; _disk=${fields[4]//%/}

    echo '{"updateTime":"'${_time}'","temperature":'${_temp:5:4}',"fan":'${_fan:5:4}',"power":'${_power}',"uptime":"'${_uptime}'","load":"'${_load}'","freemem":'${_freemem:0:6}',"disk":"'${_disk}'","user":'${_user}'}' > $JSON_DATA_FILE
}

STEP 3 : Add NOPASSWD entry in your /etc/sudoers

# root and users in group wheel can run anything on any machine as any user
root        ALL = (ALL) ALL
%admin      ALL = (ALL) ALL
<USER>      ALL=NOPASSWD: ALL

Note : You must change the user <USER> by the user who run homebridge in your system

STEP 4 : restart homebridge

Combine the two commands in a terminal to restart homebridge background process

  • launchctl unload ~/Library/LaunchAgents/com.homebridge.server.plist
  • launchctl load ~/Library/LaunchAgents/com.homebridge.server.plist

Note : This commands are only avalable for macOS

Todo

  • [x] Generate all the measures in a .json file [#3]
  • [x] Worked on performance
    • [x] Use only sh built-in (no sed & no awk) [#4]

Known bugs

  • [x] Uptime error in "homebridge-macosx-info" after more than one day ! [#1]
  • [x] Temparature and fan mesures don't work on all Apple mac hardware. Used now check_osx_smc binary. You can see the hardware compatibility here [#2]

Credits

Disclaimer

I'm furnishing this software "as is". I do not provide any warranty of the item whatsoever, whether express, implied, or statutory, including, but not limited to, any warranty of merchantability or fitness for a particular purpose or any warranty that the contents of the item will be error-free. The development of this module is not supported by Apple Inc. or eve. These vendors and me are not responsible for direct, indirect, incidental or consequential damages resulting from any defect, error or failure to perform.

License

This project is licensed under the MIT License - see the LICENSE file for details