在 Node.js 中创建正常运行时间监视器的架构
使用 Node.js 和 Redis 创建正常运行时间监控系统的最佳解决方案是什么?我可以使用 Redis 作为队列,但这不是保存信息的最佳方式,也许 MongoDB 是?
这看起来很简单,但需要有超过 1 台服务器来保证服务器关闭并让所有内容协同工作并不那么容易。
What's the best solution for using Node.js and Redis to create an uptime monitoring system? Can I use Redis as a queue but is not the best way to save information, maybe MongoDB is?
It seems pretty simple but needing to have more than 1 server to guarantee the server is down and make everything work together is not so easy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要监控正常运行时间,您可以在系统上使用 Cron 作业。每次调用时,您都会检查主机是否已启动以及需要多长时间。在该脚本中,您可以将数据保存在 Redis 中。
要在 Node.JS 中执行此操作,您需要创建一个脚本来检查服务器的状态。只需向服务器(或 Ping,我们)发出 HTTP 请求并记录是否失败。然后我就把它记录到 Redis 中。你如何做并不重要,因为脚本(如果你每 30 秒运行一次 cron)距离下一次运行还有 [30] 秒,所以你不必担心将查询发送到服务器。如何保存数据取决于您,但在这种情况下,即使是 MySQL 也可以工作(如果您只做少量站点)
更多关于 Cron @ 维基百科
To monitor uptime, you would use a Cron job on the system. With each call, you would check to see if the host is up, and how long it would take. And in that script, you would save your data in Redis.
To do this in Node.JS, you would create a script that checks the status of the server. Just making a HTTP request to the server (Or Ping, w.e.) and recording if it fails or not. Then I would just record it to Redis. How you do it does not matter, because the script (if you run the cron every 30 seconds) has [30] seconds before the next run, so you dont have to worry about getting your query to the server. How you save your data is up to you, but in this case even MySQL would work (if you are only doing a small number of sites)
More on Cron @ Wikipedia
您可以(应该)使用 Redis 作为队列。速度将会非常快。
我还认为将信息保存在 Redis 中将是一个非常好的选择。不幸的是,Redis 还没有做任何计时。我认为你可以/应该使用 Beanstalkd 将消息放入队列在需要时交付(每 x 秒)。我还认为 cron 不是一个好主意,因为您将需要很多它们,并且在使用队列时您也可以更快地完成工作(在多个进程之间共享负载)。
另外,我认为您不需要那么多内存来保存内存中的所有内容(使站点速度更快),因为数据集相对简单。即使您无法(如果您问我,聪明地获得更多内存)将整个数据集放入内存中,您也可以依靠 Redis 的虚拟内存。
我认为你应该阅读分片/复制来解决这个问题(很难)。幸运的是Redis支持复制(也可以实现分片)。 MongoDB 支持开箱即用的分片/复制。老实说,我认为您还不需要分片,并且您的数据集相当简单,因此 Redis 会更快:
You can(should) use Redis as your queue. It is going to be extremely fast.
I also think it is going to be very good option to save the information inside Redis. Unfortunately Redis does not do any timing(yet). I think you could/should use Beanstalkd to put messages on the queue that get delivered when needed(every x seconds). I also think cron is not that a very good idea because you would be needing a lot of them and when using a queue you could do your work faster(share load among multiple processes) also.
Also I don't think you need that much memory to save everything in memory(makes site fast) because dataset is going to be relative simple. Even if you aren't able(smart to get more memory if you ask me) to fit entire dataset in memory you can rely on Redis's virtual memory.
Sharding/replication is what I think you should read into to solve this problem(hard). Luckily Redis supports replication(sharding can also be achieved). MongoDB supports sharding/replication out of the box. To be honest I don't think you need sharding yet and your dataset is rather simple so Redis is going to be faster: