Skip to content

Monitor Resource

Authorization

Currently monitors are only able to access the API while they are signed into the application. The API requires the access_token cookie to be present in the request.

Restrictions

There are various restrictions applied to the monitor data. The following are some of the important restrictions when creating a monitor.

Name

  • Name does not have to be unique
  • Name must be between 3 and 64 characters

URL/IP

  • Value must be a valid URL/IP
  • Value for IP must be IPv4

Method

  • Value must be one of the following GET, POST, PUT, DELETE, HEAD, OPTIONS, or PATCH

Interval, Retry Interval, Request Timeout

  • Value must be greater than 20
  • Value must be less than 600

Port for TCP

  • Value must be between 1 and 65535

Monitor Object

Partial Monitor Structure

FieldTypeDescription
monitorIdstringUnique id for the monitor
namestringName of the monitor
urlstringURL/IP of the monitor
intervalnumberInterval between each ping to monitor
retryIntervalnumberRetry interval after a failed ping
requestTimeoutnumberRequest timeout for ping
methodstringMethod for http monitor
headersobjectHeaders object for http request
bodyobjectBody object for http request
valid_status_codesarrayArray of valid status codes for http request
emailstringEmail address for the user who created the monitor
typestringType of montior (HTTP/TCP)
portnumberPort for the TCP monitor
uptimePercentagenumberUptime percentage for the monitor over the last 24 hours
averageHeartbeatLatencynumberAverage latency for the monitor over the last 24 hours

Example Partial Monitor

json
{
  "monitorId": "4d048471-9e85-428b-8050-4238f6033478",
  "name": "Lunalytics",
  "url": "https://demo.lunalytics.xyz/api/status",
  "interval": 30,
  "retryInterval": 30,
  "requestTimeout": 30,
  "method": "GET",
  "headers": {},
  "body": {},
  "valid_status_codes": ["200-299"],
  "email": "KSJaay@lunalytics.xyz",
  "type": "http",
  "port": null,
  "uptimePercentage": 83,
  "averageHeartbeatLatency": 38
}
json
{
  "monitorId": "4d048471-9e85-428b-8050-4238f6033478",
  "name": "Lunalytics TCP",
  "url": "127.0.0.1",
  "interval": 30,
  "retryInterval": 30,
  "requestTimeout": 30,
  "method": null,
  "headers": null,
  "body": null,
  "valid_status_codes": null,
  "email": "KSJaay@lunalytics.xyz",
  "type": "tcp",
  "port": 2308,
  "uptimePercentage": 83,
  "averageHeartbeatLatency": 38
}

Full Monitor Structure

FieldTypeDescription
monitorIdstringUnique id for the monitor
namestringName of the monitor
urlstringURL/IP of the monitor
intervalnumberInterval between each ping to monitor
retryIntervalnumberRetry interval after a failed ping
requestTimeoutnumberRequest timeout for ping
methodstringMethod for http monitor
headersobjectHeaders object for http request
bodyobjectBody object for http request
valid_status_codesarrayArray of valid status codes for http request
emailstringEmail address for the user who created the monitor
typestringType of montior (HTTP/TCP)
portnumberPort for the TCP monitor
uptimePercentagenumberUptime percentage for the monitor over the last 24 hours
averageHeartbeatLatencynumberAverage latency for the monitor over the last 24 hours
lastChecknumberTime of last time monitor was checked (in ms)
nextChecknumberTime of next time monitor should be checked (in ms)
heartbeatsArray<Heartbeat>Array of monitor heartbeats
certCertificateInformation about the certificate

Example Full Monitor

