Skip to content

Commit

Permalink
✨ Init Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
axiliquint committed Feb 13, 2022
0 parents commit a5dd8ce
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Hyra

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
37 changes: 37 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const axios = require("axios").default;

const pageId = "ckqu7nm8617021395n6p5xvlvlk";
const metricId = "ckxo16fcc189614o8ond2p5splu";

const path = "https://edge.koal.us";

require("dotenv").config();

const checkApi = () => {
const start = new Date().getTime();
axios.get(path).then(response => {
const latency = new Date().getTime() - start;

axios.post(`https://api.instatus.com/v1/${pageId}/metrics/${metricId}`,
{
timestamp: Math.floor(new Date()),
value: latency
},
{
headers: {
Authorization: "Bearer " + process.env.API_KEY
}
}).then(result => {
console.log('All went well with latency of ' + latency);
setTimeout(() => {
checkApi();
}, 30 * 1000)
}).catch(err => {
console.log(err);
})
}).catch(err => {
console.log(err);
})
}

checkApi();
72 changes: 72 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "api-latency",
"version": "1.0.0",
"description": "Latency monitor for Atlassian StatusPage",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/hyra-io/API-Latency.git"
},
"author": "Hyra",
"license": "MIT",
"bugs": {
"url": "https://github.com/hyra-io/API-Latency/issues"
},
"homepage": "https://github.com/hyra-io/API-Latency#readme",
"dependencies": {
"axios": "^0.24.0",
"dotenv": "^10.0.0"
}
}
30 changes: 30 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
### Based off of [Hyra's Atlassian Statuspage monitor](https://github.com/hyra-io/API-Latency)

# API Latency
This is a very simple monitoring script that will monitor the latency of your API server. It simply makes a request to a HTTP or HTTPS path every 30 seconds and reports the latency to [Instatus](https://instatus.com) via their API. This is used in a metric graph.

## Installation
There are a few prerequisites to run this project locally. You'll need:
* Node.js - this was built using Node.js v16.11
* All the dependencies in the package.json

Clone the repo to your system

To install the dependencies simply run `npm install`.

You'll then need to set up your environment variables.

## Operation
Once you've installed the latency monitor, you'll need to run it. To run it, we'd recommend using a process manager like [pm2](https://pm2.io/).

## Secrets
We store secrets in a `.env` file stored in the root directory of the project - you can't see this file because it's in our `.gitignore`.

Please see the format for this file below

```
API_KEY=
```

## License
This project is licensed under [MIT License](LICENSE)

0 comments on commit a5dd8ce

Please sign in to comment.