# N|Solid Management Console

The Console provides valuable insight into clusters of N|Solid processes running in a variety of configurations. Processes are grouped by their associated application which makes it simple to find outliers in memory/cpu utilization and quickly identify unexpected behavior.


## System Requirements

* 2+gb of free ram
* [git](https://git-scm.com/downloads) or the github desktop application for your platform ([mac](https://mac.github.com/) / [windows](https://windows.github.com/))
* [nsolid](https://nsolid-download.nodesource.com/download/release/v0.3.6/) installed
* [etcd](https://github.com/coreos/etcd) installed (`brew install etcd` on OSX)

__install N|Solid Console__

```
git clone git@github.com:/nodesource/nsolid-console.git
cd nsolid-console
npm install
```

## Local Preview

This is intended for folks who pass by and want to play with the console.

```
npm run demo
```

then open [http://localhost:3000/](http://localhost:3000/) in Chrome/Firefox

This demo script includes a leaky http server running on port 10000, which you can use to demonstrate memory leaks:

by running:

```
ab -c 1 -n 500 http://localhost:10000/
ab -c 1 -n 500 http://localhost:10000/
ab -c 1 -n 500 http://localhost:10000/
```

this will make the leaky http server process use about 1500mb of memory. To trigger garbage collection:

```
curl -X DELETE :10000
```

__Note__: garbage collection may take a few seconds

## Developing `nsolid-console`

### Usage

If you would rather run this inside of a virtual machine, see the [Vagrant](#vagrant) section below

Otherwise, you will need 5+ terminal tabs open running the following:

1. etcd

	```
	etcd
	```

2. N|Solid Proxy

	```
	cd nsolid-console
	npm run proxy
	```

3. N|Solid Console

	```
	cd nsolid-console
	npm start
	```

4. N|Solid Collector

	```
	cd nsolid-console
	npm run collector
	```

5. Run a scenario

	```
	cd nsolid-console
	NSOLID_APPNAME="beees" node bin/simulate.js test/simulator/scenarios.js/noop@10 test/simulator/scenarios/leaky-http.js@10
	```


then open [http://localhost:3000/](http://localhost:3000/) in Chrome/Firefox

__Note__: to get multiple applications running, run another scenario and change the `NSOLID_APPNAME=""`. Further documentation can be found in the [Using the Simulator](#using-the-simulator) section below.

### Linting

This project includes React-friendly ESLint configuration.

```
npm run lint
```

### Using `0.0.0.0` as Host

You may want to change the host in `server.js` and `webpack.config.js` from `0.0.0.0` to `localhost`. This is enabled by default but it is reported to cause problems on Windows.

### Vagrant

#### setup

* Install [virtualbox](https://www.virtualbox.org/wiki/Downloads)
* Install [vagrant](http://www.vagrantup.com/downloads.html)
* Add your private key to your local ssh keyserver: `ssh-add ~/.ssh/id_rsa`
* Ensure that you are added as a collaborator to all the nsolid repos on github
* Run `vagrant up` in the root of the repo

#### daemons

If you need to connect to the running consoles attached to the various daemons use this:

```vagrant ssh -c 'screen -r NAME'```

where `NAME` is:

* `etcd`
* `proxy`
* `collect`
* `console`
* `noop1`
* `noop2`
* `noop3`

To detach from the console, type `Ctrl-AD`.

#### production

`npm run production` will bring up the static server (if this doesn't work, try building the static files with `webpack` first via `npm run build`)

#### webpack-dev-server

If you are developing, there is a bug in VirtualBox local shares that will keep hot reloading from triggering correctly. You can fix this by running `vagrant rsync-auto` on the host machine. You don't need to worry about this for a demo.

### Using the Collector

`npm run collector`

If you do not have nsolid installed on your system, you can provide a path to `nsolid-cli` by providing an `NSOLID_CLI` environment variable

`NSOLID_CLI=/path/to/nsolid/bin/nsolid-cli npm run collector`

At the time of this writing the collector will poll the N|Solid Hub every 5 seconds and push an update through clients connected to a websocket server (running on port 3001)

To setup the N|Solid Hub and other development infrastructure see: [Getting Started With N|Solid + N|Solid Hub](https://nodesource.slack.com/files/tmpvar/F07NZEQ4T/Getting_Started_With_N_Solid___N_Solid_Hub)

### Using the Simulator

`node bin/simulate.js path/to/scenario.js@10 path/to/other.js@5`

where `@10` means run 10 instances of `path/to/scenario.js`

More pre-built scenarios can be found in [test/simulator/scenarios](test/simulator/scenarios).

### bin

There are a few scripts in `bin/` to do things with the collector. All of them have a `--help` CLI arg, if you'd like to know what options you have.

*  `./bin/nsolid-console.js` - collect info from nsolid hub, and serve a websocket for frontend client connections
*  `./bin/nrecord.js` - same as `nsolid-console.js`, but it will record a scenerio for playback using `nplay.js`
*  `./bin/nplay.js` - play a recorded scenerio for to frontend clients
*  `./bin/simulate.js` - simulate a scenario (prebaked scenarios live in [test/simulator/scenarios](test/simulator/scenarios))