json
{
  "monitorId": "4d048471-9e85-428b-8050-4238f6033478",
  "name": "Lunalytics",
  "url": "https://demo.lunalytics.xyz/api/status",
  "interval": 30,
  "retryInterval": 30,
  "requestTimeout": 30,
  "method": "GET",
  "headers": {},
  "body": {},
  "valid_status_codes": ["200-299"],
  "email": "KSJaay@lunalytics.xyz",
  "type": "http",
  "port": null,
  "uptimePercentage": 83,
  "averageHeartbeatLatency": 38,
  "lastCheck": 1708092690225,
  "nextCheck": 1708095536463,
  "heartbeats": [
    {
      "id": 38,
      "status": 200,
      "latency": 38,
      "date": 1708095536463,
      "isDown": false,
      "message": "200 - OK"
    }
    {
      "id": 23,
      "status": 200,
      "latency": 38,
      "date": 1714178279326,
      "isDown": false,
      "message": "200 - OK"
    },
    ...
  ],
  "cert": {
    "isValid": true,
    "issuer": { "C": "US", "O": "Let's Encrypt", "CN": "R3" },
    "validFrom": "Apr 11 03:50:40 2024 GMT",
    "validTill": "Jul 10 03:50:39 2024 GMT",
    "validOn": ["lunalytics.xyz", "www.lunalytics.xyz"],
    "daysRemaining": "72",
    "lastCheck": 1708092690225,
    "nextCheck": 1714178279326
  }
}
json
{
  "monitorId": "4d048471-9e85-428b-8050-4238f6033478",
  "name": "Lunalytics TCP",
  "url": "127.0.0.1",
  "interval": 30,
  "retryInterval": 30,
  "requestTimeout": 30,
  "method": null,
  "headers": null,
  "body": null,
  "valid_status_codes": null,
  "email": "KSJaay@lunalytics.xyz",
  "type": "tcp",
  "port": 2308,
  "uptimePercentage": 83,
  "averageHeartbeatLatency": 38,
  "lastCheck": 1708092690225,
  "nextCheck": 1708095536463,
  "heartbeats": [
    {
      "id": 38,
      "status": "ALIVE",
      "latency": 38,
      "date": 1708095536463,
      "isDown": false,
      "message": "Up and running!"
    }
    {
      "id": 23,
      "status": "ALIVE",
      "latency": 38,
      "date": 1714178279326,
      "isDown": false,
      "message": "Up and running!"
    },
    ...
  ],
  "cert": { "isValid": false }
}

Certificate Object

Certificate Structure

FieldTypeDescription
isValidbooleanBoolean if the certificate is valid
issuerobjectInformation about the issuer of the certificate
validFromdateDate the certificate was issued
validTilldateDate the certificate expires
validOnarrayArray of urls the certificate is valid for
daysRemainingnumberNumber of days the certificate is valid
lastChecknumberTime of last time certificate was checked (in ms)
nextChecknumberTime of next time certificate should be checked (in ms)

Example Certificate

json
{
  "isValid": true,
  "issuer": { "C": "US", "O": "Let's Encrypt", "CN": "R3" },
  "validFrom": "Apr 11 03:50:40 2024 GMT",
  "validTill": "Jul 10 03:50:39 2024 GMT",
  "validOn": ["lunalytics.xyz", "www.lunalytics.xyz"],
  "daysRemaining": "72",
  "lastCheck": 1708092690225,
  "nextCheck": 1714178279326
}

Heartbeat Object

Heartbeat Structure

FieldTypeDescription
idstringUnique Id for that specific heartbeat
statusnumber/stringStatus code from request
latencynumberLatency of request
datenumberDate the request was made (in ms)
isDownbooleanBoolean if the monitor is down
messagestringMessage from request

Example Heartbeat

json
{
  "id": 23,
  "status": 200,
  "latency": 38,
  "date": 1714178279326,
  "isDown": false,
  "message": "200 - OK"
}

Add a new monitor

POST /api/monitor/add

Returns the full monitor object for the new monitor added. Only editors, admins, and owners are allow to access this endpoint.

Payload

json
{
  "name": "Lunalytics",
  "url": "https://lunalytics.xyz/api/status",
  "type": "http",
  "method": "GET",
  "valid_status_codes": ["200-299"],
  "interval": 30,
  "retryInterval": 30,
  "requestTimeout": 30
}
json
{
  "name": "Lunalytics",
  "url": "127.0.0.1",
  "type": "tcp",
  "port": 2308,
  "interval": 30,
  "retryInterval": 30,
  "requestTimeout": 30
}

HTTP Response Codes

Status CodeDescription
200Success, returns full monitor object
401Unauthorized (Missing access_token cookie or API Token)
403User is unverified
422Invalid monitor information
curl -X POST \
  -H "Content-Type:application/json" \
  -H "Authorization:API Token" \
  --data '{"name":"Lunalytics","url":"https://lunalytics.xyz/api/status","type":"http","method":"GET","valid_status_codes":["200-299"],"interval":30,"retryInterval":30,"requestTimeout":30}' \
    'https://lunalytics.xyz/api/monitor/add'
js
axios('/api/monitor/add', {
  method: 'POST',
  headers: {
    Authorization: 'API Token',
    'Content-Type': 'application/json',
  },
  data: {
    name: 'Lunalytics',
    url: 'https://lunalytics.xyz/api/status',
    type: 'http',
    method: 'GET',
    valid_status_codes: ['200-299'],
    interval: 30,
    retryInterval: 30,
    requestTimeout: 30,
  },
});

Edit a monitor

POST /api/monitor/edit

Returns the full monitor object for the edited monitor added. Only editors, admins, and owners are allow to access this endpoint.

Payload

