mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 22:59:07 +00:00
make probe into a job
This commit is contained in:
parent
259710e527
commit
82ce593b38
@ -127,7 +127,6 @@ services:
|
||||
# There can only be one probe in developer docker compose.
|
||||
probe:
|
||||
ports:
|
||||
- '3008:3008'
|
||||
- '9238:9229' # Debugging port.
|
||||
build:
|
||||
context: .
|
||||
|
@ -169,8 +169,6 @@ services:
|
||||
- MONGO_URL=mongodb://mongo:27017/oneuptimedb
|
||||
- REALTIME_URL=http://realtime:3300
|
||||
probe1:
|
||||
ports:
|
||||
- '3024:3024'
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./probe/Dockerfile
|
||||
@ -189,8 +187,6 @@ services:
|
||||
- backend
|
||||
- data-ingestor
|
||||
probe2:
|
||||
ports:
|
||||
- '3025:3025'
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./probe/Dockerfile
|
||||
|
@ -54,8 +54,6 @@ spec:
|
||||
value: {{ template "oneuptime.serverUrl" $ }}
|
||||
- name: DATA_INGESTOR_URL
|
||||
value: {{ template "oneuptime.dataIngestorUrl" $ }}
|
||||
- name: PORT
|
||||
value: {{ $value.port | quote }}
|
||||
- name: PROBE_NAME
|
||||
value: {{ $value.name }}
|
||||
- name: PROBE_KEY
|
||||
@ -77,29 +75,8 @@ spec:
|
||||
{{- end }}
|
||||
- name: NODE_ENV
|
||||
value: {{ $.Values.nodeEnv }}
|
||||
ports:
|
||||
- containerPort: {{ $value.port }}
|
||||
hostPort: {{ $value.port }}
|
||||
name: {{ printf "%s-%s" $.Release.Name $key }}
|
||||
restartPolicy: {{ $.Values.image.restartPolicy }}
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
app: {{ printf "%s-%s" $.Release.Name $key }}
|
||||
app.kubernetes.io/part-of: oneuptime
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
name: {{ printf "%s-%s" $.Release.Name $key }}
|
||||
namespace: {{ $.Release.Namespace }}
|
||||
spec:
|
||||
ports:
|
||||
- port: {{ $value.servicePort }}
|
||||
targetPort: {{ $value.port }}
|
||||
selector:
|
||||
app: {{ printf "%s-%s" $.Release.Name $key }}
|
||||
type: ClusterIP
|
||||
---
|
||||
###########################
|
||||
{{- end }}
|
@ -68,15 +68,11 @@ httpTestServer:
|
||||
|
||||
probes:
|
||||
probe1:
|
||||
port: 3024
|
||||
name: Probe 1
|
||||
key: sample-key
|
||||
servicePort: 80
|
||||
probe2:
|
||||
name: Probe 2
|
||||
port: 3025
|
||||
key: sample-key
|
||||
servicePort: 80
|
||||
|
||||
##################################################################################
|
||||
## Important: RateLimitter Values. More information in the Readme.md
|
||||
|
@ -2,7 +2,6 @@ const { NODE_ENV } = process.env;
|
||||
const asyncSleep = require('await-sleep');
|
||||
|
||||
if (!NODE_ENV || NODE_ENV === 'development') {
|
||||
// Load env vars from /backend/.env
|
||||
require('custom-env').env();
|
||||
}
|
||||
|
||||
@ -25,71 +24,14 @@ process.on('uncaughtException', err => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const http = require('http').createServer(app);
|
||||
const cors = require('cors');
|
||||
const Main = require('./workers/main');
|
||||
const config = require('./utils/config');
|
||||
const logger = require('../common-server/utils/logger');
|
||||
|
||||
const cronMinuteStartTime = Math.floor(Math.random() * 50);
|
||||
|
||||
app.use(cors());
|
||||
app.set('port', process.env.PORT || 3008);
|
||||
|
||||
const monitorStore = {};
|
||||
|
||||
// handle probe1 status
|
||||
app.get(['/probe1/status', '/status'], function(req, res) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(
|
||||
JSON.stringify({
|
||||
status: 200,
|
||||
message: 'Service Status - OK',
|
||||
serviceType: 'oneuptime-probe',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// handle probe2 status
|
||||
app.get(['/probe2/status', '/status'], function(req, res) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(
|
||||
JSON.stringify({
|
||||
status: 200,
|
||||
message: 'Service Status - OK',
|
||||
serviceType: 'oneuptime-probe',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
app.get(['/probe1/monitorCount', '/monitorCount'], function(req, res) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(
|
||||
JSON.stringify({
|
||||
monitorCount: Object.keys(monitorStore).length,
|
||||
monitors: monitorStore,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
app.get(['/probe2/monitorCount', '/monitorCount'], function(req, res) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send(
|
||||
JSON.stringify({
|
||||
monitorCount: Object.keys(monitorStore).length,
|
||||
monitors: monitorStore,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
//App Version
|
||||
app.get(['/probe/version', '/version'], function(req, res) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.send({ probeVersion: process.env.npm_package_version });
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
// keep monitoring in an infinate loop.
|
||||
|
||||
@ -98,22 +40,14 @@ setTimeout(async () => {
|
||||
try {
|
||||
await Main.runJob(monitorStore);
|
||||
} catch (error) {
|
||||
logger.error(erorr);
|
||||
logger.error(error);
|
||||
logger.info('Sleeping for 30 seconds...');
|
||||
await asyncSleep(30 * 1000);
|
||||
}
|
||||
}
|
||||
}, cronMinuteStartTime * 1000);
|
||||
|
||||
http.listen(app.get('port'), function() {
|
||||
// eslint-disable-next-line
|
||||
console.log(
|
||||
`Probe with Probe Name ${config.probeName} and Probe Key ${
|
||||
config.probeKey
|
||||
} Started on port ${app.get('port')}. OneUptime API URL: ${
|
||||
config.serverUrl
|
||||
}`
|
||||
);
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(
|
||||
`Probe with Probe Name ${config.probeName} and Probe Key ${config.probeKey}. OneUptime Probe API URL: ${config.probeApiUrl}`
|
||||
);
|
||||
|
2191
probe/package-lock.json
generated
2191
probe/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -25,9 +25,7 @@
|
||||
"await-sleep": "^0.0.1",
|
||||
"axios": "^0.25.0",
|
||||
"chrome-launcher": "^0.15.0",
|
||||
"cors": "^2.8.5",
|
||||
"custom-env": "^2.0.1",
|
||||
"express": "^4.17.2",
|
||||
"get-ssl-certificate": "^2.3.3",
|
||||
"moment": "^2.29.1",
|
||||
"node-fetch-commonjs": "^3.1.1",
|
||||
|
@ -47,7 +47,7 @@ const _this = {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios({
|
||||
method: 'GET',
|
||||
url: `${config.fetchResourcesUrl}/${url}?limit=${limit}`,
|
||||
url: `${config.probeApiUrl}/${url}?limit=${limit}`,
|
||||
headers,
|
||||
})
|
||||
.then(function(response) {
|
||||
|
@ -44,5 +44,5 @@ module.exports = {
|
||||
clusterKey: process.env['CLUSTER_KEY'],
|
||||
probeVersion: packageJson.version,
|
||||
dataIngestorUrl: process.env['DATA_INGESTOR_URL'],
|
||||
fetchResourcesUrl: process.env['PROBE_API_URL'],
|
||||
probeApiUrl: process.env['PROBE_API_URL'],
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user