https://github.com/alpgokcek/perfanalyticsapi
PerfAnalytics.API is a restful API which saves data, posted from PerfAnalytics.JS and returns time specific filtered data.
https://github.com/alpgokcek/perfanalyticsapi
docker jest mongodb nodejs postman travis-ci typescript
Last synced: 12 months ago
JSON representation
PerfAnalytics.API is a restful API which saves data, posted from PerfAnalytics.JS and returns time specific filtered data.
- Host: GitHub
- URL: https://github.com/alpgokcek/perfanalyticsapi
- Owner: alpgokcek
- License: mit
- Created: 2021-05-22T14:23:39.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-05-23T10:03:54.000Z (almost 5 years ago)
- Last Synced: 2025-02-02T00:33:45.249Z (about 1 year ago)
- Topics: docker, jest, mongodb, nodejs, postman, travis-ci, typescript
- Language: TypeScript
- Homepage: https://api-perf-analytics.herokuapp.com
- Size: 164 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README








# PerfAnalyticsAPI
PerfAnalytics.API is a restful API which saves data, posted from PerfAnalytics.JS and returns time specific filtered data. Application is deployed to Heroku and could be found on [api-perf-analytics.herokuapp.com](https://api-perf-analytics.herokuapp.com).
## Table of Contents:
- [Getting Started](#getting-started)
- [Requirements](#requirements)
- [With Docker](#with-docker)
- [Without Docker](#without-docker)
- [Building the Project](#building-the-project)
- [Running the Tests](#running-the-tests)
- [Environment Variables](#environment-variables)
- [API Endpoints and Documentations](#api-endpoints-and-documentations)
- [GET `/metrics`](#get-metrics)
- [POST `/metrics`](#post-metrics)
- [Contact Information](#contact-information)
- [License](#license)
## Getting Started
### Requirements:
- MongoDB v4.4 or higher -> [mongoDB Installation Page](https://docs.mongodb.com/manual/installation)
- Node v12 or higher (with npm) -> [Node.js Downloads Page](https://nodejs.org/en/download)
- Yarn Package Manager -> Install yarn with npm: `npm install -g yarn`
- Docker v3.3.2 or higher (optional) -> [Docker Get Started Page](https://www.docker.com/get-started)
Before starting the application, fork/download/clone this repo. There are two different ways to run the application:
### With Docker
- Build the docker image with the following code:
```
./docker-build.sh # for mac users
./docker-build.bat # for windows users
```
- To run the application on [localhost:8080](http://localhost:8080):
```
docker-compose up -d --build
```
- To stop the application:
```
docker-compose stop
```
### Without Docker
- Install the required dependencies:
```
yarn install
```
- To run the application in dev mode on [localhost:5000](http://localhost:5000):
```
yarn run dev
```
- To run the application with the production build on [localhost:5000](http://localhost:5000):
```
yarn build # producing a production build
cp -r src/swagger dist/src # copy swagger config to dist
yarn start # running the server
```
## Building the Project
- To create an optimized production build:
```
npm run build
```
or
```
yarn build
```
## Running the Tests
- To run the unit tests:
```
npm test
```
or
```
yarn test
```
- To run the load tests:
```
npm run artillary-local # use artillary-prod for heroku app
```
or
```
yarn run artillary-local # use artillary-prod for heroku app
```
## Environment Variables
- `DB_URI`: MongoDB URI. An example could be found below.
```
mongodb+srv://:@/?retryWrites=true&w=majority
```
- `PORT`: Port of the server.
## API Endpoints and Documentations
REST API endpoints documentation. For further information, you can check out the Postman Collections & Environments at `postman` directory and the Swagger Documentation from `/swagger` endpoint.
`/metrics` endpoint can handle 266.67 requests per second on a:
- MacBook Pro (16-inch, 2019)
- Processor: 2,3 GHz 8-Core Intel Core i9
- Memory: 16 GB 2667 MHz
- Number of Processors: 1
- Total Number of Cores: 8
- L2 Cache (per Core): 256 KB
- L3 Cache: 16 MBDDR4
For further information, checkout `load-testing-report.json` file.
### GET `/metrics`
- Description: Get Metrics from last 30 minutes or within a time range.
- Query Parameters:
- `startDate`: Start date of the time range. Must be in ISO8601 format. E.g. 2021-05-10T00:00:00.000Z
- `endDate`: End date of the time range. Must be in ISO8601 format. E.g. 2021-05-10T00:00:00.000Z
#### Reponse:
```
{
"data": [
{
"id": string,
"url": string,
"ttfb": number,
"fcp": number,
"domLoad": number,
"windowLoadEvents": number,
"resources": [
{
"name": string
"source": string
"responseTime": number
"executionTime": number
"fetchTime": number
}
],
"timestamp": string
}
]
}
```
### POST `/metrics`
- Description: Create new Metric.
#### Request Body:
```
{
"url": string,
"ttfb": number,
"fcp": number,
"domLoad": number,
"windowLoadEvents": number,
"resources": [
{
"name": string
"source": string
"responseTime": number
"executionTime": number
"fetchTime": number
}
],
"timestamp": string
}
```
#### Reponse:
```
{
"id": string
}
```
## Contact Information
#### Author: Alp Gökçek
#### Github: alpgokcek
#### Email: alp.gokcek1@gmail.com
#### Date: May, 2021
## License
[MIT](https://choosealicense.com/licenses/mit/)