"Go-monitor" open source a lightweight quality of service analysis alarm tool
Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. Introduction ' Go-monitor ' based on ' Golang ' development, is a lightweight, tool for quality of service monitoring and for the analysis of alarms. ' Go-monitor ' is not an independent service at this time, but rather it is intended to be used by most projects based on ' Golang ' as if it were introduced as a log component. What > ' Go-monitor ' can do by reporting interfaces, functions, or the time-consuming and successful state of any invocation of the service, ' Go-monitor ' will automatically perform the service quality analysis, statistics, and output detailed report data according to the set cycle. When the quality of service is less than ideal, ' go-monitor ' triggers an alarm and triggers a recovery notification when the service quality picks up. ' Go-monitor ' provides a very flexible configuration so that it can be used in most scenarios to function as a service monitor through parameter adjustments. ' Go-monitor ' uses a lock-free queue to avoid the performance problems associated with concurrent locks, the MBP2012 version is measured 5 million times reported (go test bench) With just 1.6s to complete all analysis statistics (previously the Concurrency Lock Scheme is 1.9s), powerful performance allows you to use it like logging, and you don't need to worry about IO pressure (most of the log components use cache writes to improve performance, large concurrent IO pressure is obvious). > What scenarios suggest using ' go-monitor ' For example, we have developed a Web application to provide services externally, we can embed go-monitor, escalate the time and status of each visit to monitor the quality of our entire Web application service, can also be in a timely manner when the quality of service decline or even when the alarm, more detailed, we can report any call service status, such as the database we access, dependent on the external interface, in addition to monitoring the quality of service, In fact, the statistical data provided by Go-monitor can be used to understand the average latency of any one service, as large as a complete interface, as small as a database query statement. The cost of using Go-monitor is very small, just introducing go-monitor in the Golang project, like using a log component, without the burden. # # # Use method > Install ' Go get github.com/blurooo/go-monitor ' ' > introduced using ' Go-monitor ' is very simple, just call its provided ' Register ' function to register for an escalation client, reporting that the client has exposed the ' report ' method for reporting the service's time-consuming metrics: ' Import ("Github.com/blurooo/go-monitor""Time")//register to get an escalation client for HTTP service quality monitoring var httpreportclient = monitor. Register (monitor. reportclientconfig {Name: "HTTP Service Monitoring", statisticalcycle:100,//100ms statistics per service quality}) Func main () {t: = time. Newticker (Ten * time. Millisecond) for curtime: = range t.c {//per 10ms to the HTTP monitoring client to escalate an HTTP service data, time-consuming 0-100ms with a status of $ httpreportclient.report ("GET-A Pp/api/users ", UInt32 (Curtime.nanosecond (), +)}" Go-monitor "outputs a quality of service analysis report for each statistical period (100ms, default 1min), for example: ' {' Timestamp ":" 2018-01-24t09:10:55.190503145z "," clientName ":" HTTP Service Monitoring "," InterfaceName ":" GET-/app/api/users "," Count ": Ten," Successcount ": Ten," Successrate ": 1," Successmsaver ": $," MAXMS ": 98," MINMS ": 9," Fastcount ": Ten," Fastrate " : 1, "Failcount": 0, "Faildistribution": {}, "Timeconsumingdistribution": {"100~150": 0, "150~200": 0, "200~250": 0, "250~ ": 0," 300~350 ": 0," 350~400 ": 0," 400~450 ": 0," 450~500 ": 0," <100 ": Ten," >500 ": 0}}" "The default report data will be output in the console, but allow us to customize, For example, to print to a log file or write to a database, etc., simply pass in our own ' Outputcaller ': ' Import ("Github.com/blurooo/go-monitor" "Time")// Register to get an escalation client for HTTP service quality monitoring var hTtpreportclient = Monitor. Register (monitor. reportclientconfig {Name: "HTTP Service Monitoring", statisticalcycle:100,//100ms statistics once service quality Outputcaller:func (o *monitor. Outputdata) {//Write database Logic ...}}) func main () {t: = time. Newticker (Ten * time. Millisecond) for curtime: = range t.c {//per 10ms to the HTTP monitoring client to escalate an HTTP service data, time-consuming 0-100ms with a status of $ httpreportclient.report ("GET-A Pp/api/users ", UInt32 (Curtime.nanosecond ()%)," Go-monitor "supports multiple instances, and encourages the use of multiple instances. Instances of each other, such as in the same application, we can register an HTTP service monitoring, but also register a function time-consuming monitoring: ""//register to get an escalation client for HTTP service quality monitoring var httpreportclient = monitor. Register (monitor. reportclientconfig {Name: "HTTP Service Monitoring",})//register to get an escalation client for function time monitoring var funcreportclient = monitor. Register (monitor. reportclientconfig {Name: "function time-consuming monitoring",}) "Go-monitor" In addition to analyzing statistics, it also helps to implement the alarm policy, which relies on the decision rules of the service exception. By default, when the escalation code is 200, it is considered successful. Of course, in most applications, such simple decision rules are often difficult to handle in a variety of complex scenarios. So ' Go-monitor ' allows us to use whitelist to customize our own set of rules: ' '//register to get an escalation client for HTTP service quality monitoring var httpreportclient = monitor. Register (monitor. reportclientconfig {Name: "HTTP Service monitoring", Codefeaturemap:map[int]moniTor. Codefeature {0: {success:true, Name: "Success",}, 10000: {success:false, Name: "Service Unavailable",},}}) ' ' Codefeaturemap ' allows the state to be declared If the code succeeds and specifies its name (used in the statistics report), the code will be considered unsuccessful. In addition to using the whitelist mechanism to determine code, ' Go-monitor ' also provides a more adaptable way to decide (precedence over ' Codefeaturemap '): '//Register to get an escalation client for HTTP service quality monitoring var Httpreportclient = Monitor. Register (monitor. reportclientconfig {Name: "HTTP Service Monitoring", Getcodefeature:func (code int) (Success bool, Name string) {if Code = = 0 {return True, "success"} else {return false, "failed"}},}) ' In each statistical cycle, the success rate does not reach the desired value, the entry will be marked, after a continuous marking of several statistical cycles, ' go-monitor ' will trigger the success rate of the non-standard alarm, The alarm data clearly indicates the specific monitoring services and alarm entries, accompanied by successive statistics marked as the success rate of the non-standard, the default print to the console, but also allows us to customize, we can do as we wish, such as sending e-mail notification to the relevant person: "'// Register to get an escalation client for HTTP service quality monitoring var httpreportclient = monitor. Register (monitor. reportclientconfig {Name: "HTTP Service Monitoring", Alertcaller:func (ClientName string, InterfaceName string, AlertType Monitor.) AlertType, Recentoutputdata []monitor. Outputdata) {//Process related alarms}}) "In addition to the success rate of the non-standard alarm, ' go-monitor ' also provides time-consuming non-standard alarm, accurate to each monitoring entry allows custom time-consuming parameters. "//An Escalation client global time-consuming compliance value VAR httpreportclient = Monitor. Register (monitor. reportclientconfig {Name: "HTTP Service Monitoring", defaultfasttime:1000,//Set HTTP escalation client's default time-consuming target of 1000ms})// The time-consuming standard httpreportclient.addentryconfig ("GET-/app/api/users", monitor) that is specific to an entry. Entryconfig {fastlessthan:100,//SET interface "GET-/app/api/users" for a time-consuming compliance value of 100ms}) "Go-monitor" also supports the service quality recovery notification, similar to the alert policy, In the event of an alarm state, subsequent successive marks of the service compliance statistics will trigger the recovery notification, we only need to customize the ' Recovercaller ' can: ' var httpreportclient = monitor. Register (monitor. reportclientconfig {Name: "HTTP Service Monitoring", Recovercaller:func (ClientName string, InterfaceName string, AlertType Monitor.) AlertType, Recentoutputdata []monitor. Outputdata) {//Process recovery notification},}) ' and more flexible configurations are supported in ' go-monitor ', welcome to find them in use, and welcome the intention of the developer to participate in this work, in the vision, Hope ' go-monitor ' can be derived from a well-established independent service to support any system access (including front-end escalation), and provide as many out-of-the-box solutions, such as statistical data output to the database, mailbox alarms, interface notifications and so on. Here's a point: [GitHub] (https://github.com/blurooo/go-monitor). 324 reads
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.