How to deploy a server monitor dashboard

Why we need Nezha or what can Nezha do for us?

We can monitor multiple server simultaneously if we have Nezha dashboard, in which we are able to see the CPU, memory, swap, network, trafic, disk info and uptime of our server. Moreover, we have the ability to be informed if there is something wrong just like the network error which make server offline.

How to deploy

For server

Create and get the github app client id and secret key

First of all, go to https://github.com/settings/developers, create a new app and enter information like below.

Screenshot 2023-10-15 at 17.00.22

Then click Register application, click Generate a new client secret to get the secret key. Remember these information as the secret key won’t appear twice.

Install dashboard on server

Connect to your server using ssh.

1
curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh  -o nezha.sh && chmod +x nezha.sh && sudo ./nezha.sh

Then enter the information following the prompt.

1
vim /etc/nginx/sites-available/00-default-ssl.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
server
{
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name your_domain;

#SSL-START SSL related config,do not change or delete the following config with annotation symbols.
#error_page 404/404.html;
ssl_certificate /etc/letsencrypt/live/your_domain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your_domain/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
error_page 497 https://$host$request_uri;

location /
{
proxy_pass http://127.0.0.1:8008;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
}
location /ws
{
proxy_pass http://127.0.0.1:8008;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $http_host;
}
}

PS: I did not write the nginx config for terminal as I do not want to use web shell in Nezha dashboard for safety considering.

1
2
# sign up ssl certificate for nezha dashboard
sudo certbot certonly --nginx -d your_domain

Setup notification

Before setup, you need to register a wxpusher account following the official instruction and bind it with your wechat account.

Go to admin, click notifications, add a notification method.

Screenshot 2023-10-16 at 08.20.38

Next, click add notification rule.

Screenshot 2023-10-16 at 08.23.51

Client connection

For Linux

I did not know why I can not install the agent via command provided by the nezha dashboard. So I need to download the script and install it manually.

1
curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh -o nezha.sh && chmod +x nezha.sh && sudo ./nezha.sh

Then install it manually by choose the number and follow the prompt. The secret key can be found in Nezha management dashboard.

For OpenWrt

1
2
3
4
5
6
# download the agent bin from github release
cd /root
wget https://github.com/nezhahq/agent/releases/download/v0.15.6/nezha-agent_linux_amd64.zip
unzip nezha-agent_linux_amd64.zip
chmod +x /root/nezha-agent
vim /etc/init.d/nezha-service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh /etc/rc.common

START=99
USE_PROCD=1

start_service() {
procd_open_instance
procd_set_param command /root/nezha-agent -s your_domain:port -p secret_key -d
procd_set_param respawn
procd_close_instance
}

stop_service() {
killall nezha-agent
}

restart() {
stop
sleep 2
start
}
1
2
chmod +x /etc/init.d/nezha-service
/etc/init.d/nezha-service enable && /etc/init.d/nezha-service start

For Synology

1
2
3
cd /root
wget https://github.com/nezhahq/agent/releases/download/v0.15.6/nezha-agent_linux_amd64.zip
unzip nezha-agent_linux_amd64.zip

Then go to your synology web page.

Control Panel > Task Scheduler > Create > Triggered Task

Screenshot 2023-10-15 at 19.33.07

Screenshot 2023-10-15 at 19.40.40

Then check this task and click run.

For Windows 10

Download nssm software from https://nssm.cc/ci/nssm-2.24-101-g897c7ad.zip, nezha agent for windows from https://github.com/nezhahq/agent/releases and unzip them.

Open cmd, and input sysdm.cpl and enter.

Screenshot 2023-10-15 at 19.58.35

Click environment variables, edit system variables, click path and click edit.

Screenshot 2023-10-15 at 20.03.41

Then add your nssm exe directory to path.

The next move, go to cmd.

1
nssm install nezha

nazha-windows05

Moving forward, click install servce, and go to cmd. Input nssm start nezha and enter. Use services.msc to check if nezha agent is running correctly.

For Windows 7

The process is similar to Windows 10.

Screenshot 2023-10-15 at 20.47.05

Screenshot 2023-10-15 at 20.47.57

Screenshot 2023-10-15 at 20.48.32

Note: If you found a error like below, you can solve this problem refering to https://www.youtube.com/watch?v=Z6IXdv-2inM&list=PL1hfaKfj6i71XBr7f5qmfEb3T67yv1PIv&index=1

395181697170112_.pic

Reference