kopia lustrzana https://github.com/cyoung/stratux
				
				
				
			Print stats in main log.
2015/09/22 13:52:11 stats [uptime 1 minute ago] 2015/09/22 13:52:11 - CPUTemp=49.23 deg C, MemStats.Alloc=101MB, MemStats.Sys=126MB, totalNetworkMessagesSent=0 2015/09/22 13:52:11 - UAT/min 103,226/103,226 [maxSS=55.30%], ES/min 0/0 2015/09/22 13:52:11 - Total traffic targets tracked=0, last GPS fix: a long while agopull/58/head
							rodzic
							
								
									476ebed93d
								
							
						
					
					
						commit
						0db905904f
					
				|  | @ -13,6 +13,7 @@ import ( | |||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	"time" | ||||
| 	"github.com/dustin/go-humanize" | ||||
| ) | ||||
| 
 | ||||
| // http://www.faa.gov/nextgen/programs/adsb/wsa/media/GDL90_Public_ICD_RevA.PDF
 | ||||
|  | @ -391,6 +392,19 @@ func parseInput(buf string) ([]byte, uint16) { | |||
| 		parseDownlinkReport(s) | ||||
| 	} | ||||
| 
 | ||||
| 	if isUplink && len(x) >= 3 { | ||||
| 		// See if we can parse out the signal strength.
 | ||||
| 		ss := x[2] | ||||
| 		if strings.HasPrefix(ss, "ss=") { | ||||
| 			ssStr := ss[3:] | ||||
| 			if ssInt, err := strconv.Atoi(ssStr); err == nil { | ||||
| 				if ssInt > maxSignalStrength { | ||||
| 					maxSignalStrength = ssInt | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	s = s[1:] | ||||
| 	msglen := len(s) / 2 | ||||
| 
 | ||||
|  | @ -536,7 +550,7 @@ func defaultSettings() { | |||
| 	globalSettings.ES_Enabled = false  //TODO
 | ||||
| 	globalSettings.GPS_Enabled = false //TODO
 | ||||
| 	//FIXME: Need to change format below.
 | ||||
| 	globalSettings.NetworkOutputs = []networkConnection{{nil, "", 4000, NETWORK_GDL90_STANDARD, nil, time.Time{}, time.Time{}}, {nil, "", 43211, NETWORK_GDL90_STANDARD | NETWORK_AHRS_GDL90, nil, time.Time{}, time.Time{}}, {nil, "", 49002, NETWORK_AHRS_FFSIM, nil, time.Time{}, time.Time{}}} | ||||
| 	globalSettings.NetworkOutputs = []networkConnection{{nil, "", 4000, NETWORK_GDL90_STANDARD, nil, time.Time{}, time.Time{}, 0}, {nil, "", 43211, NETWORK_GDL90_STANDARD | NETWORK_AHRS_GDL90, nil, time.Time{}, time.Time{}, 0}, {nil, "", 49002, NETWORK_AHRS_FFSIM, nil, time.Time{}, time.Time{}, 0}} | ||||
| 	globalSettings.AHRS_Enabled = false | ||||
| 	globalSettings.DEBUG = false | ||||
| 	globalSettings.ReplayLog = false //TODO: 'true' for debug builds.
 | ||||
|  | @ -590,6 +604,19 @@ func openReplay(fn string) (*os.File, error) { | |||
| 	return ret, err | ||||
| } | ||||
| 
 | ||||
| func printStats() { | ||||
| 	statTimer := time.NewTicker(30 * time.Second) | ||||
| 	for { | ||||
| 		<-statTimer.C | ||||
| 		var memstats runtime.MemStats | ||||
| 		runtime.ReadMemStats(&memstats) | ||||
| 		log.Printf("stats [up since: %s]\n", humanize.Time(timeStarted)) | ||||
| 		log.Printf(" - CPUTemp=%.02f deg C, MemStats.Alloc=%s, MemStats.Sys=%s, totalNetworkMessagesSent=%s\n", globalStatus.CPUTemp, humanize.Bytes(uint64(memstats.Alloc)), humanize.Bytes(uint64(memstats.Sys)), humanize.Comma(int64(totalNetworkMessagesSent))) | ||||
| 		log.Printf(" - UAT/min %s/%s [maxSS=%.02f%%], ES/min %s/%s\n", humanize.Comma(int64(globalStatus.UAT_messages_last_minute)), humanize.Comma(int64(globalStatus.UAT_messages_max)), float64(maxSignalStrength) / 10.0, humanize.Comma(int64(globalStatus.ES_messages_last_minute)), humanize.Comma(int64(globalStatus.ES_messages_max))) | ||||
| 		log.Printf(" - Total traffic targets tracked=%s, last GPS fix: %s\n", humanize.Comma(int64(len(seenTraffic))), humanize.Time(mySituation.lastFixLocalTime)) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func main() { | ||||
| 	timeStarted = time.Now() | ||||
| 	runtime.GOMAXPROCS(runtime.NumCPU()) // redundant with Go v1.5+ compiler
 | ||||
|  | @ -651,6 +678,9 @@ func main() { | |||
| 	// Initialize the (out) network handler.
 | ||||
| 	initNetwork() | ||||
| 
 | ||||
| 	// Start printing stats periodically to the logfiles.
 | ||||
| 	go printStats() | ||||
| 
 | ||||
| 	reader := bufio.NewReader(os.Stdin) | ||||
| 
 | ||||
| 	for { | ||||
|  |  | |||
|  | @ -41,6 +41,8 @@ var outSockets map[string]networkConnection | |||
| var dhcpLeases map[string]string | ||||
| var netMutex *sync.Mutex | ||||
| 
 | ||||
| var totalNetworkMessagesSent uint32 | ||||
| 
 | ||||
| var pingResponse map[string]time.Time // Last time an IP responded to an "echo" response.
 | ||||
| 
 | ||||
| const ( | ||||
|  | @ -108,6 +110,7 @@ func sendToAllConnectedClients(msg networkMessage) { | |||
| 		if !msg.queueable { | ||||
| 			if !isSleeping(k) { | ||||
| 				netconn.Conn.Write(msg.msg) // Write immediately.
 | ||||
| 				totalNetworkMessagesSent++ | ||||
| 			} | ||||
| 		} else { | ||||
| 			if !isSleeping(k) { | ||||
|  | @ -118,7 +121,7 @@ func sendToAllConnectedClients(msg networkMessage) { | |||
| 				log.Printf("%s:%d - message queue overflow.\n", netconn.Ip, netconn.Port) | ||||
| 				netconn.numOverflows++ | ||||
| 				s := 2 * netconn.numOverflows // Double the amount we chop off on each overflow.
 | ||||
| 				if s >= len(netconn.messageQueue) { | ||||
| 				if int(s) >= len(netconn.messageQueue) { | ||||
| 					netconn.messageQueue = make([][]byte, 0) | ||||
| 				} else { | ||||
| 					netconn.messageQueue = netconn.messageQueue[s:] | ||||
|  | @ -193,6 +196,7 @@ func messageQueueSender() { | |||
| 				if len(netconn.messageQueue) > 0 && !isSleeping(k) && !isThrottled(k) { | ||||
| 					tmpConn := netconn | ||||
| 					tmpConn.Conn.Write(tmpConn.messageQueue[0]) | ||||
| 					totalNetworkMessagesSent++ | ||||
| 					tmpConn.messageQueue = tmpConn.messageQueue[1:] | ||||
| 					outSockets[k] = tmpConn | ||||
| 				} | ||||
|  | @ -251,6 +255,7 @@ func icmpEchoSender(c *icmp.PacketConn) { | |||
| 				log.Printf("couldn't send ICMP Echo: %s\n", err.Error()) | ||||
| 				continue | ||||
| 			} | ||||
| 			totalNetworkMessagesSent++ | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -10,6 +10,8 @@ import ( | |||
| var uatSDR int // Index.
 | ||||
| var esSDR int  // Index.
 | ||||
| 
 | ||||
| var maxSignalStrength int | ||||
| 
 | ||||
| // Read 978MHz from SDR.
 | ||||
| func sdrReader() { | ||||
| 	var err error | ||||
|  |  | |||
|  | @ -73,6 +73,7 @@ type TrafficInfo struct { | |||
| 
 | ||||
| var traffic map[uint32]TrafficInfo | ||||
| var trafficMutex *sync.Mutex | ||||
| var seenTraffic map[uint32]bool // Historical list of all ICAO addresses seen.
 | ||||
| 
 | ||||
| func cleanupOldEntries() { | ||||
| 	for icao_addr, ti := range traffic { | ||||
|  | @ -351,6 +352,7 @@ func parseDownlinkReport(s string) { | |||
| 	} | ||||
| 
 | ||||
| 	traffic[ti.icao_addr] = ti | ||||
| 	seenTraffic[ti.icao_addr] = true // Mark as seen.
 | ||||
| } | ||||
| 
 | ||||
| func esListen() { | ||||
|  | @ -417,18 +419,18 @@ func esListen() { | |||
| 
 | ||||
| 				altFloat, err := strconv.ParseFloat(alt, 32) | ||||
| 				if err != nil { | ||||
| //					log.Printf("err parsing alt (%s): %s\n", alt, err.Error())
 | ||||
| 					//					log.Printf("err parsing alt (%s): %s\n", alt, err.Error())
 | ||||
| 					valid_change = false | ||||
| 				} | ||||
| 
 | ||||
| 				latFloat, err := strconv.ParseFloat(lat, 32) | ||||
| 				if err != nil { | ||||
| //					log.Printf("err parsing lat (%s): %s\n", lat, err.Error())
 | ||||
| 					//					log.Printf("err parsing lat (%s): %s\n", lat, err.Error())
 | ||||
| 					valid_change = false | ||||
| 				} | ||||
| 				lngFloat, err := strconv.ParseFloat(lng, 32) | ||||
| 				if err != nil { | ||||
| //					log.Printf("err parsing lng (%s): %s\n", lng, err.Error())
 | ||||
| 					//					log.Printf("err parsing lng (%s): %s\n", lng, err.Error())
 | ||||
| 					valid_change = false | ||||
| 				} | ||||
| 
 | ||||
|  | @ -452,18 +454,18 @@ func esListen() { | |||
| 
 | ||||
| 				speedFloat, err := strconv.ParseFloat(speed, 32) | ||||
| 				if err != nil { | ||||
| //					log.Printf("err parsing speed (%s): %s\n", speed, err.Error())
 | ||||
| 					//					log.Printf("err parsing speed (%s): %s\n", speed, err.Error())
 | ||||
| 					valid_change = false | ||||
| 				} | ||||
| 
 | ||||
| 				trackFloat, err := strconv.ParseFloat(track, 32) | ||||
| 				if err != nil { | ||||
| //					log.Printf("err parsing track (%s): %s\n", track, err.Error())
 | ||||
| 					//					log.Printf("err parsing track (%s): %s\n", track, err.Error())
 | ||||
| 					valid_change = false | ||||
| 				} | ||||
| 				vvelFloat, err := strconv.ParseFloat(vvel, 32) | ||||
| 				if err != nil { | ||||
| //					log.Printf("err parsing vvel (%s): %s\n", vvel, err.Error())
 | ||||
| 					//					log.Printf("err parsing vvel (%s): %s\n", vvel, err.Error())
 | ||||
| 					valid_change = false | ||||
| 				} | ||||
| 
 | ||||
|  | @ -503,6 +505,7 @@ func esListen() { | |||
| 			} | ||||
| 
 | ||||
| 			traffic[icaoDec] = ti // Update information on this ICAO code.
 | ||||
| 			seenTraffic[icaoDec] = true // Mark as seen.
 | ||||
| 			trafficMutex.Unlock() | ||||
| 		} | ||||
| 	} | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 Christopher Young
						Christopher Young