Monitoring and management of server cluster through Redis pub/sub

Source: Internet
Author: User
Tags redis install redis

Demand:

In order to accurately monitor the internal state of each server, without affecting the existing business logic, a simple centralized monitoring system for the server needs to be deployed quickly. After consideration, you can use the Redis pub/sub function to implement a monitoring system is very good and appropriate.

Of course, we can also pass this to do batch management.

Pub/sub is literally the publication (Publish) and Subscription (Subscribe), in Redis, you can set a key value for the message and message subscriptions, when a key value of the message published, all subscribed to its clients will receive the corresponding message. This function can be used as a real-time messaging system.

Publish and subscribe mechanism

When a client sends a message to the subscriber via the PUBLISH command, we call the client Publisher.

When a client uses the SUBSCRIBE or Psubscribe command to receive information, we call the client a Subscriber (subscriber).

To understand the relationship between a decoupling publisher (publisher) and a Subscriber (subscriber), Redis uses the channel (channel) as an intermediary--the publisher publishes the information directly to channel, and the channel is responsible for sending the information to the appropriate subscriber, There is no relationship between the publisher and the Subscriber, and there is no knowledge of the other.

The following figure is suitable for batch management, each client's server must have a redis-cli, install Redis naturally have, and then define sub, in the management end can be published through pub Some instructions, the client received, you can perform, you can do some other operations.

The following is suitable for monitoring, put their own business indicators pub in the past, the server can handle the corresponding, can be written to MySQL inside, can be and the page to interact.

In fact, the use of sockets can also be achieved, but Redis is already a more mature product, the internal implementation of the Epoll package, there are multiplexing features, non-blocking Io, and most of the request is pure memory operation. With these features, we don't have to bother to write a concurrent asynchronous refactoring to the socket, which is too much trouble.

Well, let's do it now.

This is a subscriber.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.