1. __ __ __ _ __
  2. ____ ____ ____/ /__ _____/ /_ _______/ /____ _____ ___ ____ ___ ____ _(_) /
  3. / __ \/ __ \/ __ / _ \______/ ___/ / / / / ___/ __/ _ \/ ___/_____/ _ \/ __ `__ \/ __ `/ / /
  4. / / / / /_/ / /_/ / __/_____/ /__/ / /_/ (__ ) /_/ __/ / /_____/ __/ / / / / / /_/ / / /
  5. /_/ /_/\____/\__,_/\___/ \___/_/\__,_/____/\__/\___/_/ \___/_/ /_/ /_/\__,_/_/_/

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

  1. npm install https://github.com/sunNode/node-cluster-email

Usage

Initialize mail plugin with the given email(s), with the given options.

Options:

  • from sender email
  • timeout sendmail timeout in milliseconds
  • subject defaulting to "cluster({worker}) exception: {message}"
  • template function called with local variables (usually jade / ejs template etc)

Example

  1. const cluster = require('cluster')
  2. const cpu = require ('os').cpus().length
  3. const mail = require('node-cluster-mail')
  4. /**
  5. * [if description]
  6. * @param {[type]} cluster.isMaster [description]
  7. * @return {[type]} [description]
  8. */
  9. if (cluster.isMaster) {
  10. // Fork workers.
  11. for (let i = 0; i < cpu; i++) {
  12. cluster.fork();
  13. }
  14. cluster.on('exit', function(worker, code, signal) {
  15. mail('phonenix@gmail.com',{'from':'phonenix-test@gmail.com','cc':'phonenix-test2@gmail.com'})
  16. console.log('worker ' + worker.process.pid + ' died');
  17. });
  18. cluster.on('fork', function(worker) {
  19. console.log(`workers: ${worker.id} worker.process.pid :${worker.process.pid}`)
  20. });
  21. } else {
  22. // Workers can share any TCP connection
  23. // In this service its a restify server
  24. require('./app')
  25. }

Reference

node-cluster-email

用node.js做cluster,监听异常的邮件提醒服务的更多相关文章

  1. Node.js之事件监听和发送

    演示事件的发送和监听 const events = require("events"); function Account() { this.balance = 0; events ...

  2. JS通用事件监听函数

    JS通用事件监听函数 版本一 //把它全部封装到一个对象中 var obj={ readyEvent:function (fn){ if(fn==null){ fn=document; } var o ...

  3. Oracle 监听器日志文件过大导致监听异常

    Oracle 监听器日志文件过大导致监听异常 db版本:11.2.0.1 os版本:windows2008 现象: 应用异常,无法连接数据库.登陆数据库服务器,查看监听已经断掉.尝试重启监听,重启失败 ...

  4. 简单剖析Node中的事件监听机制(一)

    使用js的class类简单的实现一个事件监听机制,不同于浏览器中的时间绑定与监听,类似于node中的时间监听,并且会在接下来的文章中去根据自己的理解去写一下Event模块中的原理. Node.js使用 ...

  5. js进阶 12-6 监听鼠标滚动事件和窗口改变事件怎么写

    js进阶 12-6 监听鼠标滚动事件和窗口改变事件怎么写 一.总结 一句话总结:滚动事件scroll(),浏览器窗口调整监听resize(),思考好监听对象. 1.滚动事件scroll()的监听对象是 ...

  6. js添加事件监听的方式与this

    js添加事件监听与this js添加事件监听的方式与this 在标签中调用自定义函数 DOM0级事件处理程序 DOM2级事件处理程序 this 代表谁? js添加事件监听的方式与this <di ...

  7. Node.js的cluster模块——Web后端多进程服务

    众所周知,Node.js是单线程的,一个单独的Node.js进程无法充分利用多核.Node.js从v0.6.0开始,新增cluster模块,让Node.js开发Web服务时,很方便的做到充分利用多核机 ...

  8. node.js使用cluster实现多进程

    首先郑重声明: nodeJS 是一门单线程!异步!非阻塞语言! nodeJS 是一门单线程!异步!非阻塞语言! nodeJS 是一门单线程!异步!非阻塞语言! 重要的事情说3遍. 因为nodeJS天生 ...

  9. 初涉node.js做微信测试公众号一路填坑顺便发现个有趣的其他漏洞

    [微信测试公众号] 半年前耍着玩搭起来的“微信简历”,是LAMP版的,很皮毛. 微信的官方文档在这 http://mp.weixin.qq.com/wiki/index.php 1.获取access ...

随机推荐

  1. 示例:pm_multiple_models 匹配——形状匹配

    * This example program shows how to use HALCON's shape-based matching* to find multiple different mo ...

  2. create react app遇到的问题

    我现在想的是吧 static 资源和动态 api 来分开处理, static 资源开启 nginx 服务器,api 请求由 express 完成, 现在的问题是开发的时候 proxy 设定将所有的请求 ...

  3. 算法练习LeetCode初级算法之树

    二叉树的前序遍历 我的解法:利用递归,自底向下逐步添加到list,返回最终的前序遍历list class Solution { public List<Integer> preorderT ...

  4. 部分用户访问Polycom视频会议时故障

    1.现象 Polycom视频会议服务器部署在防火墙下,通过Paloalto防火墙的一对一映射到公网. 部分同事使用职场网络或者4G通过公网访问时,出现超时问题. 2.分析: Polycom设备并没有做 ...

  5. jsp中<c:if>标签的用法

    <c:if test="${(tbl.column1 eq '值') and (tbl.column2 eq 'str')}"> <table>...< ...

  6. input中用中文输入法下的全角·替换英文输入法下的句号.

    核心语句 <input type="text" onkeyup="this.value=this.value.replace(/\./g, '·')" o ...

  7. [leetcode]297. Serialize and Deserialize Binary Tree 序列化与反序列化二叉树

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  8. Linux系统中的tar命令

    时间一长什么东西都容易忘记,尤其是一些不常用的东西忘记的更快,所以避免忘记,就记录下来,可以方面使用的时候查询.Tar命令在linux系统中算是一个比较重要的命令,今天就针对该命令进行总结一下. 1. ...

  9. boost的下载和安装(windows版)

    1 简介 boost是一个准C++标准库,相当于STL的延续和扩充,它的设计理念和STL比较接近,都是利用泛型让复用达到最大化. boost主要包含以下几个大类: 字符串及文本处理.容器.迭代器(it ...

  10. leveldb 源码编译 vs版本

    为什么要windows版本? 因为方便调试跟进 VS的体验真的很不错. 搜索了一段时间才发现GITHUB有windows版本的leveldb 但是使用VS编译也有不少坑 可以下载网络上的其他朋友的版本 ...