0.5.0-0 • Published 9 years ago

uri-monitor v0.5.0-0

Weekly downloads
5
License
MIT
Repository
github
Last release
9 years ago

:toc: macro :toc-title: :toclevels: 9

URI Monitor

image:https://circleci.com/gh/jasonkuhrt/uri-monitor.svg?style=svg["Circle CI", link="https://circleci.com/gh/jasonkuhrt/uri-monitor"]

toc::[]

Installation

npm install --save uri-monitor

Examples

Basis for following examples:

import Monitor from 'uri-monitor'

const monitor = Monitor.create('https://foo.io', 1500)

Monitoring outages:

const serviceChanges = monitor.filter(({ type }) => type === 'change')

serviceChanges
.filter({ data: { isResponsive }} => !isResponsive)
.observe(({ data: { result }}) => console.warn('Service Down!', result))

serviceChanges
.filter({ data: { isResponsive }} => isResponsive)
.observe(() => console.warn('Service Up!'))

Monitoring outages via <<convenience-streams-on-stream, Stream sugar>>:

monitor
.downs
.observe(() => console.warn('Service Down!'))

serviceChanges
.ups
.observe(() => console.warn('Service Up!'))

API

.create

create :: String, Maybe Integer -> Stream MonitorEvent
--        uri     interval
  • uri The URI that periodic GET requests will be made to.

  • interval Optional, defaults to 1000. The milliseconds between each request. Note this is not the time between a response and the next request because requests are evenly staggered. For example:

+

--- = Time    Q = Request    R = Response

Q1----R1-Q2-R2----Q3--R3---Q4--
^        ^        ^        ^    <== Evenly staggered

+ A response cannot temporally leak into the next request because each request is configured to timeout within the interval.

Definition of request failure

The following will cause the result of a request to be considered a failure:

  • Request is not responded to within interval
  • Response HTTP Status Code is >= 400.
  • Any general HTTP Error (e.g. a client-side CORS error)

In all of these cases data.isResponsive will be false and data.result will be either a <<requesterror, RequestError>> or <<networkerror, NetworkError>>.

Convenience streams on Stream

The <<stream,Stream>> returned by <<create, create>> is monkey patched with filtered variants for common patterns. They are:

.pongs
pongs :: Stream CheckedEvent

<<checkedevent, CheckedEvents>> where data.isResponsive is true.

.drops
drops :: Stream CheckedEvent

<<checkedevent, CheckedEvents>> where data.isResponsive is false.

.ups
ups :: Stream ChangedEvent

<<changedevent, ChangedEvents>> where data.isResponsive is true.

.downs
ups :: Stream ChangedEvent

<<changedevent, ChangedEvents>> where data.isResponsive is false.

Types

Stream

An instance of link:https://github.com/cujojs/most/blob/master/docs/api.md[most].

MonitorEvent

Base interface that all emitted events implement. If isResponsive is false then result is either a <<requesterror, RequestError>> or <<networkerror, NetworkError>> otherwise result is a <<response, Response>>.

type : String
data :
  isResponsive: Bool
  result: CheckResult
CheckedEvent

Emitted every time a result of a request is available.

type: "checked"
data:
  isResponsive: Bool
  result: CheckResult
ChangedEvent

Emitted every time a result of a request has a different isResponsive value than the previous result.

type: "changed"
data:
  isResponsive: Bool
  result: CheckResult

CheckResult

RequestError | NetworkError | Response

Response

A link:https://visionmedia.github.io/superagent/#response-properties[Superagent Response].

RequestError

message: String
status: Integer
body: Object
res: Response

NetworkError

message: String
originalError: Object
0.5.0-0

9 years ago

0.4.0

10 years ago

0.3.0

11 years ago

0.2.0

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago