How we use OmniEdge Github Action to monitor our servers
Tags: vpn, opensource, cloud, tutorial
Published: 2022-08-10 03:55:00

There are a lot of method to monitor server status, however some of them are too heavy for us, our goal is very easy, just make sure the [public super node](https://omniedge.io/docs/article/install/customize-supernode) severs across the world are online. 

## Why monitoring

We are running 11 public super node servers located in Ohio, Oregon,Frankfurt,Tokyo,Sydney, Mumbai, SaoPaulo,Milan,Singapore,HongKong and Taipei. 

All the servers are running in the a separated cloud instance from AWS and GCP, opening the UDP port to server, help [omniedge](https://omniedge.io) nodes connect peer-to-peer, and as a fallback to relay traffic between nodes in case NAT traversal fails and a direct connection can not be established. So the supernode server is very important for users across the world. 

## How to monitor

Since the server only opens one udp port, it is easy to check the status by running a command: 

```bash
nc -v -w 2 -z -u 1.2.3.4 80  #scan port 80 of IP 1.2.3.4
```

Netcat (or nc in short) is a simple yet powerful networking command-line tool used for performing any operation in Linux related to TCP, UDP, or UNIX-domain sockets. It is quite easy to install: 
```bash
$ yum install nc                  #CentOS/RHEL
$ dnf install nc                  #Fedora
$ sudo apt-get install Netcat     #Debian/Ubuntu
```

The command use different parameters: 
- -v option enables verbose mode
- -w specifies a timeout for connection that can not be established.
- -u scan `UDP` port
- -z sets `nc` to simply scan for listening daemons, without actually sending any data to them. 

## How to connect all server in one intranet

1.[Sign up OmniEdge account](https://omniedge.io/register), and system will build a virtual network for you, get the virtual network ID, and create a Security Key from [Dashboard](https://omniedge.io/dashboard).

2.Instal Docker, and run the command with your own Security-key and Virtual Network ID in all severs:
```bash
sudo docker run -d \
  -e OMNIEDGE_SECURITYKEY=Security-key \
  -e OMNIEDGE_VIRUTALNETWORK_ID="Virtual Network ID" \
  --network host \
  --privileged \
  omniedge/omniedge:latest
```

3.You will see all the server are listed in your virtual network dashboard.

## Use Github action with to monitor

We have connected all the super nodes into an intranet, and we would like to the check internally. So we bring GitHub action into the intranet, to check the status through a peer-to-peer connection without their internal IP rather than the public IP. 

Here is the step to setup the GitHub action to check the status and update readme.

1. Create a workflow in your GitHub repo
```
mkdir -p /.github/workflows/check-server-status.yml
```

2.Setup the environment variable, switch to `your-repo-address/settings/secrets/actions`, create the `Repository secrets` with the name: 

```
  SERVER_IPs #Servers IP and name with format: server_name, IP
  PORT # 80
  OMNIEDGE_SECURITY_KEY #OmniEdge security_key
  OMNIEDGE_VIRTUALNETWORK_ID #OmniEdge Virtual network ID
```

3.[Sign up OmniEdge account](https://omniedge.io/register) to get the `OMNIEDGE_SECURITY_KEY` and `OMNIEDGE_VIRTUALNETWORK_ID` from [Dashboard](https://omniedge.io/dashboard), fill them in the step 2

4.Edit `check-server-status.yml` file, add [OmniEdge for GitHub Action](https://github.com/marketplace/actions/omniedge-for-github-action).
```
- name: OmniEdge for Github Action
  uses: omniedgeio/github-action@v1
  with:
    securitykey: ${{ secrets.OMNIEDGE_SECURITY_KEY }}
    virtualnetworkid: ${{ secrets.OMNIEDGE_VIRTUALNETWORK_ID }}
```

5.Set the checking schedule, here we do it every 5 hours
```
- cron: "0 */5 * * *"
```

6.you can copy the whole workflow from the link [https://github.com/omniedgeio/server-status/blob/main/.github/workflows/check-server-status.yml](https://github.com/omniedgeio/server-status/blob/main/.github/workflows/check-server-status.yml)

7.Push your commit to repo, and you can see the action is running and a new **README.md** will be generated after 1 minute.

![Server Status check with OmniEdge](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jansomtg1aqriv94i30x.png)

Yes, the Readme shows HongKong is offline, but it is not actually. **nc** command is not working properly always, if you have better command, let me know please. 

Thanks.

Here is the whole running repo: [https://github.com/omniedgeio/server-status](https://github.com/omniedgeio/server-status)