Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tpkn/sava
A tiny module that lets you check whether the server is responding or not
https://github.com/tpkn/sava
Last synced: 6 days ago
JSON representation
A tiny module that lets you check whether the server is responding or not
- Host: GitHub
- URL: https://github.com/tpkn/sava
- Owner: tpkn
- License: mit
- Created: 2020-01-23T22:54:39.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-07T21:07:34.000Z (over 4 years ago)
- Last Synced: 2024-04-25T06:02:53.263Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sava [![npm Package](https://img.shields.io/npm/v/sava.svg)](https://www.npmjs.org/package/sava)
A tiny module that lets you check whether the server is responding or not## Usage
```javascript
const ServiceAvailability = require('sava');let health = new ServiceAvailability({
url: 'https://domain.com/content/ping.jpg',
body_size: 276423,
timeout: 30,
interval: 60,
max_ping: 800,
max_errors_streak: 10,
messages: {
timeout: 'Server does not respond',
not_found: 'Wrong url',
high_ping: 'Ping is %s ms above the maximum',
wrong_body_size: 'Wrong response body size: %s bytes',
init_failed: 'Initialization failed, the file is not available'
}
})health.on('update', (data) => {
// => { date: "2020-01-23 22:37:15", status: "error", details: [ "404" ], ping: 2503 }
})health.on('alarm', () => {
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
console.log(' ALARM ALARM ALARM ALARM ALARM ALARM ALARM ALARM ALARM ALARM ');
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
})health.schedule();
```If you dont't want to calculate `body_size` of your reference file, you can call `init()` method, that will do that for you:
```js
health.on('init', ({ size }) => {
health.schedule();
console.log('size:', size);
});health.init();
```Received `body_size` will be saved to a '.cache' file.