json
{
  "monitorId": "4d048471-9e85-428b-8050-4238f6033478",
  "name": "Lunalytics",
  "url": "https://lunalytics.xyz/api/status",
  "type": "http",
  "method": "GET",
  "valid_status_codes": ["200-299"],
  "interval": 30,
  "retryInterval": 30,
  "requestTimeout": 30
}
json
{
  "monitorId": "4d048471-9e85-428b-8050-4238f6033478",
  "name": "Lunalytics",
  "url": "127.0.0.1",
  "type": "tcp",
  "port": 2308,
  "interval": 30,
  "retryInterval": 30,
  "requestTimeout": 30
}

HTTP Response Codes

Status CodeDescription
200Success, returns full monitor object
401Unauthorized (Missing access_token cookie or API Token)
403User is unverified
422Invalid monitor information
curl -X POST \
  -H "Content-Type:application/json" \
  -H "Authorization:API Token" \
  --data '{"monitorId": "4d048471-9e85-428b-8050-4238f6033478","name":"Lunalytics","url":"https://lunalytics.xyz/api/status","type":"http","method":"GET","valid_status_codes":["200-299"],"interval":30,"retryInterval":30,"requestTimeout":30}' \
    'https://lunalytics.xyz/api/monitor/edit'
js
axios('/api/monitor/edit', {
  method: 'POST',
  headers: {
    Authorization: 'API Token',
    'Content-Type': 'application/json',
  },
  data: {
    monitorId: '4d048471-9e85-428b-8050-4238f6033478',
    name: 'Lunalytics',
    url: 'https://lunalytics.xyz/api/status',
    type: 'http',
    method: 'GET',
    valid_status_codes: ['200-299'],
    interval: 30,
    retryInterval: 30,
    requestTimeout: 30,
  },
});

Delete monitor

GET /api/monitor/delete

Deletes the monitor, along with the heartbeats and certificates. Only editors, admins, and owners are allow to access this endpoint.

Query Parameters

monitorId String

Monitor id for the monitor to be deleted.

HTTP Response Codes

Status CodeDescription
200Success, return status code 200
400Bad Request, monitorId not provided
401Unauthorized (Missing access_token cookie or API Token)
403User is unverified
curl -X GET \
  -H "Content-Type:application/json" \
  -H "Authorization:API Token" \
  -d "monitorId=4d048471-9e85-428b-8050-4238f6033478" \
    'https://lunalytics.xyz/api/monitor/delete'
js
axios('/api/monitor/delete', {
  method: 'GET',
  headers: {
    Authorization: 'API Token',
    'Content-Type': 'application/json',
  },
  params: {
    monitorId: '4d048471-9e85-428b-8050-4238f6033478',
  },
});

Get monitor status

GET /api/monitor/status

Endpoint returns an array of heartbeats within the given timespace. Heartbeats for week and month are the heartbeats closest to every fith minute within the time span.

Query Parameters

monitorId String

Monitor id for the monitor to be deleted.

Status String

Status can either be latest, day, week, or month. If no status is specified, the latest status will be returned.

HTTP Response Codes

Status CodeDescription
200Success, an array of heartbeats
400Bad Request, monitorId not provided or invalid status type
401Unauthorized (Missing access_token cookie or API Token)
403User is unverified
404Monitor not found
416Range Not Satisfiable (Less than 2 monitors)
curl -X GET \
  -H "Content-Type:application/json" \
  -H "Authorization:API Token" \
  -d "monitorId=4d048471-9e85-428b-8050-4238f6033478" \
  -d "type=latest" \
    'https://lunalytics.xyz/api/monitor/status'
js
axios('/api/monitor/status', {
  method: 'GET',
  headers: {
    Authorization: 'API Token',
    'Content-Type': 'application/json',
  },
  params: {
    monitorId: '4d048471-9e85-428b-8050-4238f6033478',
    type: 'latest',
  },
});

Get a specific monitor

GET /api/monitor/id

Returns the full monitor object for a specific monitor using the given monitor id.

Query Parameters

monitorId String

Monitor id for the monitor to be deleted.

HTTP Response Codes

Status CodeDescription
200Success, returns the full monitor object
400Bad Request, monitorId not provided
401Unauthorized (Missing access_token cookie or API Token)
403User is unverified
404Monitor not found
curl -X GET \
  -H "Content-Type:application/json" \
  -H "Authorization:API Token" \
  -d "monitorId=4d048471-9e85-428b-8050-4238f6033478" \
    'https://lunalytics.xyz/api/monitor/id'
js
axios('/api/monitor/id', {
  method: 'GET',
  headers: {
    Authorization: 'API Token',
    'Content-Type': 'application/json',
  },
  params: {
    monitorId: '4d048471-9e85-428b-8050-4238f6033478',
  },
});