-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
4,286 additions
and
2,800 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.DS_Store | ||
.idea | ||
server/node_modules | ||
.access-key | ||
.raid | ||
node_modules | ||
*.db | ||
config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,60 @@ | ||
# highload-stats | ||
HGLS Statistics server in real-time graphs, light powerful stats. | ||
![Preview](web/preview/latest.png) | ||
HGLS Statistics – stats on servers in real-time graphs and history, easy and powerful. | ||
|
||
![Preview](web/preview/v2.png) | ||
|
||
## Install for Debian/Ubuntu/... | ||
Execute in console | ||
* Get code | ||
```bash | ||
cd ~ && git clone https://github.com/oxmix/highload-stats.git | ||
``` | ||
* Install nodejs and sysutils | ||
```bash | ||
curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash - \ | ||
&& sudo apt-get update && sudo apt-get install nodejs ifstat sysstat | ||
``` | ||
* Install node depends | ||
```bash | ||
cd ~/highload-stats/server && chmod +x server.js && npm i | ||
``` | ||
* If need postgres, redis, mysql | ||
```bash | ||
sudo apt-get install redis-tools postgresql-client mysql-client | ||
``` | ||
|
||
* If need telemetry stats disks | ||
* Get code and install | ||
```bash | ||
sudo apt install smartmontools | ||
cd ~ && git clone https://github.com/oxmix/highload-stats.git && cd ./highload-stats/server && bash ./install.sh | ||
``` | ||
|
||
## Run | ||
* in console # `sudo ./server/server.js start` maybe also `stop|restart` | ||
* open in browser `http://remote.host.io:3939` | ||
## Settings autostart through systemd | ||
* run in console # `sudo ./systemd.sh` | ||
* then use `systemctl status hgls` or `journalctl -fu hgls` | ||
* open in browser [`http://remote.host.io:8039`](http://remote.host.io:8039) or [`http://127.0.0.1:8039`](http://127.0.0.1:8039) | ||
|
||
## If need only through access by key | ||
* go to, console # `cd ~/highload-stats/server` | ||
* create file .access-key in folder ./server, console # `</dev/urandom | fold -w 32 | head -n 1 | sha256sum | awk '{print $1}' > .access-key` | ||
* now restart, console # `sudo ./server.js restart` | ||
* open in browser `http://remote.host.io:3939/-access-key-`, your -access-key- in file .access_key | ||
## Required | ||
* Don't forget open firewall port 3939 for connection hgls-collectors | ||
* Or settings proxy through nginx | ||
|
||
## If need get telemetry | ||
* open in browser or curl `http://remote.host.io:3939/telemetry` or `http://remote.host.io:3939/-access-key-/telemetry` | ||
## Install hgls-collector | ||
* Install and run collector for each server [https://github.com/oxmix/hgls-collector](https://github.com/oxmix/hgls-collector) | ||
|
||
## Debug | ||
* back-end - run console `sudo ./server/server.js debug` or only `info|warn|error` | ||
* frond-end - `./web/external/common.js` => `debug: true` | ||
* also check logs maybe errors `tail -f ./server/hgls-error.log` | ||
### Run without systemd | ||
* in console # `./index.js start` maybe also `stop|restart|debug` | ||
* open in browser [`http://remote.host.io:8039`](http://remote.host.io:8039) or [`http://127.0.0.1:8039`](http://127.0.0.1:8039) | ||
* also check logs maybe errors `tail -f ./hgls-error.log` | ||
|
||
## Settings autostart through systemd | ||
* run in console # `sudo ./systemd.sh` | ||
* then use `systemctl status hgls` | ||
### If need get telemetry | ||
* open in browser or curl `http://remote.host.io:8939/telemetry` | ||
|
||
## Settings Proxy | ||
### Settings proxy | ||
Example for proxy nginx >= 1.3.13 | ||
```nginx | ||
server { | ||
location /highload-stats/ { | ||
proxy_pass http://remote.host.io:3939; | ||
listen 80; | ||
server_name remote.host.io; | ||
location / { | ||
proxy_pass http://127.0.0.1:8039; | ||
proxy_http_version 1.1; | ||
proxy_read_timeout 200s; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection "upgrade"; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
} | ||
} | ||
``` | ||
## Setting access to MySql | ||
```bash | ||
echo '[client] | ||
host=127.0.0.1 | ||
user=root-or-other | ||
password=***pass***' >> /root/.my.cnf | ||
``` | ||
## Setting PgBouncer | ||
```bash | ||
echo '"pgbouncer" ""' >> /etc/pgbouncer/userlist.txt && systemctl restart pgbouncer | ||
``` | ||
|
||
## Enable stats for Nginx and FPM | ||
* Nginx add server | ||
```nginx | ||
server { | ||
listen 80 default; | ||
listen [::]:80 ipv6only=on; | ||
server_name default; | ||
location / { | ||
return 444; | ||
} | ||
location /hgls-nginx { | ||
stub_status on; | ||
access_log off; | ||
allow 127.0.0.1; | ||
deny all; | ||
} | ||
location /hgls-fpm { | ||
access_log off; | ||
include /etc/nginx/fastcgi_params; | ||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
fastcgi_pass unix:/run/phpX.X-fpm.sock; | ||
allow 127.0.0.1; | ||
deny all; | ||
location /collector { | ||
proxy_pass http://127.0.0.1:3939; | ||
proxy_http_version 1.1; | ||
proxy_read_timeout 200s; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection "upgrade"; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
} | ||
} | ||
``` | ||
* FPM | ||
```bash | ||
sed -i 's/;pm.status_path = \/status/pm.status_path = \/hgls-fpm/' /etc/php/X.X/fpm/pool.d/www.conf | ||
``` | ||
* Then | ||
```bash | ||
nginx -s reload && systemctl restart phpX.X-fpm | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ ! -f "./server/config.js" ]]; then | ||
cp ./server/config.default.js ./server/config.js | ||
fi | ||
|
||
chmod +x ./systemd.sh | ||
chmod +x ./server/index.js | ||
|
||
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - \ | ||
&& sudo apt-get -y update \ | ||
&& sudo apt-get install nodejs php-cli | ||
|
||
cd ./server && npm i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const | ||
config = require('./config'), | ||
helpers = require('./helpers'), | ||
ws = require('ws'), | ||
http = require('http'); | ||
|
||
/** | ||
* Collector server | ||
* @type {Function} | ||
*/ | ||
module.exports.start = (function (call) { | ||
const app = http.createServer(function (req, res) { | ||
res.writeHead(403); | ||
res.end('hgls-collector: 403'); | ||
}).listen(config.collector.port, config.collector.host); | ||
|
||
let wss = new ws.Server({server: app}); | ||
wss.on('connection', function (ws, req) { | ||
let remoteAddress = ws._socket.remoteAddress; | ||
if ('x-forwarded-for' in req.headers) | ||
remoteAddress = req.headers['x-forwarded-for'].split(/\s*,\s*/)[0]; | ||
|
||
helpers.log('info', '[collector] new connect, ip: ' + remoteAddress); | ||
|
||
if (config.collector.allowIps.indexOf(remoteAddress) === -1) { | ||
helpers.log('error', '[collector] access deny, ip: ' + remoteAddress); | ||
ws.close(); | ||
return; | ||
} | ||
|
||
ws.hgls = { | ||
pong: (new Date).getTime(), | ||
timeCreate: (new Date).getTime(), | ||
remoteAddress: remoteAddress | ||
} | ||
|
||
ws.on('message', function (json) { | ||
try { | ||
var obj = JSON.parse(json); | ||
} catch (err) { | ||
return helpers.log('error', '[collector] json parse error: ' + err.toString()); | ||
} | ||
|
||
if (!('hostname' in obj)) { | ||
return helpers.log('error', '[collector] undefined hostname'); | ||
} | ||
|
||
if (call) { | ||
call(obj) | ||
} | ||
|
||
helpers.log('debug', '[collector] message: ' + json); | ||
}); | ||
|
||
ws.on('close', function (errorId) { | ||
ws.terminate(); | ||
helpers.log('info', '[collector] close[' + errorId + ']'); | ||
}); | ||
|
||
ws.on('pong', function (_data) { | ||
ws.hgls.pong = (new Date).getTime(); | ||
}); | ||
|
||
ws.on('disconnect', function () { | ||
helpers.log('warn', '[collector] disconnecting'); | ||
}); | ||
|
||
ws.on('error', function (error) { | ||
helpers.log('error', '[collector] ' + error); | ||
}); | ||
}); | ||
|
||
helpers.log('info', '[collector] server start: ' + config.collector.host + ':' + config.collector.port); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
web: { | ||
host: '0.0.0.0', | ||
port: 8039 | ||
}, | ||
collector: { | ||
host: '0.0.0.0', | ||
port: 3939, | ||
|
||
/** | ||
* List ipv4 addresses allowing push stats from hgls-collector | ||
*/ | ||
allowIps: [ | ||
'127.0.0.1', | ||
] | ||
} | ||
}; |
Oops, something went wrong.