mirror of
				https://github.com/nadoo/glider.git
				synced 2025-11-04 07:42:38 +08:00 
			
		
		
		
	strategy: add features latencythreshold
This commit is contained in:
		
							parent
							
								
									d5a9d680a9
								
							
						
					
					
						commit
						0337e98215
					
				
							
								
								
									
										1
									
								
								conf.go
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								conf.go
									
									
									
									
									
								
							@ -41,6 +41,7 @@ func confInit() {
 | 
				
			|||||||
	flag.StringVar(&conf.StrategyConfig.CheckWebSite, "checkwebsite", "www.apple.com", "proxy check HTTP(NOT HTTPS) website address, format: HOST[:PORT], default port: 80")
 | 
						flag.StringVar(&conf.StrategyConfig.CheckWebSite, "checkwebsite", "www.apple.com", "proxy check HTTP(NOT HTTPS) website address, format: HOST[:PORT], default port: 80")
 | 
				
			||||||
	// TODO: change to checkinterval
 | 
						// TODO: change to checkinterval
 | 
				
			||||||
	flag.IntVar(&conf.StrategyConfig.CheckInterval, "checkduration", 30, "proxy check interval(seconds)")
 | 
						flag.IntVar(&conf.StrategyConfig.CheckInterval, "checkduration", 30, "proxy check interval(seconds)")
 | 
				
			||||||
 | 
						flag.IntVar(&conf.StrategyConfig.LatencyThreshold, "latencythreshold", 10000, "proxy check latency time(millisecond)")
 | 
				
			||||||
	flag.IntVar(&conf.StrategyConfig.MaxFailures, "maxfailures", 3, "max failures to change forwarder status to disabled")
 | 
						flag.IntVar(&conf.StrategyConfig.MaxFailures, "maxfailures", 3, "max failures to change forwarder status to disabled")
 | 
				
			||||||
	flag.StringVar(&conf.StrategyConfig.IntFace, "interface", "", "source ip or source interface")
 | 
						flag.StringVar(&conf.StrategyConfig.IntFace, "interface", "", "source ip or source interface")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -25,6 +25,7 @@ type Config struct {
 | 
				
			|||||||
	Strategy      string
 | 
						Strategy      string
 | 
				
			||||||
	CheckWebSite  string
 | 
						CheckWebSite  string
 | 
				
			||||||
	CheckInterval int
 | 
						CheckInterval int
 | 
				
			||||||
 | 
						LatencyThreshold int
 | 
				
			||||||
	MaxFailures   int
 | 
						MaxFailures   int
 | 
				
			||||||
	IntFace       string
 | 
						IntFace       string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -229,11 +230,18 @@ func (d *Dialer) check(i int) {
 | 
				
			|||||||
			f.Disable()
 | 
								f.Disable()
 | 
				
			||||||
			log.F("[check] %s(%d) -> %s, DISABLED. error in read: %s", f.Addr(), f.Priority(), d.config.CheckWebSite, err)
 | 
								log.F("[check] %s(%d) -> %s, DISABLED. error in read: %s", f.Addr(), f.Priority(), d.config.CheckWebSite, err)
 | 
				
			||||||
		} else if bytes.Equal([]byte("HTTP"), buf) {
 | 
							} else if bytes.Equal([]byte("HTTP"), buf) {
 | 
				
			||||||
			f.Enable()
 | 
					 | 
				
			||||||
			retry = 2
 | 
								retry = 2
 | 
				
			||||||
			readTime := time.Since(startTime)
 | 
								readTime := time.Since(startTime)
 | 
				
			||||||
 | 
								readLatency := int64(readTime) / 1e6
 | 
				
			||||||
 | 
								LatencyThreshold := int64(d.config.LatencyThreshold)
 | 
				
			||||||
 | 
								if readLatency > LatencyThreshold {
 | 
				
			||||||
 | 
									f.Disable()
 | 
				
			||||||
 | 
									log.F("[check] %s(%d) -> %s, DISABLED. connect time: %s > latencythreshold: %dms", f.Addr(), f.Priority(), d.config.CheckWebSite, readTime.String(), LatencyThreshold)
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									f.Enable()
 | 
				
			||||||
				f.SetLatency(int64(readTime))
 | 
									f.SetLatency(int64(readTime))
 | 
				
			||||||
				log.F("[check] %s(%d) -> %s, ENABLED. connect time: %s", f.Addr(), f.Priority(), d.config.CheckWebSite, readTime.String())
 | 
									log.F("[check] %s(%d) -> %s, ENABLED. connect time: %s", f.Addr(), f.Priority(), d.config.CheckWebSite, readTime.String())
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			f.Disable()
 | 
								f.Disable()
 | 
				
			||||||
			log.F("[check] %s(%d) -> %s, DISABLED. server response: %s", f.Addr(), f.Priority(), d.config.CheckWebSite, buf)
 | 
								log.F("[check] %s(%d) -> %s, DISABLED. server response: %s", f.Addr(), f.Priority(), d.config.CheckWebSite, buf)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user