owned this note
owned this note
Published
Linked with GitHub
# Monitoring my KS0 ULTRA KAS miner remotely
:::warning
:warning: This is just a note for sharing purpose, please be aware of the owner of the miner should take full responsibility to their miner if they adopt the following guideline, the author will not be responsible for any damage to any person or any property.
:::
Bought my first crypto miner on iceriver official website, and it provides a console which can only be accessed within LAN.
We can view the current status of the miner on this console, like average hashrate, temperature inside, fan speed, etc...
**But it can be only accessible within LAN**, which means you can't check the status of your miner if you left your warehouse, we can still guess the health of miner by the bot provided by the pool, however, it provides very few information of our miner.
So I decided to create a scheduler to report the miner status every hour and turn it off if there's anything wrong to it.
## What is the API to be called to get the status
There's no much information on the forum, so I clicked F12 and checked it by myself.

~~We can find out there's **no token needed** to call the API request, the account name and password you typed in just letting you can access the **UI** of the LAN console, nothing more...~~
Checking the API interacton between client and server, found the one which returns all of the status on the LAN console.
```
GET http://<local IP address>/user/userpanel?post=4
```
Calling this api using postman, it ruturns the current info of the miner in json format

```
{"error":0,"data":{"model":"none","algo":"none","online":true,"firmver1":"BOOT_3_3","firmver2":"image_1.0","softver1":"ICM168_3_2_14_ks0ultra_miner","softver2":"ICM168_3_2_14_ks0ultra_bg","firmtype":"Factory","nic":"eth0","mac":"00:0a:66:30:00:6d","ip":"192.168.0.136","netmask":"255.255.255.0","host":"ICERIVER","dhcp":true,"gateway":"192.168.0.1","dns":"192.168.0.1","locate":0,"rtpow":"359G","avgpow":"375G","reject":0.000000,"runtime":"00:01:15:16","unit":"G","pows": {"board1":[0,230,282,364,377,361,395,417,350,362,397,357,382,397,359,-1,-1,-1,-1,-1,-1,-1,-1,-1]},"pows_x":["0 mins","5 mins","10 mins","15 mins","20 mins","25 mins","30 mins","35 mins","40 mins","45 mins","50 mins","55 mins","60 mins","65 mins","70 mins","75 mins","80 mins","85 mins","90 mins","95 mins","100 mins","105 mins","110 mins","115 mins"],"powstate":true,"netstate":true,"fanstate":true,"tempstate":true,"fans":[6079,6079,0,0],"pools":[{"no":1.000000,"addr":"stratum+tcp://kas-asia.f2pool.com:1400","user":"kwl88347.001","pass":"21235365876986800","connect":-1.000000,"diff":"0.00 G","priority":1.000000,"accepted":0.000000,"rejected":0.000000,"diffa":0.000000,"diffr":0.000000,"state":0.000000,"lsdiff":0.000000,"lstime":"00:00:00"},{"no":2.000000,"addr":"stratum+tcp://kas-asia.f2pool.com:1430","user":"kwl88347.002","pass":"","connect":1.000000,"diff":"8796.09 G","priority":2.000000,"accepted":281.000000,"rejected":0.000000,"diffa":0.000000,"diffr":0.000000,"state":1.000000,"lsdiff":0.000000,"lstime":"00:00:00"},{"no":3.000000,"addr":"stratum+tcp://kas-euro.f2pool.com:1400","user":"kwl88347.003","pass":"","connect":-1.000000,"diff":"0.00 G","priority":3.000000,"accepted":0.000000,"rejected":0.000000,"diffa":0.000000,"diffr":0.000000,"state":0.000000,"lsdiff":0.000000,"lstime":"00:00:00"}],"boards":[{"no":1.000000,"chipnum":18.000000,"chipsuc":0.000000,"error":0.000000,"freq":875.000000,"rtpow":"359.17G","avgpow":"376.28G","idealpow":"0.00G","tempnum":"(null)","pcbtemp":"0.00-0.00-0.00-0.00","intmp":48.000000,"outtmp":37.000000,"state":true,"false":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]}],"refTime":"2024-06-30 07:07:42 UTC"},"message":""}
```
## Creating some tests to check the miner health
Next, create some test cases to see if the miner is in good health like if hashrate is in between 350~450 (GH/s), or the temperature is under 50 degree Celsius.
I created some test cases on postman on the script page.
```
// Parse the response body to JSON
const responseJson = pm.response.json();
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
// Check if 'error' exists and equals to 0
pm.test("error = 0", function(){
pm.expect(responseJson).to.have.property('data').to.have.property('boards').to.have.property('0').to.have.property('error');
pm.expect(responseJson.data.boards[0].error).to.be.equals(0);
});
// Check if the 'intmp' exists and its value is lower than 60
pm.test("in tmp value is lower than 60", function () {
pm.expect(responseJson).to.have.property('data').to.have.property('boards').to.have.property('0').to.have.property('intmp');
pm.expect(responseJson.data.boards[0].intmp).to.be.below(60);
});
// Check if 'outtmp' exists and its value is lower than 50
pm.test("out tmp value is lower than 50", function () {
pm.expect(responseJson).to.have.property('data').to.have.property('boards').to.have.property('0').to.have.property('outtmp');
pm.expect(responseJson.data.boards[0].outtmp).to.be.below(50);
});
// Check if 'avgpow' exists and it's in normal range (hashrate)
pm.test("avgpow is in the range 350-450", function(){
pm.expect(responseJson).to.have.property('data').to.have.property('boards').to.have.property('0').to.have.property('avgpow');
let intmpValueStr = responseJson.data.boards[0].avgpow;
let intmpValue = parseFloat(intmpValueStr);
pm.expect(intmpValue).to.be.within(350,450);
console.log(intmpValue);
});
```
If the miner is in good health, we can see all of the tests passed.

