Skip to content

PerfAnalytics.API is a restful API which saves data, posted from PerfAnalytics.JS and returns time specific filtered data.

License

Notifications You must be signed in to change notification settings

alpgokcek/PerfAnalyticsAPI

Repository files navigation

Typescript Docker Node.js npm yarn swagger express MongoDB

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.

Table of Contents:


Getting Started


Requirements:


  • MongoDB v4.4 or higher -> mongoDB Installation Page

  • Node v12 or higher (with npm) -> Node.js Downloads Page

  • Yarn Package Manager -> Install yarn with npm: npm install -g yarn

  • Docker v3.3.2 or higher (optional) -> Docker Get Started Page

    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
docker-compose up -d --build
  • To stop the application:
docker-compose stop

Without Docker


  • Install the required dependencies:
yarn install
yarn run dev
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://<db-user>:<db-pass>@<cluster-address>/<db-name>?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

Date: May, 2021


License


MIT

About

PerfAnalytics.API is a restful API which saves data, posted from PerfAnalytics.JS and returns time specific filtered data.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published