Skip to content

Added a simple http+json server option for monitoring purposes #111

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mike-teehan
Copy link

it's a little undercooked... but it works.

@krtschmr
Copy link

@Snipa22 did you try this? looks good to me, but im a noob!

@nthall350
Copy link

Do you have a link to a demo of it in action, or at least some screenshots?

@@ -803,7 +810,8 @@ function Miner(id, params, ip, pushMessage, portData, minerSocket) {
lastShare: this.lastShareTime,
coin: this.coin,
pool: this.pool,
id: this.id
id: this.id,
password: this.password
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also add this.login here?

@@ -578,7 +579,13 @@ function balanceWorkers(){
}
}

function enumerateWorkerStats(){
function enumerateWorkerStats() {
// here we do a bit of a hack and "cache" the activeWorkers
Copy link

@Ethorsen Ethorsen Mar 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should check for global.config.httpEnable before dumping to disk. Maybe even start a different timeout function and not re-use enumerateWorkerStats

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know where else in the app loop "activeWorkers" is properly defined, and I haven't tried too hard to figure it out, hence the "hack."

@FranzDE
Copy link

FranzDE commented Apr 12, 2018

@mike-teehan
@Ethorsen
hello guys, sorry for the question .. is it required that I install apache and that I insert the file index.html inside the apache folder www ?
Or the installation of apache is not necessary and I just place the file index.html inside the path: /home/nodeproxy/xmr-node-proxy/ ?
.
.
EDIT: now I can see the index page, it was a port issue on my cloud server.

But there is a problem:

DataTables warning: table id=displaytable - Ajax error. For more information about this error, please see http://datatables.net/tn/7

index

@mike-teehan
Copy link
Author

@FranzDE if you want us to diagnose networking issues for you, you'll need to post some network info. Maybe a screenshot of the Network tab of Dev Tools after you've loaded the info page. Something.

Also, new branch, please update:
https://github.com/mike-teehan/xmr-node-proxy/tree/monitor

@FranzDE
Copy link

FranzDE commented Apr 17, 2018

@mike-teehan hi Mike, sorry it was my mistake.

do you think it is possible to make the miner remain on the list even when it is disconnected?
A "connection" column would be useful, with the words: "1" (or more), "0" (for disconnected ones)

Like this page "proxy-stat.php" that works on "xmrig-proxy":

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Local Proxy Stat</title>
</head>
<body>

<?php

// ---------------------------
// Change PORT for you system:
// -------------------
$url="http://localhost:PORT/workers.json/endpoint";

// Check curl module installed and loaded
if (!extension_loaded('curl')) {
    if (!dl('curl.so')) {
      echo "<br><h1>CURL module not found!</h1><br>";
            exit;
    }
}

// Check json module installed and loaded
if (!extension_loaded('json')) {
    if (!dl('json.so')) {
       echo  "<br><h1>JSON module not found!</h1><br>";
       exit;
    }
}


// get func from: http://php.net/manual/ru/function.json-decode.php
/**
* Clean comments of json content and decode it with json_decode().
* Work like the original php json_decode() function with the same params
*
* @param   string  $json    The json string being decoded
* @param   bool    $assoc   When TRUE, returned objects will be converted into associative arrays.
* @param   integer $depth   User specified recursion depth. (>=5.3)
* @param   integer $options Bitmask of JSON decode options. (>=5.4)
* @return  string
*/
function json_clean_decode($json, $assoc = false, $depth = 512, $options = 0) {

    // search and remove comments like /* */ and //
    $json = preg_replace("#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t](//).*)#", '', $json);

    if(version_compare(phpversion(), '5.4.0', '>=')) {
        $json = json_decode($json, $assoc, $depth, $options);
    }
    elseif(version_compare(phpversion(), '5.3.0', '>=')) {
        $json = json_decode($json, $assoc, $depth);
    }
    else {
        $json = json_decode($json, $assoc);
    }

    return $json;
}


//  Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);

// Will dump a beauty json :3
//var_dump(json_decode($result, true));
//$data = json_decode($result,true);
$data = json_clean_decode($result,true);
if (json_last_error() === JSON_ERROR_NONE) {
    //do something with $json. It's ready to use
    //echo  "<br><h1>JSON Decode NOT ERROR</h1><br>";

?>

<table border="1" cellpadding="5">
<thead>
 Total:
    <tr>
        <th>1 min HR</th>
        <th>10 min HR</th>
        <th>1 hour HR</th>
        <th>12 hours HR</th>
        <th>24 hours HR</th>
    </tr>
</thead>

<tbody>
<?php
foreach( $data['hashrate'] as $hr) {  ?>
 <tr>
 <?php  foreach($hr as $key => $wrk) {  ?>
  <td><?php echo $wrk; ?> </td>
 <?php
 }
 ?></tr>
<?php
}
?>
</tbody>


<table border="1" cellpadding="5">
<thead>
Workers:
    <tr>
        <th>Worker Name</th>
        <th>Last IP</th>
        <th>Conn count</th>
        <th>Accept shares</th>
        <th>Upstream Rejected</th>
        <th>Invalid shares</th>
        <th>Total shares</th>
        <th>Timestamp</th>
        <th>1 min HR</th>
        <th>10 min HR</th>
        <th>1 hour HR</th>
        <th>12 hours HR</th>
        <th>24 hours HR</th>
    </tr>
</thead>

<tbody>
<?php
foreach( $data['workers'] as $hr) {  ?>
 <tr>
 <?php  foreach($hr as $key => $wrk) {  ?>
  <td><?php echo $wrk; ?> </td>
 <?php
 }
 ?></tr>
<?php
}

} else {
    //yep, it's not JSON. Log error or alert someone or do nothing
    echo  "<br><h1>JSON Decode ERROR</h1><br>";
}

?>
</tbody>

</body>
</html>

Preview:
img_4084

@ariadarkkkis
Copy link

ariadarkkkis commented Apr 23, 2018

Hi @mike-teehan @Snipa22
Can you add this feature that xmrigCC have?
When the miners disconnect from CCserver, in the index.html(https://github.com/Bendr0id/xmrigCC/blob/master/index.html) it will throw a notification and says that IP or that workerID gone offline.
I want to use something like this to notify me when a miner disconnect from XNP by email or notification ( I personally prefer email more reliable). Can you add this feature or help me do that?
Thanks a lot for this fork its awesome
BTW my miners IDs are in user field not in password field but I can work that. Just want the idea how to make XNP notify me by email when a miner disconnect just like pools like supportxmr.com or other node-js pools
thanks

@bobbieltd
Copy link

In the mean time of waiting Snipa merging this PR (he is very busy with works now). Anyone wants to try http / json to monitor workerID, you can use MoneroOcean fork here https://github.com/MoneroOcean/xmr-node-proxy

Tested and Worked very well.
800b7063-56b2-4105-9fe4-571315eb0f7e

@ariadarkkkis
Copy link

@bobbieltd will it notify when a miner disconnects or will it save offline miners(name and IP and etc.)?

@bobbieltd
Copy link

Email feature will be added to notify about miner disconnection (waiting for MO), still in discussion.
Offline miners will be removed after a period of time ( it is trivial to add a time setting in config.json if you want ). But I guess email notification is still better than keeping dead worker in stats.

@phubbard91
Copy link

@bobbieltd Could you give a little guidance on what steps need to be taken to get output like yours? Thanks in advance.

@bobbieltd
Copy link

@phubbard91 You don’t need any guidance. Install MoneroOcean XNP fork and change some parameters in config.json for http.

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.

8 participants