/** * Initialize reporter * @param {MetricRegistry} registry * @memberof PrometheusReporter */ init(registry) { super.init(registry); this.server = http.createServer(); this.server.on("request", this.handler.bind(this)); this.server.listen(this.opts.port, err => { if (err) { /* istanbul ignore next */ return this.registry.broker.fatal(new MoleculerError("Prometheus metric reporter listening error: " + err.message)); } this.logger.info(`Prometheus metric reporter listening on http://0.0.0.0:${this.opts.port}${this.opts.path} address.`); }); this.defaultLabels = isFunction(this.opts.defaultLabels) ? this.opts.defaultLabels.call(this, registry) : this.opts.defaultLabels; }
// Response to PING on GET /ping server.on('request', (req, res) => { if (req.method === 'GET' && req.url === '/ping') { setTimeout(() => { res.statusCode = 200; res.end(); }, 1000); } else { res.statusCode = 404; res.end(); } });
function testFuncCall(test) { var server = http.createServer(function(req, res) { res.writeHeader(200); res.end(); }); server.on('listening', function() { console.log(`Listening on http://localhost:${server.address().port}/`); console.log('PID %d', process.pid); var heapSnapshotFile = 'heapdump-*.heapsnapshot'; shelljs.rm('-f', heapSnapshotFile); function waitForHeapdump(err, filename) { var files = shelljs.ls(heapSnapshotFile); test.equals(err, null); test.equals(files.length, 1); test.equals(filename, files[0]); server.close(); test.end(); } heapdump.writeSnapshot(waitForHeapdump); }); server.listen(0); }
}); server.on('listening', function() { console.log(`Listening on http://localhost:${server.address().port}/`); console.log('now sending SIGUSR2 to %d', process.pid);
function testFuncCall(test) { var server = http.createServer(function(req, res) { res.writeHeader(200); res.end(); }); server.on('listening', function() { console.log(`Listening on http://localhost:${server.address().port}/`); console.log('PID %d', process.pid); var heapSnapshotFile = 'heapdump-' + Date.now() + '.heapsnapshot'; shelljs.rm('-f', heapSnapshotFile); function waitForHeapdump(err, filename) { var files = shelljs.ls(heapSnapshotFile); test.equals(err, null); test.equals(files.length, 1); test.equals(filename, files[0]); server.close(); test.end(); } heapdump.writeSnapshot(heapSnapshotFile, waitForHeapdump); }); server.listen(0); }
server.on('listening', () => { co(function* () { yield DB.use(Conf.www.table); console.log(`Web start http://localhost:${server.address().port}/`); }).catch((err) => { console.log(err); }); });
server.on('error', (e) => { if (e.code == 'EADDRINUSE') { console.error('HTTP中间人代理启动失败!!'); console.error(`端口:${port},已被占用。`); } else if (e.code == 'ECONNRESET') { console.error(e); } else { console.error(e); } });
server.on('listening', () => { const addr = server.address() const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port debug('Listening on ' + bind) })
httpTunnel.on('error', (e) => { if (e.code == 'EADDRINUSE') { console.error('HTTP中间人代理启动失败!!'); console.error(`端口:${port},已被占用。`); } else { console.error(e); } });
server.on('error', (e) => { if (e.code == 'EADDRINUSE') { console.error('HTTP中间人代理启动失败!!'); console.error(`端口:${port},已被占用。`); } else if (e.code == 'ECONNRESET') { console.error(e); } else { console.error(e); } });
server.on('error', (e) => { if (e.code == 'EADDRINUSE') { console.error('HTTP中间人代理启动失败!!'); console.error(`端口:${port},已被占用。`); } else if (e.code == 'ECONNRESET') { console.error(e); } else { console.error(e); } });
httpMitmProxy.on('error', (e) => { if (e.code == 'EADDRINUSE') { console.error('HTTP中间人代理启动失败!!'); console.error(`端口:${port},已被占用。`); } else { console.error(e); } });