This commit is contained in:
2024-02-20 17:15:27 +08:00
committed by huty
parent 6706e1a633
commit 34158042ad
1529 changed files with 177765 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
FROM node:16.13.1-alpine3.14 AS builder
WORKDIR /src
COPY src/package.json .
RUN npm install
FROM node:16.13.1-alpine3.14
CMD ["node", "/app/app.js"]
ENV TARGET="blog.sixeyed.com" \
METHOD="HEAD" \
INTERVAL="3000"
WORKDIR /app
COPY --from=builder /src/node_modules/ /app/node_modules/
COPY src/ .

View File

@@ -0,0 +1,25 @@
const https = require('https');
const log = require("./log");
const options = {
hostname: process.env.TARGET,
method: process.env.METHOD
};
log.Logger.info('** web-ping ** Pinging: %s; method: %s; %dms intervals', options.hostname, options.method, process.env.INTERVAL);
let i = 1;
let start = new Date().getTime();
setInterval(() => {
start = new Date().getTime();
log.Logger.debug('Making request number: %d; at %d', i++, start);
var req = https.request(options, (res) => {
var end = new Date().getTime();
var duration = end-start;
log.Logger.debug('Got response status: %s at %d; duration: %dms', res.statusCode, end, duration);
});
req.on('error', (e) => {
console.error(e);
});
req.end();
}, process.env.INTERVAL)

View File

@@ -0,0 +1,16 @@
const { format, transports } = require('winston');
var logConfig = module.exports = {};
logConfig.options = {
transports: [
new transports.Console({
level: 'debug',
format: format.combine(
format.splat(),
format.printf(log => {
return `${log.message}`
})
)
})
]
};

View File

@@ -0,0 +1,5 @@
const winston = require('winston');
var logConfig = require('./config/logConfig');
const logger = winston.createLogger(logConfig.options);
exports.Logger = logger;

View File

@@ -0,0 +1,9 @@
{
"name": "web-ping",
"version": "1.0.0",
"main": "app.js",
"author": "kiamol",
"dependencies": {
"winston": "3.3.3"
}
}