Skip to content

Commit

Permalink
Merge pull request #45 from sophie0730/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sophie0730 authored Jan 1, 2024
2 parents 378f4ff + 601a7f5 commit 8ce3dd7
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 120 deletions.
299 changes: 226 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,173 @@

# PulseTracker

This document provides step-by-step instructions to set up PulseTracker on your Linux environment. Please ensure you follow each step carefully for a successfuly installation.
![release](https://badgen.net/github/release/sophie0730/PulseTracker/stable)

PulseTracker is an application for developers to monitor server and application status in one place, and trigger alerts.

It allows users to configure their alerting rules and metrics target URLs using YAML files.

![pulsetracker](https://github.com/sophie0730/PulseTracker/assets/112261858/a02247b7-791f-422d-ade9-fb4f5cedb316)

## Menu

[Prerequisites](#prerequisites) | [Install](#install) | [Environment Variables](#environment-variables) | [YAML File Configuration](#yaml-file-configuration) | [Getting Started](#getting-started) | [Features](#Features) | [Architecture Overview](#architecture-overview) | [Built With](#built-with) | [Contact](#contact)

## Prerequisites

Please make sure your Linux environment is prepared before you start the installation process.

1. Docker Installation:
**1. Docker Installation**

PulseTracker requires Docker. If you haven't installed Docker yet, please follow the instructions provided in the Docker document:
PulseTracker requires Docker. If you haven't installed Docker yet, please follow the instructions provided in the Docker document: [Install Docker on Ubuntu](https://docs.docker.com/engine/install/ubuntu/).

- Please install Docker in you Linux Environment first.
You can refer to the below document for install process.
https://docs.docker.com/engine/install/ubuntu/
**2. Linux Commands**

Run the following commands to update your system and install necessary tools:
```
sudo apt-get update
sudo apt-get install sysstat
```

- Please install the below Linux command:
```
sudo apt-get update
sudo apt-get install sysstat
```
- Please always make sure your Linux time is corrrect.
You can use ntp tool to adjust your environment time.
```
sudo apt update
sudo apt install ntp
sudo systemctl start ntp
**3. Time Synchronization**

sudo systemctl enable ntp
```
Ensure your Linux system time is accurate. Use the NTP tool for time synchronization.
```
sudo apt update
sudo apt install ntp
sudo systemctl start ntp

sudo systemctl enable ntp
```

**4. Nginx Installation (optional)**

If you plan to use `nginx_exporter`, please install Nginx on your machine first.

- If you would like to use `nginx_exporter`, please install Nginx in your machine first.
**5. Network setting for AWS services**

- Please add port 4000, 9100, 9101, 8086 and 6379 in the inbounding rules on the security groups if you are using AWS EC2 services.
For AWS EC2 users, add ports 4000, 9100, 9101, 8086, 6379 to the inbound rules of your security group.

<p align="right"><a href="#top">Back to Top</a></p>

## Install

- Download the compressed file from Github releases.
You can refer to Github releases and download your preffered version
```
wget [package_release_url]
```
Precompiled binaries for released versions are available in the
[GitHub Releases](https://github.com/sophie0730/PulseTracker/releases). Using the latest release binary
is the recommended way of installing PulseTracker.

- Create a new directory and decompress the file
Follow these steps to set up and start using PulseTracker on your machine.

**1. Download and Decompress the Release Package**

Download your preffered version of PulseTracker from the GitHub Release.
```
wget [GitHub_release_package_url]
tar xvf [package_name].tar
```

- Use docker compose to setup InfluxDB and Redis
If you have already installed these two services on your machine, you can modify `docker-compose.yml` as you needed.
**2. Setting Up InfluxDB and Redis with Docker Compose**

If InfluxDB or Redis has been installed on your machine, you may need to config `docker-compose.yml` to suit your setup.

Then, start the services using Docker Compose.
```
docker compose up -d
```

- Please sign in InfluxDB([YOUR HOST]:8086) to create a organization, bucket and API token. They will be used for storing your data.
**3. Config InfluxDB**

Access InfluxDB at [HOST]:8086 and set up an `organization`, a `bucket`, and an `API token`.

**4. Update Environment setting**

Modify the `.env.templete` with your InfluxDB settings. Remember to rename this file to `.env` after you entered all the necessary information.

- Edit .env.template according to your InfluxDB settings. Please remember to rename it to .env after editing all the required information.
Please refer to [Environment Variable] section for detail setting information.

- Edit pulse.yml and alert.yml based on your needs and environment setting.
**5. Customize Configuration Files**

- (optional) If you would like to send email or Line message, please register a SMTP server(Mailgun or other services) and Line notify(https://notify-bot.line.me/zh_TW/) token.
Modify `pulse.yml` and `alert.yml` according to your specific needs and environment setting.

**6. Optional: Email and Line Notification**

If you need to send alerts via emails or Line messages, register with a SMTP server (like Mailgun) and obtain a Line Notify token from [Line Notify](https://notify-bot.line.me/zh_TW/).

**7. Start the Exporters**

To fetch system-level data and application-level data, please launch the system and nginx exporters. By default, these exporters run on port 9100(server) and 9101(nginx).

- Execute exporters (system and nginx application)
```
./server_exporter
```
```
./nginx_exporter
```
These two exporters will be running on port 9100(server) and 9101(nginx) by default.

- Execute PulseTracker server
**8. Run PulseTracker server**

Finally, start PulseTracker server.
```
./pulsetracker
```

Now, you are able to use PulseTracker application on your machine.
You are now ready to use PulseTracker on your machine.

<p align="right"><a href="#top">Back to Top</a></p>

## Environment Variables

To run this project, you will need to add the following environment variables to your .env file

`INFLUXDB_URL` : This should be set according to the host and port of your InfluxDB.

`ORG`, `BUCKET` : These values should be configured based on your [initial setup](#Install) of InfluxDB.

`MEASUREMENT`, `ALERT_MEASUREMENT`: These are the names of the tables where your data is stored. You can assign any names you prefer.

`TOKEN`: API token you set for InfluxDB.

`EMAIL_USER`, `EMAIL_TOKEN`: These should be set according to your SMTP configuration.

`LINE_URL`, `LINE_TOKEN`: These should be configured based on your Line Notify setting.

```
# Please follow the below example
#INFLUXDB_URL based on your host and port
INFLUXDB_URL='http://52.62.225.143:8086'
# ORG and BUCKET based on your setting on InfluxDB
ORG='personal'
BUCKET='pulse_tracker'
# You can named what you want for MEASUREMENT and ALERT_MEASUREMENT
MEASUREMENT='metrices'
ALERT_MEASUREMENT='alert'
# The API token you set on InfluxDB
TOKEN=''
# (optional) If you want to set email and Line message function
# Please use SMTP server (e.g. Mailgun) and Line Notify service
EMAIL_USER='[email protected]'
EMAIL_TOKEN=''
LINE_URL='https://notify-api.line.me/api/notify'
LINE_TOKEN=''
```

<p align="right"><a href="#top">Back to Top</a></p>

## Config Files
Please refer to the corresponding examples for each config file.
## YAML File Configuration

- docker-compose.yml
**Pulse.yml**

If you want to modify Docker setting for InfluxDB or Redis services, please refer to this file.
You can customize some PulseTracker settings through this yaml file. This includes configuring the worker frequency, setting up alerting receivers and specifying target URLs for metrics.

- Pulse.yml
An example configuration is provided below for reference.
```
global:
store_timeout: 10 # set store metrices worker every 10 seconds. unit: second
Expand Down Expand Up @@ -135,7 +219,10 @@ scrape_configs:
metrics_path: '/metrics'
```

- alert.yml
**alert.yml**

You have the flexibility to add or remove alerting rules as per your requirements.

```
groups:
# Please add your alerting rules
Expand All @@ -146,7 +233,8 @@ groups:
for: # The duration of
annotations:
summary: # The summary of this rule.
```
```
# For example
groups:
- name: server_is_down
Expand All @@ -158,34 +246,99 @@ groups:
summary: Server(s) are down.
```

- .env
```
# Please follow the below example
#INFLUXDB_URL based on your host and port
INFLUXDB_URL='http://52.62.225.143:8086'
# ORG and BUCKET based on your setting on InfluxDB
ORG='personal'
BUCKET='pulse_tracker'
# You can named what you want for MEASUREMENT and ALERT_MEASUREMENT
MEASUREMENT='metrices'
ALERT_MEASUREMENT='alert'
# The API token you set on InfluxDB
TOKEN=''
# (optional) If you want to set email and Line message function
# Please use SMTP server (e.g. Mailgun) and Line Notify service
EMAIL_USER='[email protected]'
EMAIL_TOKEN=''
LINE_URL='https://notify-api.line.me/api/notify'
LINE_TOKEN=''
```

- dashboard-table.json and dashboard-graph.json
<p align="right"><a href="#top">Back to Top</a></p>

## Getting Started

- Create a dashboard
![create_dashboard (1)](https://github.com/sophie0730/PulseTracker/assets/112261858/d7cf00f4-2308-4822-b15b-9a57d3db32c2)

- Add graph in your dashboard
![add_graph (1) (1)](https://github.com/sophie0730/PulseTracker/assets/112261858/7f080110-ccd1-462b-a796-a9b8f8b0fe2b)


<p align="right"><a href="#top">Back to Top</a></p>

## Features
- Dashboard
![dashboard](https://github.com/sophie0730/PulseTracker/assets/112261858/ba203a91-f691-4be2-abe4-f10f7e69f8d6)

- Change graph type as per your requirement.
![change_graph](./documentation/images/change_graph_type%20(1).gif)


- Target status
![target_status](https://github.com/sophie0730/PulseTracker/assets/112261858/6a16a00d-767b-4763-8da3-886de84eb10a)

- Alerts
![alert](https://github.com/sophie0730/PulseTracker/assets/112261858/21b8f9ef-2567-4330-99ba-cbe86e45334c)


- Config alerting rules as per your requirement.
![config_alert](./documentation/images/config_alertt.gif)

- Triggering alerts
![send_alert](./documentation/images/send_alert.gif)

<p align="right"><a href="#top">Back to Top</a></p>

## Architecture Overview

![final_structure_pulsetracker20231229](https://github.com/sophie0730/PulseTracker/assets/112261858/a54749ec-8693-43a7-a2ce-8698169bfad2)
## Built With

<table>
<tbody>
<tr>
<th text-align="center">Back-End</th>
<th>Cloud-Service</th>
<th>Front-End</th>
<th>Tools</th>
</tr>
<tr>
<td style="vertical-align:top">
<li><a href="https://nodejs.org/en/">Node.js</a></li>
<li><a href="https://expressjs.com/">Express.js</a></li>
<li><a href="https://www.mongodb.com/">MongoDB</a></li>
<li><a href="https://redis.io/">Redis</a></li>
<li><a href="https://www.docker.com/">Docker</a></li>
<li><a href="https://www.nginx.com/">Nginx</a></li>
</td>
<td style="vertical-align:top">
<li><a href="https://aws.amazon.com/ec2/">Amazon EC2</a></li>
<li><a href="https://aws.amazon.com/s3/">Amazon S3</a></li>
<li><a href="https://aws.amazon.com/cloudfront/">Amazon CloudFront</a></li>
<li><a href="https://aws.amazon.com/cloudwatch/">Amazon CloudWatch</a></li>
<li><a href="https://aws.amazon.com/elasticache/">Amazon ElastiCache</a></li>
<li><a href="https://aws.amazon.com/elasticloadbalancing/">Elastic Load Balancing</a></li>
<li><a href="https://aws.amazon.com/autoscaling/">AWS Auto Scaling</a></li>
</td>
<td style="vertical-align:top">
<li><a href="https://reactjs.org/">React.js</a></li>
<li><a href="https://mui.com/">MUI</a></li>
<li>HTML5</li>
<li>CSS3</li>
<li>JavaScript</li>
</td>
<td style="vertical-align:top">
<li>Git, GitHub</li>
<li><a href="https://swagger.io/tools/swaggerhub/">Swagger</a></li>
<li><a href="https://k6.io/">K6</a></li>
<li><a href="https://www.postman.com/">Postman</a></li>
<li><a href="https://mochajs.org/">Mocha</a></li>
<li><a href="https://www.chaijs.com/">Chai</a></li>
</td>
</tr>
</tbody>
</table>

<p align="right"><a href="#top">Back to Top</a></p>

## Contact

- [Sophie (Hsuan-Ni) Hsu (許玄妮)](https://www.github.com/sophie0730)
- Email: [email protected]

<p align="right"><a href="#top">Back to Top</a></p>

The json files which store dashboard data. Please do not edit or remove them.

Binary file added documentation/images/change_graph_type (1).gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/images/config_alertt.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/images/send_alert.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 1 addition & 6 deletions server/models/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ export async function checkAlerts(alertStates, timeRange, alertFile) {

const data = await fetchData(fluxQuery);

let startTime = '';
let endTime = '';

if (data.length === 0) {
alertStates[group.name] = null;
alertsArr.push({ groupName: group.name, value: alertStates[group.name] });
Expand All @@ -87,9 +84,7 @@ export async function checkAlerts(alertStates, timeRange, alertFile) {
if (!alertStates[group.name]) {
alertStates[group.name] = { startTime: data[0]._time, isFiring: 'pending' };
alertsArr.push({ groupName: group.name, value: alertStates[group.name] });
startTime = alertStates[group.name].startTime;
endTime = data[data.length - 1]._time;
} else if (alertStates[group.name].isFiring !== 'true' && dateInterval(startTime, endTime) >= duration) {
} else if (alertStates[group.name].isFiring !== 'true' && dateInterval(alertStates[group.name].startTime, data[data.length - 1]._time) >= duration) {
alertStates[group.name].isFiring = 'true';
alertsArr.push({ groupName: group.name, value: alertStates[group.name] });
sendEmail(group.name, group.rules[0].expr);
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
"sinon": "^17.0.1"
},
"description": ""
}
}
Loading

0 comments on commit 8ce3dd7

Please sign in to comment.