Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Refactor (#144)
Browse files Browse the repository at this point in the history
* refactor and update

* Apply fixes from StyleCI

Co-authored-by: Tobias <[email protected]>
  • Loading branch information
BitDesert and BitDesert authored Jan 1, 2021
1 parent a5a9046 commit 508b9c8
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 5,073 deletions.
82 changes: 61 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,87 @@ Nano Node Monitor is a server-side PHP-based monitor for Nano and Banano nodes.
![Banano](https://i.imgur.com/FMO8H9u.png)


## Prerequisites
## Docker Installation

- Running Nano Node with RPC enabled ([Tutorial](https://github.com/nanocurrency/raiblocks/wiki/Docker-node))
- Webserver with PHP ([Tutorial](https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04))
### Pulling Docker image

sudo docker pull nanotools/nanonodemonitor

### Running

#### Standalone

sudo docker run -d -p 80:80 -v ~:/opt --restart=unless-stopped nanotools/nanonodemonitor

This will create a directory called _nanoNodeMonitor_ inside your home directory with the _config.php_ inside it.
Edit it according to your needs and you're good to go!

#### Docker Compose

1. Create a directory called _nano_ and go inside it: `mkdir nano && cd nano`

2. Create a new file called _docker-compose.yml_ with the following contents:

```
version: '3'
services:
monitor:
image: "nanotools/nanonodemonitor"
restart: "unless-stopped"
ports:
- "80:80"
volumes:
- "~:/opt"
node:
image: "nanocurrency/nano"
restart: "unless-stopped"
ports:
- "7075:7075"
- "127.0.0.1:7076:7076"
volumes:
- "~:/root"
```
3. Nice! Now execute `sudo docker-compose up -d` to start everything.

4. Inside your home directory you will find a new directory called _nanoNodeMonitor_, edit the _config.php_: `cd ~/nanoNodeMonitor`

5. You will have to change the node IP to the name of the nodes Docker container e.g. `nano_node_1`. Edit the other things as well if you want to.

6. Done!

## Manual Installation

### Prerequisites

- Running Nano Node with RPC enabled ([Tutorial](https://docs.nano.org/running-a-node/node-setup/))
- Webserver with PHP 7.2
- PHP-Curl Module

`sudo apt-get install php-curl`

## Installation
### Installation

In your empty webserver directory, e.g. `/var/www/html`, execute:

git clone https://github.com/NanoTools/nanoNodeMonitor .


If you want it to run a subdirectory remove the `.` at the end.

In the `modules` folder, create your own config file by executing:


cp config.sample.php config.php

## Usage

You will have to add your node's account to the config file `config.php` by modifying the following lines. Make sure to remove the `//` in front of `$nanoNodeAccount`:

```
// account of this node
$nanoNodeAccount = 'nano_1f56swb9qtpy3yoxiscq9799nerek153w43yjc9atoaeg3e91cc9zfr89ehj';
$nanoNodeAccount = 'nano_1youraccountname24cq9799nerek153w43yjc9atoaeg3e91cc9zfr89ehj';
```


If you are running a standalone node you might need to modify the IP-address and the port for the RPC in the file `config.php`. It should match the corresponding entries in `~/RaiBlocks/config.json`, e.g.
If you are running a standalone node you might need to modify the IP-address and the port for the RPC in the file `config.php`. It should match the corresponding entries in `~/Nano/config.json`, e.g.

```
// ip address for RPC (default: [::1])
Expand All @@ -51,24 +101,14 @@ $nanoNodeRPCIP = '127.0.0.1';
$nanoNodeRPCPort = '7076';
```

## Updating

Switch to your installation directory and execute `git pull`.

## Creating a Theme

If you're interested in creating your own theme in addition to the official Light, Dark, and Banano themes, we've made it very simple for you to do so. Check out the [Wiki](https://github.com/NanoTools/nanoNodeMonitor/wiki/Create-a-theme) for more info.


## Links

* [Installation Official Nano Node with Docker (Official Nano Repo Wiki)](https://github.com/nanocurrency/raiblocks/wiki/Docker-node)
* [Easy-Nano-Node 5 minute installation](https://nanotools.github.io/easy-nano-node/)

## Support

Feel free to change your representative to the [Nano Node Monitor Rep](https://mynano.ninja/account/nano_1f56swb9qtpy3yoxiscq9799nerek153w43yjc9atoaeg3e91cc9zfr89ehj) `nano_1f56swb9qtpy3yoxiscq9799nerek153w43yjc9atoaeg3e91cc9zfr89ehj` to support further decentralization within the Nano network. In case of problems, please send an [issue](https://github.com/NanoTools/nanoNodeMonitor/issues).
Donations to the development of Nano Node Monitor are very welcome to:

Donations to the development of Nano Node Monitor are very welcome to: [nano_1nanomon9uycemhgonue4twmcqmsu7oxw43maro8amj751ozpus8r8gsic48](https://nanocrawler.cc/explorer/account/nano_1nanomon9uycemhgonue4twmcqmsu7oxw43maro8amj751ozpus8r8gsic48)
nano_1ninja7rh37ehfp9utkor5ixmxyg8kme8fnzc4zty145ibch8kf5jwpnzr3r

Have fun! :)
Or [sponsor the development on GitHub](https://github.com/sponsors/BitDesert)! Thanks!
34 changes: 21 additions & 13 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@

// get cached response
$data = $cache->fetch($apiName, function () use (
&$nanoNodeRPCIP, &$nanoNodeRPCPort, &$nanoNodeAccount, &$blockExplorer,
&$nanoNodeName, &$nanoNumDecimalPlaces, &$uptimerobotApiKey, &$currency,
&$nodeLocation
&$nanoNodeRPCIP,
&$nanoNodeRPCPort,
&$nanoNodeAccount,
&$blockExplorer,
&$nanoNodeName,
&$nanoNumDecimalPlaces,
&$uptimerobotApiKey,
&$currency,
&$nodeLocation
) {
// get curl handle
$ch = curl_init();
Expand Down Expand Up @@ -63,10 +69,6 @@
$data->uncheckedBlocks = (int) $rpcBlockCount->{'unchecked'};
$data->cementedBlocks = (int) $rpcBlockCount->{'cemented'} ?: 0;

if ($currency == 'nano') {
$data->blockSync = getSyncStatus($data->currentBlock);
}

// -- Get number of peers from nano_node
$rpcPeers = getPeers($ch);
$peers = (array) $rpcPeers->{'peers'};
Expand Down Expand Up @@ -132,6 +134,7 @@
$data->repAccount = $rpcNodeRepInfo->{'representative'} ?: '';
$data->repAccountShort = truncateAddress($data->repAccount);
$data->repAccountUrl = getAccountUrl($data->repAccount, $blockExplorer);
// $data->repDelegatorsCount = getDelegatorsCount($ch, $nanoNodeAccount)->count; // disabled (poor performance)

// get the account weight
$rpcNodeAccountWeight = getAccountWeight($ch, $nanoNodeAccount);
Expand All @@ -153,13 +156,8 @@
$data->nodeUptime = getNodeUptime($uptimerobotApiKey);
}

// get info from My Nano Ninja
$data->nodeNinja = getNodeNinja($nanoNodeAccount);

// get node location
// 1) If location is set by user, we use it.
// 2) If location not set by user, we try to get if from ninja.
$data->nodeLocation = getNodeLocation($nodeLocation, $data->nodeNinja);
$data->nodeLocation = $nodeLocation;

// currency and currency symbol
$data->currency = $currency;
Expand All @@ -176,6 +174,16 @@
// get the counters
$data->stats->counters = getStats($ch, 'counters');

// get telemetry data from other nodes
$data->telemetry = getTelemetry($ch);

// sync status in %
if ($data->telemetry->block_count) {
$data->blockSync = getSyncStatus($data->currentBlock, $data->telemetry->block_count);
} else {
$data->blockSync = null;
}

// close curl handle
curl_close($ch);

Expand Down
31 changes: 0 additions & 31 deletions contribute.php

This file was deleted.

8 changes: 8 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3'
services:
web:
build: .
ports:
- "3000:80"
volumes:
- .:/var/www/html
4 changes: 2 additions & 2 deletions modules/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// $themeChoice = 'light';

// Choice of block explorer
// Nano Explorers: 'ninja', 'nanoodle', 'nanocrawler', 'nifni'
// Nano Beta Explorers: 'nanocrawler-beta', 'nano-beta'
// Nano Explorers: 'ninja', 'nanocrawler'
// Nano Beta Explorers: 'nanocrawler-beta'
// Banano Explorers: 'banano'
// $blockExplorer = 'nanocrawler';

Expand Down
14 changes: 7 additions & 7 deletions modules/constants.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

// the project version
define('PROJECT_VERSION', '1.5.5');
define('PROJECT_VERSION', '1.5.6');

// project URL
define('PROJECT_URL', 'https://github.com/NanoTools/nanoNodeMonitor');
Expand All @@ -16,19 +16,19 @@
define ('NODEMON_BAN_REP_ACCOUNT', 'ban_1kxnxi5zurj6h7dfb87ik6hhu9yo63miyg6q1fjaxgnd1kknr5y5md4xwxoj');

// nano donation account for Nano Node Monitor development
define ('NODEMON_DON_ACCOUNT', 'nano_1nanomon9uycemhgonue4twmcqmsu7oxw43maro8amj751ozpus8r8gsic48');
define ('NODEMON_DON_ACCOUNT', 'nano_1ninja7rh37ehfp9utkor5ixmxyg8kme8fnzc4zty145ibch8kf5jwpnzr3r');

// baano donation account for Nano Node Monitor development
define ('NODEMON_BAN_DON_ACCOUNT', 'ban_1kxnxi5zurj6h7dfb87ik6hhu9yo63miyg6q1fjaxgnd1kknr5y5md4xwxoj');
define ('NODEMON_BAN_DON_ACCOUNT', 'ban_1ninja7rh37ehfp9utkor5ixmxyg8kme8fnzc4zty145ibch8kf5jwpnzr3r');

// total number of characters for displaying Nano addresses including ellipsis
define ('NANO_ADDR_NUM_CHAR', 17);

// curl timeout in seconds to receive data from ninja (max delay is NINJA_TIMEOUT + NINJA_CONECTTIMEOUT)
define ('NINJA_TIMEOUT', 3);
// curl timeout in seconds to receive data from external services (max delay is EXTERNAL_TIMEOUT + EXTERNAL_CONECTTIMEOUT)
define ('EXTERNAL_TIMEOUT', 3);

// curl timeout in seconds to connect to ninja (max delay is NINJA_TIMEOUT + NINJA_CONECTTIMEOUT)
define ('NINJA_CONECTTIMEOUT', 2);
// curl timeout in seconds to connect to external services (max delay is EXTERNAL_TIMEOUT + EXTERNAL_CONECTTIMEOUT)
define ('EXTERNAL_CONECTTIMEOUT', 2);

// maximum allowed age of data to be part of the block confirmation time percentiles calculation (milliseconds)
define ('CONFIRMATION_TIME_LIMIT', 600000);
10 changes: 5 additions & 5 deletions modules/defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
$themeChoice = 'light';

// Choice of block explorer
// Nano Explorers: 'nanode', 'ninja', 'nanoexplorer', 'nanowatch', or 'meltingice'
// Banano Explorers: 'banano'
$blockExplorer = 'nanode';
// Nano Explorers: 'ninja', 'nanocrawler'
// Nano Beta Explorers: 'nanocrawler-beta'
// Banano Explorers: 'banano'
$blockExplorer = 'nanocrawler';

// autorefresh interval for the status webpage in seconds
$autoRefreshInSeconds = 5;
Expand All @@ -26,8 +27,7 @@
$nanoNodeName = gethostname();

// Location of your node
// If left empty, we try to get it from My Nano Ninja.
$nodeLocation = '';
$nodeLocation = NULL;

// A welcome message shown on top
$welcomeMsg = '';
Expand Down
5 changes: 2 additions & 3 deletions modules/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
?>
</li>
<li>Powered by <a href="<?php echo PROJECT_URL ?>" target="_blank" rel="noopener">Nano Node Monitor</a></li>
<li>GitHub: <a href="<?php echo PROJECT_URL; ?>" target="_blank" rel="noopener">Source</a> | <a href="<?php echo PROJECT_URL . '/wiki'; ?>" target="_blank" rel="noopener">Wiki</a> | <a href="<?php echo PROJECT_URL . '/wiki/API-Description'; ?>" target="_blank" rel="noopener">API</a></li>
<li>GitHub: <a href="<?php echo PROJECT_URL; ?>" target="_blank" rel="noopener">Source</a></li>
<li>
Donate: <a href="<?php echo getAccountUrl($donAccount, $blockExplorer); ?>" target="_blank" rel="noopener"><?php echo truncateAddress($donAccount); ?></a>
</li>
<li>Made by <a href="https://github.com/NanoTools" target="_blank" rel="noopener">Nano Tools</a></li>
</ul>
</small>
</footer>
Expand All @@ -50,7 +49,7 @@

<script src="static/js/axios.min.js?v=<?php echo PROJECT_VERSION; ?>"></script>
<script src="static/js/bootstrap-native-v4.min.js?v=<?php echo PROJECT_VERSION; ?>"></script>
<script src="static/js/handlebars-v4.1.2.js?v=<?php echo PROJECT_VERSION; ?>"></script>
<script src="static/js/handlebars.min-v4.7.6.js?v=<?php echo PROJECT_VERSION; ?>"></script>
<script src="static/js/main.js?v=<?php echo PROJECT_VERSION; ?>"></script>

<?php
Expand Down
Loading

0 comments on commit 508b9c8

Please sign in to comment.