diff --git a/common/counters/memory.go b/common/counters/memory.go index cc702fbc..11bb5307 100644 --- a/common/counters/memory.go +++ b/common/counters/memory.go @@ -28,7 +28,7 @@ type DefaultMemoryCounter struct { func NewMemoryCounter(acc *qgen.Accumulator) (*DefaultMemoryCounter, error) { co := &DefaultMemoryCounter{ - insert: acc.Insert("memchunks").Columns("count, stack, heap, createdAt").Fields("?,?,?,UTC_TIMESTAMP()").Prepare(), + insert: acc.Insert("memchunks").Columns("count,stack,heap,createdAt").Fields("?,?,?,UTC_TIMESTAMP()").Prepare(), } c.AddScheduledFifteenMinuteTask(co.Tick) //c.AddScheduledSecondTask(co.Tick) @@ -57,19 +57,16 @@ func NewMemoryCounter(acc *qgen.Accumulator) (*DefaultMemoryCounter, error) { func (co *DefaultMemoryCounter) Tick() (err error) { var m runtime.MemStats runtime.ReadMemStats(&m) - var avgMem, avgStack, avgHeap uint64 + var rTotMem, rTotCount, rStackMem, rStackCount, rHeapMem, rHeapCount uint64 + co.Lock() - co.totCount++ - co.totMem += m.Sys - co.stackCount++ - co.stackMem += m.StackInuse - co.heapCount++ - co.heapMem += m.HeapAlloc - - avgMem = co.totMem / co.totCount - avgStack = co.stackMem / co.stackCount - avgHeap = co.heapMem / co.heapCount + rTotMem = co.totMem + rTotCount = co.totCount + rStackMem = co.stackMem + rStackCount = co.stackCount + rHeapMem = co.heapMem + rHeapCount = co.heapCount co.totMem = 0 co.totCount = 0 @@ -80,6 +77,11 @@ func (co *DefaultMemoryCounter) Tick() (err error) { co.Unlock() + var avgMem, avgStack, avgHeap uint64 + avgMem = (rTotMem + m.Sys) / (rTotCount + 1) + avgStack = (rStackMem + m.StackInuse) / (rStackCount + 1) + avgHeap = (rHeapMem + m.HeapAlloc) / (rHeapCount + 1) + c.DebugLogf("Inserting a memchunk with a value of %d - %d - %d", avgMem, avgStack, avgHeap) _, err = co.insert.Exec(avgMem, avgStack, avgHeap) if err != nil { diff --git a/common/counters/systems.go b/common/counters/systems.go index 42e963e3..d8d310ae 100644 --- a/common/counters/systems.go +++ b/common/counters/systems.go @@ -50,7 +50,7 @@ func (co *DefaultOSViewCounter) insertChunk(count int64, os int) error { func (co *DefaultOSViewCounter) Bump(id int) { // TODO: Test this check - c.DebugDetail("co.buckets[", id, "]: ", co.buckets[id]) + c.DebugDetail("buckets[", id, "]: ", co.buckets[id]) if len(co.buckets) <= id || id < 0 { return } diff --git a/gen_router.go b/gen_router.go index f652b561..e23a5ab1 100644 --- a/gen_router.go +++ b/gen_router.go @@ -958,7 +958,7 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { // WIP UA Parser var items []string var buffer []byte - var os string + var os int for _, it := range StringToBytes(ua) { if (it > 64 && it < 91) || (it > 96 && it < 123) { buffer = append(buffer, it) @@ -968,15 +968,15 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Use an unsafe zero copy conversion here just to use the switch, it's not safe for this string to escape from here, as it will get mutated, so do a regular string conversion in append switch(BytesToString(buffer)) { case "Windows": - os = "windows" + os = 1 case "Linux": - os = "linux" + os = 2 case "Mac": - os = "mac" + os = 3 case "iPhone": - os = "iphone" + os = 5 case "Android": - os = "android" + os = 4 case "like","compatible": // Skip these words default: @@ -994,9 +994,6 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { break } } - if os == "" { - os = "unknown" - } // Iterate over this in reverse as the real UA tends to be on the right side for i := len(items) - 1; i >= 0; i-- { @@ -1019,11 +1016,11 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Special handling switch(agent) { case "chrome": - if os == "android" { + if os == 4 { agent = "androidchrome" } case "safari": - if os == "iphone" { + if os == 5 { agent = "mobilesafari" } case "trident": @@ -1047,7 +1044,8 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { } else { co.AgentViewCounter.Bump(agentMapEnum[agent]) } - co.OSViewCounter.Bump(osMapEnum[os]) + //co.OSViewCounter.Bump(osMapEnum[os]) + co.OSViewCounter.Bump(os) } // TODO: Do we want to track missing language headers too? Maybe as it's own type, e.g. "noheader"? diff --git a/langs/english.json b/langs/english.json index 769613e1..946b6737 100644 --- a/langs/english.json +++ b/langs/english.json @@ -984,6 +984,7 @@ "panel_stats_post_counts_head":"Post Counts", "panel_stats_referrers_head":"Referrers", "panel_stats_routes_head":"Routes", + "panel_stats_routes_perf_head":"Routes Performance", "panel_stats_operating_systems_head":"Operating Systems", "panel_stats_topic_counts_head":"Topic Counts", "panel_stats_requests_head":"Requests", diff --git a/router_gen/main.go b/router_gen/main.go index eb3651c5..9345e8bc 100644 --- a/router_gen/main.go +++ b/router_gen/main.go @@ -665,7 +665,7 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { // WIP UA Parser var items []string var buffer []byte - var os string + var os int for _, it := range StringToBytes(ua) { if (it > 64 && it < 91) || (it > 96 && it < 123) { buffer = append(buffer, it) @@ -675,15 +675,15 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Use an unsafe zero copy conversion here just to use the switch, it's not safe for this string to escape from here, as it will get mutated, so do a regular string conversion in append switch(BytesToString(buffer)) { case "Windows": - os = "windows" + os = {{.AllOSMap.windows}} case "Linux": - os = "linux" + os = {{.AllOSMap.linux}} case "Mac": - os = "mac" + os = {{.AllOSMap.mac}} case "iPhone": - os = "iphone" + os = {{.AllOSMap.iphone}} case "Android": - os = "android" + os = {{.AllOSMap.android}} case "like","compatible": // Skip these words default: @@ -701,9 +701,6 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { break } } - if os == "" { - os = "unknown" - } // Iterate over this in reverse as the real UA tends to be on the right side for i := len(items) - 1; i >= 0; i-- { @@ -726,11 +723,11 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Special handling switch(agent) { case "chrome": - if os == "android" { + if os == {{.AllOSMap.android}} { agent = "androidchrome" } case "safari": - if os == "iphone" { + if os == {{.AllOSMap.iphone}} { agent = "mobilesafari" } case "trident": @@ -754,7 +751,8 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { } else { co.AgentViewCounter.Bump(agentMapEnum[agent]) } - co.OSViewCounter.Bump(osMapEnum[os]) + //co.OSViewCounter.Bump(osMapEnum[os]) + co.OSViewCounter.Bump(os) } // TODO: Do we want to track missing language headers too? Maybe as it's own type, e.g. "noheader"? diff --git a/routes/panel/analytics.go b/routes/panel/analytics.go index d80d9a42..bc1870ba 100644 --- a/routes/panel/analytics.go +++ b/routes/panel/analytics.go @@ -827,21 +827,6 @@ func AnalyticsRoutesPerf(w http.ResponseWriter, r *http.Request, user c.User) c. return false } - /* - // TODO: Adjust for the missing chunks in week and month - var avgList []int64 - var avgItems []c.PanelAnalyticsItemUnit - for _, value := range revLabelList { - avgList = append(avgList, avgMap[value]) - cv, cu := c.ConvertPerfUnit(float64(avgMap[value])) - avgItems = append(avgItems, c.PanelAnalyticsItemUnit{Time: value, Unit: cu, Count: int64(cv)}) - } - graph := c.PanelTimeGraph{Series: [][]int64{avgList}, Labels: labelList} - c.DebugLogf("graph: %+v\n", graph) - pi := c.PanelAnalyticsPerf{graph, avgItems, timeRange.Range, timeRange.Unit, "time", typ} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_performance", pi}) - */ - var vList [][]int64 var legendList []string var i int diff --git a/templates/panel_analytics_routes_perf.html b/templates/panel_analytics_routes_perf.html index 7a49098a..71784e6a 100644 --- a/templates/panel_analytics_routes_perf.html +++ b/templates/panel_analytics_routes_perf.html @@ -1,6 +1,6 @@