| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package squidlog |
| 4 | |
| 5 | import "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/oldmetrix" |
| 6 | |
| 7 | func newSummary() oldmetrix.Summary { |
| 8 | return &summary{oldmetrix.NewSummary()} |
| 9 | } |
| 10 | |
| 11 | type summary struct { |
| 12 | oldmetrix.Summary |
| 13 | } |
| 14 | |
| 15 | func (s summary) WriteTo(rv map[string]int64, key string, mul, div int) { |
| 16 | s.Summary.WriteTo(rv, key, mul, div) |
| 17 | if _, ok := rv[key+"_min"]; !ok { |
| 18 | rv[key+"_min"] = 0 |
| 19 | rv[key+"_max"] = 0 |
| 20 | rv[key+"_avg"] = 0 |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | const ( |
| 25 | pxHTTPCode = "http_resp_code_" |
| 26 | pxReqMethod = "req_method_" |
| 27 | pxCacheCode = "cache_result_code_" |
| 28 | pxTransportTag = "cache_transport_tag_" |
| 29 | pxHandlingTag = "cache_handling_tag_" |
| 30 | pxObjectTag = "cache_object_tag_" |
| 31 | pxSourceTag = "cache_load_source_tag_" |
| 32 | pxErrorTag = "cache_error_tag_" |
| 33 | pxHierCode = "hier_code_" |
| 34 | pxMimeType = "mime_type_" |
| 35 | pxSrvAddr = "server_address_" |
| 36 | ) |
| 37 | |
| 38 | type metricsData struct { |
| 39 | Requests oldmetrix.Counter `stm:"requests"` |
| 40 | Unmatched oldmetrix.Counter `stm:"unmatched"` |
| 41 | |
| 42 | HTTPRespCode oldmetrix.CounterVec `stm:"http_resp_code"` |
| 43 | HTTPResp0xx oldmetrix.Counter `stm:"http_resp_0xx"` |
| 44 | HTTPResp1xx oldmetrix.Counter `stm:"http_resp_1xx"` |
| 45 | HTTPResp2xx oldmetrix.Counter `stm:"http_resp_2xx"` |
| 46 | HTTPResp3xx oldmetrix.Counter `stm:"http_resp_3xx"` |
| 47 | HTTPResp4xx oldmetrix.Counter `stm:"http_resp_4xx"` |
| 48 | HTTPResp5xx oldmetrix.Counter `stm:"http_resp_5xx"` |
| 49 | HTTPResp6xx oldmetrix.Counter `stm:"http_resp_6xx"` |
| 50 | |
| 51 | ReqSuccess oldmetrix.Counter `stm:"req_type_success"` |
| 52 | ReqRedirect oldmetrix.Counter `stm:"req_type_redirect"` |
| 53 | ReqBad oldmetrix.Counter `stm:"req_type_bad"` |
| 54 | ReqError oldmetrix.Counter `stm:"req_type_error"` |
| 55 | |
| 56 | BytesSent oldmetrix.Counter `stm:"bytes_sent"` |
| 57 | RespTime oldmetrix.Summary `stm:"resp_time,1000,1"` |
| 58 | UniqueClients oldmetrix.UniqueCounter `stm:"uniq_clients"` |
| 59 | |
| 60 | ReqMethod oldmetrix.CounterVec `stm:"req_method"` |
| 61 | CacheCode oldmetrix.CounterVec `stm:"cache_result_code"` |
| 62 | CacheCodeTransportTag oldmetrix.CounterVec `stm:"cache_transport_tag"` |
| 63 | CacheCodeHandlingTag oldmetrix.CounterVec `stm:"cache_handling_tag"` |
| 64 | CacheCodeObjectTag oldmetrix.CounterVec `stm:"cache_object_tag"` |
| 65 | CacheCodeLoadSourceTag oldmetrix.CounterVec `stm:"cache_load_source_tag"` |
| 66 | CacheCodeErrorTag oldmetrix.CounterVec `stm:"cache_error_tag"` |
| 67 | HierCode oldmetrix.CounterVec `stm:"hier_code"` |
| 68 | MimeType oldmetrix.CounterVec `stm:"mime_type"` |
| 69 | Server oldmetrix.CounterVec `stm:"server_address"` |
| 70 | } |
| 71 | |
| 72 | func (m *metricsData) reset() { |
| 73 | m.RespTime.Reset() |
| 74 | m.UniqueClients.Reset() |
| 75 | } |
| 76 | |
| 77 | func newMetricsData() *metricsData { |
| 78 | return &metricsData{ |
| 79 | RespTime: newSummary(), |
| 80 | UniqueClients: oldmetrix.NewUniqueCounter(true), |
| 81 | HTTPRespCode: oldmetrix.NewCounterVec(), |
| 82 | ReqMethod: oldmetrix.NewCounterVec(), |
| 83 | CacheCode: oldmetrix.NewCounterVec(), |
| 84 | CacheCodeTransportTag: oldmetrix.NewCounterVec(), |
| 85 | CacheCodeHandlingTag: oldmetrix.NewCounterVec(), |
| 86 | CacheCodeObjectTag: oldmetrix.NewCounterVec(), |
| 87 | CacheCodeLoadSourceTag: oldmetrix.NewCounterVec(), |
| 88 | CacheCodeErrorTag: oldmetrix.NewCounterVec(), |
| 89 | HierCode: oldmetrix.NewCounterVec(), |
| 90 | Server: oldmetrix.NewCounterVec(), |
| 91 | MimeType: oldmetrix.NewCounterVec(), |
| 92 | } |
| 93 | } |