用node.js做cluster,监听异常的邮件提醒服务
__ __ __ _ __
____ ____ ____/ /__ _____/ /_ _______/ /____ _____ ___ ____ ___ ____ _(_) /
/ __ \/ __ \/ __ / _ \______/ ___/ / / / / ___/ __/ _ \/ ___/_____/ _ \/ __ `__ \/ __ `/ / /
/ / / / /_/ / /_/ / __/_____/ /__/ / /_/ (__ ) /_/ __/ / /_____/ __/ / / / / / /_/ / / /
/_/ /_/\____/\__,_/\___/ \___/_/\__,_/____/\__/\___/_/ \___/_/ /_/ /_/\__,_/_/_/
A module for taking advantage of the built-in cluster module in node v0.8 and above.send email if cluster exception,you will recieve a detail email about worker exception.
Installation
npm install https://github.com/sunNode/node-cluster-email
Usage
Initialize mail plugin with the given email(s), with the given options.
Options:
fromsender emailtimeoutsendmail timeout in millisecondssubjectdefaulting to "cluster({worker}) exception: {message}"templatefunction called with local variables (usually jade / ejs template etc)
Example
const cluster = require('cluster')
const cpu = require ('os').cpus().length
const mail = require('node-cluster-mail')
/**
* [if description]
* @param {[type]} cluster.isMaster [description]
* @return {[type]} [description]
*/
if (cluster.isMaster) {
// Fork workers.
for (let i = 0; i < cpu; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
mail('phonenix@gmail.com',{'from':'phonenix-test@gmail.com','cc':'phonenix-test2@gmail.com'})
console.log('worker ' + worker.process.pid + ' died');
});
cluster.on('fork', function(worker) {
console.log(`workers: ${worker.id} worker.process.pid :${worker.process.pid}`)
});
} else {
// Workers can share any TCP connection
// In this service its a restify server
require('./app')
}
Reference
用node.js做cluster,监听异常的邮件提醒服务的更多相关文章
- Node.js之事件监听和发送
演示事件的发送和监听 const events = require("events"); function Account() { this.balance = 0; events ...
- JS通用事件监听函数
JS通用事件监听函数 版本一 //把它全部封装到一个对象中 var obj={ readyEvent:function (fn){ if(fn==null){ fn=document; } var o ...
- Oracle 监听器日志文件过大导致监听异常
Oracle 监听器日志文件过大导致监听异常 db版本:11.2.0.1 os版本:windows2008 现象: 应用异常,无法连接数据库.登陆数据库服务器,查看监听已经断掉.尝试重启监听,重启失败 ...
- 简单剖析Node中的事件监听机制(一)
使用js的class类简单的实现一个事件监听机制,不同于浏览器中的时间绑定与监听,类似于node中的时间监听,并且会在接下来的文章中去根据自己的理解去写一下Event模块中的原理. Node.js使用 ...
- js进阶 12-6 监听鼠标滚动事件和窗口改变事件怎么写
js进阶 12-6 监听鼠标滚动事件和窗口改变事件怎么写 一.总结 一句话总结:滚动事件scroll(),浏览器窗口调整监听resize(),思考好监听对象. 1.滚动事件scroll()的监听对象是 ...
- js添加事件监听的方式与this
js添加事件监听与this js添加事件监听的方式与this 在标签中调用自定义函数 DOM0级事件处理程序 DOM2级事件处理程序 this 代表谁? js添加事件监听的方式与this <di ...
- Node.js的cluster模块——Web后端多进程服务
众所周知,Node.js是单线程的,一个单独的Node.js进程无法充分利用多核.Node.js从v0.6.0开始,新增cluster模块,让Node.js开发Web服务时,很方便的做到充分利用多核机 ...
- node.js使用cluster实现多进程
首先郑重声明: nodeJS 是一门单线程!异步!非阻塞语言! nodeJS 是一门单线程!异步!非阻塞语言! nodeJS 是一门单线程!异步!非阻塞语言! 重要的事情说3遍. 因为nodeJS天生 ...
- 初涉node.js做微信测试公众号一路填坑顺便发现个有趣的其他漏洞
[微信测试公众号] 半年前耍着玩搭起来的“微信简历”,是LAMP版的,很皮毛. 微信的官方文档在这 http://mp.weixin.qq.com/wiki/index.php 1.获取access ...
随机推荐
- Ubuntu输入命令无效的问题
https://blog.csdn.net/u014797226/article/details/80800550?utm_source=blogxgwz2 Ubuntu启动时输入密码后,一直停留在登 ...
- pycharm的断点调试【转自https://blog.csdn.net/weixin_39198406/article/details/78873120】
1. show execution point (F10)显示目前项目所有断点2. step over (F8)下一步但仅限于设置断点的文件3. step into (F7)执行下一行4. step ...
- 吴裕雄 python深度学习与实践(14)
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt threshold = 1.0e-2 x1_dat ...
- 性感天才黑客乔治·霍兹George Hotz 17岁打脸乔布斯20岁搞疯索尼
1.国内外著名黑客信息 1) 国外著名黑客 George Hotz 乔治·霍兹(George Hotz,1989年10月2日-),美国学生,2007年8月解锁苹果(Apple)iPhone手机,使得i ...
- mysql 按出现次数排序
SELECT * FROM table a LEFT JOIN (SELECT key,count(*) as c FROM table GROUP BY key ) b on a.key=b.k ...
- linux上部署Appach,让文件目录以网页列表形式访问
效果: 1.首先,需要安装Apache httpd服务 yum install -y httpd 2.查看或者设置httpd主配文件 vim /etc/httpd/conf/htpd.conf 从中可 ...
- HDU6030 Happy Necklace(递推+矩阵快速幂)
传送门:点我 Little Q wants to buy a necklace for his girlfriend. Necklaces are single strings composed of ...
- 347. Top K Frequent Elements 最常用的k个元素
[抄题]: Given a non-empty array of integers, return the k most frequent elements. For example,Given [1 ...
- CSP里的xss
无CSP保护下的xss 1.直接嵌入型 <img src="192.168.81.137:80/xss.php?a=[cookie]"> 过滤较少时,优先考虑.触发方式 ...
- jdbc随笔
通过jdbc连接数据库的基本步骤: 导入jar包驱动类 jdbc语法:jdbc:子协议:厂商内容 对于mysql而言:jdbc:mysql://主机地址:端口号/库名 ...