If not, we can then create a workflow to turn the miner into sleep mode.
Here's the API to set the settings to the settings
```
http://192.168.0.136/user/machineconfig?pool1address=<your-address>?pool1miner=<your-miner>?pool1pwd=<your-pwd>?pool2address=<your-address>?pool2miner=<your-miner>?pool2pwd=<your-pwd>?pool3address=<your-address>?pool3miner=<your-miner>?pool3pwd=<your-pwd>?fancontrol=on?fanratio=100?fanmode=<normal-or-sleep>?post=3
```
However, there's another issue...
We can only run this script by manually triggering it, we can't run this on postman scheduler because postman schedule monitor can only run on the remote machine hosted by postman.
## Export the collection and leverage Newman
Although postman scheduler monitor is not a feasible way to meet the requirement, we can still leverage Newman CLI tool to do the schdule task.
### Step1: Export the postman collection
Click on the triple dots on the top-right side of the postman collection, export the json file containg the collection.

### Step2: Install nodejs and newman on your machine
### Step3: Create a task scheduler to generate the schedule report
In Windows, we can use task scheduler.
In Linux, we can use cron command.
I run this on my Windows laptop, go to task schduler, click create task.
Enter the name and description you like, and set the scheduler you want, I set this report to be generated once an hour
Define the action you want to do, for us, we have to leverage nodejs and newman to run the collection test case exported from postman.
Choose run a process on the action drag down list, and find your location of nodejs, type into the textbox "Process or command line"
```
"C:\Program Files\nodejs\node.exe"
```
We can define the argument as following in the argument textbox.
```
C:\Users\asus\AppData\Roaming\npm\node_modules\newman\bin\newman.js run \path\to\your\collection\collection.json -r html --reporter-html-export path\the\file\exported\newman_report.html
```
After all tasks done, we can finally see the report generated every hour under the directory path\the\file\exported :tada:

Lastly, we have to find a space to upload the report onto the cloud scheduly, so we can see the report even if we are not in the LAN network.
I believe there are lots of space can be uploaded like onedrive or app chatbot, to me, I chose aws s3 bucket because I want to add more features on it in the near future.
## To be continued...