@cryptotaxi247 / netdata-1 / commits / 1f178b191

chore(go.d.plugin): fix duplicate boolToInt (#18987)

Ilya Mashchenko committed Nov 10, 2024 at 21:31 UTC 1f178b1915828de9ddb81b84f1116b9f087c2b1c
52 files changed +314 -416
src/go/plugin/go.d/agent/module/job.go
+2 -8
@@ -15,6 +15,7 @@ import (
15
16 "github.com/netdata/netdata/go/plugins/logger"
17 "github.com/netdata/netdata/go/plugins/pkg/netdataapi"
18 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
19 )
20
21 var obsoleteLock = &sync.Mutex{}
@@ -459,7 +460,7 @@ func (j *Job) processMetrics(metrics map[string]int64, startTime time.Time, sinc
460
461 j.updateChart(
462 j.collectStatusChart,
462 - map[string]int64{"success": boolToInt(updated > 0), "failed": boolToInt(updated == 0)},
463 + map[string]int64{"success": metrix.Bool(updated > 0), "failed": metrix.Bool(updated == 0)},
464 sinceLastRun,
465 )
466
@@ -668,13 +669,6 @@ func handleZero(v int) int {
669 return v
670 }
671
671 -func boolToInt(b bool) int64 {
672 - if b {
673 - return 1
674 - }
675 - return 0
676 -}
677 -
672 func cleanPluginName(name string) string {
673 r := strings.NewReplacer(" ", "_", ".", "_")
674 return r.Replace(name)
src/go/plugin/go.d/modules/chrony/collect.go
+6 -11
@@ -10,6 +10,8 @@ import (
10 "strconv"
11 "strings"
12 "time"
13 +
14 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
15 )
16
17 const scaleFactor = 1000000000
@@ -58,10 +60,10 @@ func (c *Chrony) collectTracking(mx map[string]int64) error {
60 }
61
62 mx["stratum"] = int64(reply.Stratum)
61 - mx["leap_status_normal"] = boolToInt(reply.LeapStatus == leapStatusNormal)
62 - mx["leap_status_insert_second"] = boolToInt(reply.LeapStatus == leapStatusInsertSecond)
63 - mx["leap_status_delete_second"] = boolToInt(reply.LeapStatus == leapStatusDeleteSecond)
64 - mx["leap_status_unsynchronised"] = boolToInt(reply.LeapStatus == leapStatusUnsynchronised)
63 + mx["leap_status_normal"] = metrix.Bool(reply.LeapStatus == leapStatusNormal)
64 + mx["leap_status_insert_second"] = metrix.Bool(reply.LeapStatus == leapStatusInsertSecond)
65 + mx["leap_status_delete_second"] = metrix.Bool(reply.LeapStatus == leapStatusDeleteSecond)
66 + mx["leap_status_unsynchronised"] = metrix.Bool(reply.LeapStatus == leapStatusUnsynchronised)
67 mx["root_delay"] = int64(reply.RootDelay * scaleFactor)
68 mx["root_dispersion"] = int64(reply.RootDispersion * scaleFactor)
69 mx["skew"] = int64(reply.SkewPPM * scaleFactor)
@@ -132,13 +134,6 @@ func (c *Chrony) collectServerStats(mx map[string]int64) error {
134 return nil
135 }
136
135 -func boolToInt(v bool) int64 {
136 - if v {
137 - return 1
138 - }
139 - return 0
140 -}
141 -
137 func abs(v int64) int64 {
138 if v < 0 {
139 return -v
src/go/plugin/go.d/modules/consul/collect.go
-7
@@ -85,10 +85,3 @@ func (c *Consul) createRequest(urlPath string) (*http.Request, error) {
85
86 return req, nil
87 }
88 -
89 -func boolToInt(v bool) int64 {
90 - if v {
91 - return 1
92 - }
93 - return 0
94 -}
src/go/plugin/go.d/modules/consul/collect_autopilot.go
+10 -8
@@ -5,6 +5,8 @@ package consul
5 import (
6 "net/http"
7 "time"
8 +
9 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
10 )
11
12 const (
@@ -42,15 +44,15 @@ func (c *Consul) collectAutopilotHealth(mx map[string]int64) error {
44 if srv.ID == c.cfg.Config.NodeID {
45 // SerfStatus: alive, left, failed or none:
46 // https://github.com/hashicorp/consul/blob/c7ef04c5979dbc311ff3c67b7bf3028a93e8b0f1/agent/consul/operator_autopilot_endpoint.go#L124-L133
45 - mx["autopilot_server_sefStatus_alive"] = boolToInt(srv.SerfStatus == "alive")
46 - mx["autopilot_server_sefStatus_left"] = boolToInt(srv.SerfStatus == "left")
47 - mx["autopilot_server_sefStatus_failed"] = boolToInt(srv.SerfStatus == "failed")
48 - mx["autopilot_server_sefStatus_none"] = boolToInt(srv.SerfStatus == "none")
47 + mx["autopilot_server_sefStatus_alive"] = metrix.Bool(srv.SerfStatus == "alive")
48 + mx["autopilot_server_sefStatus_left"] = metrix.Bool(srv.SerfStatus == "left")
49 + mx["autopilot_server_sefStatus_failed"] = metrix.Bool(srv.SerfStatus == "failed")
50 + mx["autopilot_server_sefStatus_none"] = metrix.Bool(srv.SerfStatus == "none")
51 // https://github.com/hashicorp/raft-autopilot/blob/d936f51c374c3b7902d5e4fdafe9f7d8d199ea53/types.go#L110
50 - mx["autopilot_server_healthy_yes"] = boolToInt(srv.Healthy)
51 - mx["autopilot_server_healthy_no"] = boolToInt(!srv.Healthy)
52 - mx["autopilot_server_voter_yes"] = boolToInt(srv.Voter)
53 - mx["autopilot_server_voter_no"] = boolToInt(!srv.Voter)
52 + mx["autopilot_server_healthy_yes"] = metrix.Bool(srv.Healthy)
53 + mx["autopilot_server_healthy_no"] = metrix.Bool(!srv.Healthy)
54 + mx["autopilot_server_voter_yes"] = metrix.Bool(srv.Voter)
55 + mx["autopilot_server_voter_no"] = metrix.Bool(!srv.Voter)
56 mx["autopilot_server_stable_time"] = int64(time.Since(srv.StableSince).Seconds())
57 mx["autopilot_server_stable_time"] = int64(time.Since(srv.StableSince).Seconds())
58 if !srv.Leader {
src/go/plugin/go.d/modules/consul/collect_checks.go
+6 -4
@@ -2,6 +2,8 @@
2
3 package consul
4
5 +import "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
6 +
7 const (
8 // https://www.consul.io/api-docs/agent/check#list-checks
9 urlPathAgentChecks = "/v1/agent/checks"
@@ -35,10 +37,10 @@ func (c *Consul) collectChecks(mx map[string]int64) error {
37 c.addHealthCheckCharts(check)
38 }
39
38 - mx["health_check_"+id+"_passing_status"] = boolToInt(check.Status == "passing")
39 - mx["health_check_"+id+"_warning_status"] = boolToInt(check.Status == "warning")
40 - mx["health_check_"+id+"_critical_status"] = boolToInt(check.Status == "critical")
41 - mx["health_check_"+id+"_maintenance_status"] = boolToInt(check.Status == "maintenance")
40 + mx["health_check_"+id+"_passing_status"] = metrix.Bool(check.Status == "passing")
41 + mx["health_check_"+id+"_warning_status"] = metrix.Bool(check.Status == "warning")
42 + mx["health_check_"+id+"_critical_status"] = metrix.Bool(check.Status == "critical")
43 + mx["health_check_"+id+"_maintenance_status"] = metrix.Bool(check.Status == "maintenance")
44 }
45
46 for id := range c.checks {
src/go/plugin/go.d/modules/consul/collect_metrics.go
+3 -2
@@ -4,6 +4,7 @@ package consul
4
5 import (
6 "fmt"
7 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
8 "math"
9 "strconv"
10 "strings"
@@ -142,8 +143,8 @@ func (c *Consul) collectGaugeBool(mx map[string]int64, mfs prometheus.MetricFami
143 v := mf.Metrics()[0].Gauge().Value()
144
145 if !math.IsNaN(v) {
145 - mx[name+"_yes"] = boolToInt(v == 1)
146 - mx[name+"_no"] = boolToInt(v == 0)
146 + mx[name+"_yes"] = metrix.Bool(v == 1)
147 + mx[name+"_no"] = metrix.Bool(v == 0)
148 }
149 }
150
src/go/plugin/go.d/modules/consul/collect_net_rtt.go
+2 -2
@@ -4,7 +4,7 @@ import (
4 "math"
5 "time"
6
7 - "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
7 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
8 )
9
10 const (
@@ -42,7 +42,7 @@ func (c *Consul) collectNetworkRTT(mx map[string]int64) error {
42 return nil
43 }
44
45 - sum := metrics.NewSummary()
45 + sum := metrix.NewSummary()
46 for _, v := range coords {
47 d := calcDistance(thisNode, v)
48 sum.Observe(d.Seconds())
src/go/plugin/go.d/modules/coredns/metrics.go
+1 -1
@@ -3,7 +3,7 @@
3 package coredns
4
5 import (
6 - mtx "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
6 + mtx "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
7 )
8
9 func newMetrics() *metrics {
src/go/plugin/go.d/modules/elasticsearch/collect.go
+7 -13
@@ -5,6 +5,7 @@ package elasticsearch
5 import (
6 "errors"
7 "fmt"
8 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
9 "math"
10 "slices"
11 "strconv"
@@ -82,9 +83,9 @@ func (es *Elasticsearch) collectClusterHealth(mx map[string]int64, ms *esMetrics
83
84 merge(mx, stm.ToMap(ms.ClusterHealth), "cluster")
85
85 - mx["cluster_status_green"] = boolToInt(ms.ClusterHealth.Status == "green")
86 - mx["cluster_status_yellow"] = boolToInt(ms.ClusterHealth.Status == "yellow")
87 - mx["cluster_status_red"] = boolToInt(ms.ClusterHealth.Status == "red")
86 + mx["cluster_status_green"] = metrix.Bool(ms.ClusterHealth.Status == "green")
87 + mx["cluster_status_yellow"] = metrix.Bool(ms.ClusterHealth.Status == "yellow")
88 + mx["cluster_status_red"] = metrix.Bool(ms.ClusterHealth.Status == "red")
89 }
90
91 func (es *Elasticsearch) collectClusterStats(mx map[string]int64, ms *esMetrics) {
@@ -114,9 +115,9 @@ func (es *Elasticsearch) collectLocalIndicesStats(mx map[string]int64, ms *esMet
115
116 px := fmt.Sprintf("node_index_%s_stats_", v.Index)
117
117 - mx[px+"health_green"] = boolToInt(v.Health == "green")
118 - mx[px+"health_yellow"] = boolToInt(v.Health == "yellow")
119 - mx[px+"health_red"] = boolToInt(v.Health == "red")
118 + mx[px+"health_green"] = metrix.Bool(v.Health == "green")
119 + mx[px+"health_yellow"] = metrix.Bool(v.Health == "yellow")
120 + mx[px+"health_red"] = metrix.Bool(v.Health == "red")
121 mx[px+"shards_count"] = strToInt(v.Rep)
122 mx[px+"docs_count"] = strToInt(v.DocsCount)
123 mx[px+"store_size_in_bytes"] = convertIndexStoreSizeToBytes(v.StoreSize)
@@ -254,13 +255,6 @@ func strToInt(s string) int64 {
255 return int64(v)
256 }
257
257 -func boolToInt(v bool) int64 {
258 - if v {
259 - return 1
260 - }
261 - return 0
262 -}
263 -
258 func removeSystemIndices(indices []esIndexStats) []esIndexStats {
259 return slices.DeleteFunc(indices, func(stats esIndexStats) bool {
260 return strings.HasPrefix(stats.Index, ".")
src/go/plugin/go.d/modules/k8s_kubelet/collect.go
+2 -3
@@ -5,11 +5,10 @@ package k8s_kubelet
5 import (
6 "math"
7
8 - mtx "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
8 + "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
9 + mtx "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
10 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
11 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/stm"
11 -
12 - "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12 )
13
14 func (k *Kubelet) collect() (map[string]int64, error) {
src/go/plugin/go.d/modules/k8s_kubelet/metrics.go
+1 -1
@@ -3,7 +3,7 @@
3 package k8s_kubelet
4
5 import (
6 - mtx "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
6 + mtx "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
7 )
8
9 func newMetrics() *metrics {
src/go/plugin/go.d/modules/k8s_kubeproxy/collect.go
+2 -3
@@ -5,11 +5,10 @@ package k8s_kubeproxy
5 import (
6 "math"
7
8 - mtx "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
8 + "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
9 + mtx "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
10 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
11 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/stm"
11 -
12 - "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12 )
13
14 func (kp *KubeProxy) collect() (map[string]int64, error) {
src/go/plugin/go.d/modules/k8s_kubeproxy/metrics.go
+1 -1
@@ -3,7 +3,7 @@
3 package k8s_kubeproxy
4
5 import (
6 - mtx "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
6 + mtx "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
7 )
8
9 func newMetrics() *metrics {
src/go/plugin/go.d/modules/k8s_state/collect.go
+29 -35
@@ -9,6 +9,7 @@ import (
9 "time"
10
11 "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
13
14 corev1 "k8s.io/api/core/v1"
15 )
@@ -144,25 +145,25 @@ func (ks *KubeState) collectPodsState(mx map[string]int64) {
145 ns.stats.podsCondPodScheduled += condStatusToInt(ps.condPodScheduled)
146 ns.stats.podsCondPodInitialized += condStatusToInt(ps.condPodInitialized)
147 ns.stats.podsCondContainersReady += condStatusToInt(ps.condContainersReady)
147 - ns.stats.podsReadinessReady += boolToInt(ps.condPodReady == corev1.ConditionTrue)
148 - ns.stats.podsReadinessUnready += boolToInt(ps.condPodReady != corev1.ConditionTrue)
149 - ns.stats.podsPhasePending += boolToInt(ps.phase == corev1.PodPending)
150 - ns.stats.podsPhaseRunning += boolToInt(ps.phase == corev1.PodRunning)
151 - ns.stats.podsPhaseSucceeded += boolToInt(ps.phase == corev1.PodSucceeded)
152 - ns.stats.podsPhaseFailed += boolToInt(ps.phase == corev1.PodFailed)
148 + ns.stats.podsReadinessReady += metrix.Bool(ps.condPodReady == corev1.ConditionTrue)
149 + ns.stats.podsReadinessUnready += metrix.Bool(ps.condPodReady != corev1.ConditionTrue)
150 + ns.stats.podsPhasePending += metrix.Bool(ps.phase == corev1.PodPending)
151 + ns.stats.podsPhaseRunning += metrix.Bool(ps.phase == corev1.PodRunning)
152 + ns.stats.podsPhaseSucceeded += metrix.Bool(ps.phase == corev1.PodSucceeded)
153 + ns.stats.podsPhaseFailed += metrix.Bool(ps.phase == corev1.PodFailed)
154
155 for _, cs := range ps.initContainers {
156 ns.stats.initContainers++
156 - ns.stats.initContStateRunning += boolToInt(cs.stateRunning)
157 - ns.stats.initContStateWaiting += boolToInt(cs.stateWaiting)
158 - ns.stats.initContStateTerminated += boolToInt(cs.stateTerminated)
157 + ns.stats.initContStateRunning += metrix.Bool(cs.stateRunning)
158 + ns.stats.initContStateWaiting += metrix.Bool(cs.stateWaiting)
159 + ns.stats.initContStateTerminated += metrix.Bool(cs.stateTerminated)
160 }
161
162 for _, cs := range ps.containers {
163 ns.stats.containers++
163 - ns.stats.contStateRunning += boolToInt(cs.stateRunning)
164 - ns.stats.contStateWaiting += boolToInt(cs.stateWaiting)
165 - ns.stats.contStateTerminated += boolToInt(cs.stateTerminated)
164 + ns.stats.contStateRunning += metrix.Bool(cs.stateRunning)
165 + ns.stats.contStateWaiting += metrix.Bool(cs.stateWaiting)
166 + ns.stats.contStateTerminated += metrix.Bool(cs.stateTerminated)
167 }
168 }
169
@@ -172,10 +173,10 @@ func (ks *KubeState) collectPodsState(mx map[string]int64) {
173 mx[px+"cond_podscheduled"] = condStatusToInt(ps.condPodScheduled)
174 mx[px+"cond_podinitialized"] = condStatusToInt(ps.condPodInitialized)
175 mx[px+"cond_containersready"] = condStatusToInt(ps.condContainersReady)
175 - mx[px+"phase_running"] = boolToInt(ps.phase == corev1.PodRunning)
176 - mx[px+"phase_failed"] = boolToInt(ps.phase == corev1.PodFailed)
177 - mx[px+"phase_succeeded"] = boolToInt(ps.phase == corev1.PodSucceeded)
178 - mx[px+"phase_pending"] = boolToInt(ps.phase == corev1.PodPending)
176 + mx[px+"phase_running"] = metrix.Bool(ps.phase == corev1.PodRunning)
177 + mx[px+"phase_failed"] = metrix.Bool(ps.phase == corev1.PodFailed)
178 + mx[px+"phase_succeeded"] = metrix.Bool(ps.phase == corev1.PodSucceeded)
179 + mx[px+"phase_pending"] = metrix.Bool(ps.phase == corev1.PodPending)
180 mx[px+"age"] = int64(now.Sub(ps.creationTime).Seconds())
181
182 for _, v := range podStatusReasons {
@@ -201,9 +202,9 @@ func (ks *KubeState) collectPodsState(mx map[string]int64) {
202 mx[px+"init_containers_state_terminated"] = 0
203
204 for _, cs := range ps.initContainers {
204 - mx[px+"init_containers_state_running"] += boolToInt(cs.stateRunning)
205 - mx[px+"init_containers_state_waiting"] += boolToInt(cs.stateWaiting)
206 - mx[px+"init_containers_state_terminated"] += boolToInt(cs.stateTerminated)
205 + mx[px+"init_containers_state_running"] += metrix.Bool(cs.stateRunning)
206 + mx[px+"init_containers_state_waiting"] += metrix.Bool(cs.stateWaiting)
207 + mx[px+"init_containers_state_terminated"] += metrix.Bool(cs.stateTerminated)
208 }
209 mx[px+"containers_state_running"] = 0
210 mx[px+"containers_state_waiting"] = 0
@@ -214,15 +215,15 @@ func (ks *KubeState) collectPodsState(mx map[string]int64) {
215 cs.new = false
216 ks.addContainerCharts(ps, cs)
217 }
217 - mx[px+"containers_state_running"] += boolToInt(cs.stateRunning)
218 - mx[px+"containers_state_waiting"] += boolToInt(cs.stateWaiting)
219 - mx[px+"containers_state_terminated"] += boolToInt(cs.stateTerminated)
218 + mx[px+"containers_state_running"] += metrix.Bool(cs.stateRunning)
219 + mx[px+"containers_state_waiting"] += metrix.Bool(cs.stateWaiting)
220 + mx[px+"containers_state_terminated"] += metrix.Bool(cs.stateTerminated)
221
222 ppx := fmt.Sprintf("%scontainer_%s_", px, cs.name)
222 - mx[ppx+"state_running"] = boolToInt(cs.stateRunning)
223 - mx[ppx+"state_waiting"] = boolToInt(cs.stateWaiting)
224 - mx[ppx+"state_terminated"] = boolToInt(cs.stateTerminated)
225 - mx[ppx+"readiness"] = boolToInt(cs.ready)
223 + mx[ppx+"state_running"] = metrix.Bool(cs.stateRunning)
224 + mx[ppx+"state_waiting"] = metrix.Bool(cs.stateWaiting)
225 + mx[ppx+"state_terminated"] = metrix.Bool(cs.stateTerminated)
226 + mx[ppx+"readiness"] = metrix.Bool(cs.ready)
227 mx[ppx+"restarts"] = cs.restarts
228
229 for _, v := range containerWaitingStateReasons {
@@ -284,8 +285,8 @@ func (ks *KubeState) collectNodesState(mx map[string]int64) {
285 mx[px+"pods_cond_podinitialized"] = ns.stats.podsCondPodInitialized
286 mx[px+"pods_cond_containersready"] = ns.stats.podsCondContainersReady
287 mx[px+"pods_cond_containersready"] = ns.stats.podsCondContainersReady
287 - mx[px+"schedulability_schedulable"] = boolToInt(!ns.unSchedulable)
288 - mx[px+"schedulability_unschedulable"] = boolToInt(ns.unSchedulable)
288 + mx[px+"schedulability_schedulable"] = metrix.Bool(!ns.unSchedulable)
289 + mx[px+"schedulability_unschedulable"] = metrix.Bool(ns.unSchedulable)
290 mx[px+"alloc_pods_available"] = ns.allocatablePods - ns.stats.pods
291 mx[px+"alloc_pods_allocated"] = ns.stats.pods
292 mx[px+"alloc_cpu_requests_util"] = calcPercentage(ns.stats.reqCPU, ns.allocatableCPU)
@@ -307,13 +308,6 @@ func (ks *KubeState) collectNodesState(mx map[string]int64) {
308 }
309 }
310
310 -func boolToInt(v bool) int64 {
311 - if v {
312 - return 1
313 - }
314 - return 0
315 -}
316 -
311 func condStatusToInt(cs corev1.ConditionStatus) int64 {
312 switch cs {
313 case corev1.ConditionFalse:
src/go/plugin/go.d/modules/mongodb/collect.go
-7
@@ -34,10 +34,3 @@ func (m *Mongo) collect() (map[string]int64, error) {
34
35 return mx, nil
36 }
37 -
38 -func boolToInt(v bool) int64 {
39 - if v {
40 - return 1
41 - }
42 - return 0
43 -}
src/go/plugin/go.d/modules/mongodb/collect_replsetgetstatus.go
+4 -3
@@ -7,6 +7,7 @@ import (
7 "strings"
8
9 "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
10 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
11 )
12
13 // https://www.mongodb.com/docs/manual/reference/replica-states/#replica-set-member-states
@@ -41,11 +42,11 @@ func (m *Mongo) collectReplSetStatus(mx map[string]int64) error {
42 mx[px+"replication_lag"] = s.Date.Sub(member.OptimeDate).Milliseconds()
43
44 for k, v := range replicaSetMemberStates {
44 - mx[px+"state_"+k] = boolToInt(member.State == v)
45 + mx[px+"state_"+k] = metrix.Bool(member.State == v)
46 }
47
47 - mx[px+"health_status_up"] = boolToInt(member.Health == 1)
48 - mx[px+"health_status_down"] = boolToInt(member.Health == 0)
48 + mx[px+"health_status_up"] = metrix.Bool(member.Health == 1)
49 + mx[px+"health_status_down"] = metrix.Bool(member.Health == 0)
50
51 if member.Self == nil {
52 mx[px+"uptime"] = member.Uptime
src/go/plugin/go.d/modules/mysql/collect_global_status.go
+11 -16
@@ -4,6 +4,8 @@ package mysql
4
5 import (
6 "strings"
7 +
8 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
9 )
10
11 const queryShowGlobalStatus = "SHOW GLOBAL STATUS;"
@@ -31,20 +33,20 @@ func (m *MySQL) collectGlobalStatus(mx map[string]int64) error {
33 case "wsrep_local_state":
34 // https://mariadb.com/kb/en/galera-cluster-status-variables/#wsrep_local_state
35 // https://github.com/codership/wsrep-API/blob/eab2d5d5a31672c0b7d116ef1629ff18392fd7d0/wsrep_api.h#L256
34 - mx[name+"_undefined"] = boolToInt(value == "0")
35 - mx[name+"_joiner"] = boolToInt(value == "1")
36 - mx[name+"_donor"] = boolToInt(value == "2")
37 - mx[name+"_joined"] = boolToInt(value == "3")
38 - mx[name+"_synced"] = boolToInt(value == "4")
39 - mx[name+"_error"] = boolToInt(parseInt(value) >= 5)
36 + mx[name+"_undefined"] = metrix.Bool(value == "0")
37 + mx[name+"_joiner"] = metrix.Bool(value == "1")
38 + mx[name+"_donor"] = metrix.Bool(value == "2")
39 + mx[name+"_joined"] = metrix.Bool(value == "3")
40 + mx[name+"_synced"] = metrix.Bool(value == "4")
41 + mx[name+"_error"] = metrix.Bool(parseInt(value) >= 5)
42 case "wsrep_cluster_status":
43 // https://www.percona.com/doc/percona-xtradb-cluster/LATEST/wsrep-status-index.html#wsrep_cluster_status
44 // https://github.com/codership/wsrep-API/blob/eab2d5d5a31672c0b7d116ef1629ff18392fd7d0/wsrep_api.h
45 // https://github.com/codership/wsrep-API/blob/f71cd270414ee70dde839cfc59c1731eea4230ea/examples/node/wsrep.c#L80
46 value = strings.ToUpper(value)
45 - mx[name+"_primary"] = boolToInt(value == "PRIMARY")
46 - mx[name+"_non_primary"] = boolToInt(value == "NON-PRIMARY")
47 - mx[name+"_disconnected"] = boolToInt(value == "DISCONNECTED")
47 + mx[name+"_primary"] = metrix.Bool(value == "PRIMARY")
48 + mx[name+"_non_primary"] = metrix.Bool(value == "NON-PRIMARY")
49 + mx[name+"_disconnected"] = metrix.Bool(value == "DISCONNECTED")
50 default:
51 mx[strings.ToLower(name)] = parseInt(value)
52 }
@@ -77,13 +79,6 @@ func convertWsrepReady(val string) string {
79 }
80 }
81
80 -func boolToInt(v bool) int64 {
81 - if v {
82 - return 1
83 - }
84 - return 0
85 -}
86 -
82 var globalStatusKeys = map[string]bool{
83 "Bytes_received": true,
84 "Bytes_sent": true,
src/go/plugin/go.d/modules/nginxplus/collect.go
+11 -20
@@ -6,6 +6,8 @@ import (
6 "errors"
7 "fmt"
8 "time"
9 +
10 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
11 )
12
13 func (n *NginxPlus) collect() (map[string]int64, error) {
@@ -98,8 +100,8 @@ func (n *NginxPlus) collectHTTPCache(mx map[string]int64, ms *nginxMetrics) {
100 for name, cache := range *ms.httpCaches {
101 n.cache.putHTTPCache(name)
102 px := fmt.Sprintf("http_cache_%s_", name)
101 - mx[px+"state_cold"] = boolToInt(cache.Cold)
102 - mx[px+"state_warm"] = boolToInt(!cache.Cold)
103 + mx[px+"state_cold"] = metrix.Bool(cache.Cold)
104 + mx[px+"state_warm"] = metrix.Bool(!cache.Cold)
105 mx[px+"size"] = cache.Size
106 mx[px+"served_responses"] = cache.Hit.Responses + cache.Stale.Responses + cache.Updating.Responses + cache.Revalidated.Responses
107 mx[px+"written_responses"] = cache.Miss.ResponsesWritten + cache.Expired.ResponsesWritten + cache.Bypass.ResponsesWritten
@@ -170,12 +172,9 @@ func (n *NginxPlus) collectHTTPUpstreams(mx map[string]int64, ms *nginxMetrics)
172
173 px = fmt.Sprintf("http_upstream_%s_server_%s_zone_%s_", name, peer.Server, upstream.Zone)
174 mx[px+"active"] = peer.Active
173 - mx[px+"state_up"] = boolToInt(peer.State == "up")
174 - mx[px+"state_down"] = boolToInt(peer.State == "down")
175 - mx[px+"state_draining"] = boolToInt(peer.State == "draining")
176 - mx[px+"state_unavail"] = boolToInt(peer.State == "unavail")
177 - mx[px+"state_checking"] = boolToInt(peer.State == "checking")
178 - mx[px+"state_unhealthy"] = boolToInt(peer.State == "unhealthy")
175 + for _, v := range []string{"up", "down", "draining", "unavail", "checking", "unhealthy"} {
176 + mx[px+"state_"+v] = metrix.Bool(peer.State == v)
177 + }
178 mx[px+"bytes_received"] = peer.Received
179 mx[px+"bytes_sent"] = peer.Sent
180 mx[px+"requests"] = peer.Requests
@@ -227,13 +226,12 @@ func (n *NginxPlus) collectStreamUpstreams(mx map[string]int64, ms *nginxMetrics
226 n.cache.putStreamUpstreamServer(name, peer.Server, peer.Name, upstream.Zone)
227
228 px = fmt.Sprintf("stream_upstream_%s_server_%s_zone_%s_", name, peer.Server, upstream.Zone)
229 +
230 mx[px+"active"] = peer.Active
231 mx[px+"connections"] = peer.Connections
232 - mx[px+"state_up"] = boolToInt(peer.State == "up")
233 - mx[px+"state_down"] = boolToInt(peer.State == "down")
234 - mx[px+"state_unavail"] = boolToInt(peer.State == "unavail")
235 - mx[px+"state_checking"] = boolToInt(peer.State == "checking")
236 - mx[px+"state_unhealthy"] = boolToInt(peer.State == "unhealthy")
232 + for _, v := range []string{"up", "down", "unavail", "checking", "unhealthy"} {
233 + mx[px+"state_"+v] = metrix.Bool(peer.State == v)
234 + }
235 mx[px+"bytes_received"] = peer.Received
236 mx[px+"bytes_sent"] = peer.Sent
237 mx[px+"downtime"] = peer.Downtime / 1000
@@ -384,10 +382,3 @@ func (n *NginxPlus) updateCharts() {
382 }
383 }
384 }
387 -
388 -func boolToInt(v bool) int64 {
389 - if v {
390 - return 1
391 - }
392 - return 0
393 -}
src/go/plugin/go.d/modules/nvidia_smi/collect.go
+5 -10
@@ -8,6 +8,8 @@ import (
8 "fmt"
9 "strconv"
10 "strings"
11 +
12 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
13 )
14
15 func (nv *NvidiaSmi) collect() (map[string]int64, error) {
@@ -83,12 +85,12 @@ func (nv *NvidiaSmi) collectGPUInfo(mx map[string]int64) error {
85 addMetric(mx, px+"voltage", gpu.Voltage.GraphicsVolt, 0)
86 for i := 0; i < 16; i++ {
87 s := "P" + strconv.Itoa(i)
86 - mx[px+"performance_state_"+s] = boolToInt(gpu.PerformanceState == s)
88 + mx[px+"performance_state_"+s] = metrix.Bool(gpu.PerformanceState == s)
89 }
90 if isValidValue(gpu.MIGMode.CurrentMIG) {
91 mode := strings.ToLower(gpu.MIGMode.CurrentMIG)
90 - mx[px+"mig_current_mode_enabled"] = boolToInt(mode == "enabled")
91 - mx[px+"mig_current_mode_disabled"] = boolToInt(mode == "disabled")
92 + mx[px+"mig_current_mode_enabled"] = metrix.Bool(mode == "enabled")
93 + mx[px+"mig_current_mode_disabled"] = metrix.Bool(mode == "disabled")
94 mx[px+"mig_devices_count"] = int64(len(gpu.MIGDevices.MIGDevice))
95 }
96
@@ -195,10 +197,3 @@ func removeUnits(s string) string {
197 }
198 return s
199 }
198 -
199 -func boolToInt(v bool) int64 {
200 - if v {
201 - return 1
202 - }
203 - return 0
204 -}
src/go/plugin/go.d/modules/nvme/collect.go
+8 -13
@@ -10,6 +10,8 @@ import (
10 "path/filepath"
11 "strconv"
12 "time"
13 +
14 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
15 )
16
17 func (n *NVMe) collect() (map[string]int64, error) {
@@ -67,12 +69,12 @@ func (n *NVMe) collectNVMeDevice(mx map[string]int64, devicePath string) error {
69 mx["device_"+dev+"_thm_temp1_total_time"] = parseValue(stats.ThmTemp1TotalTime) // seconds
70 mx["device_"+dev+"_thm_temp2_total_time"] = parseValue(stats.ThmTemp2TotalTime) // seconds
71
70 - mx["device_"+dev+"_critical_warning_available_spare"] = boolToInt(parseValue(stats.CriticalWarning)&1 != 0)
71 - mx["device_"+dev+"_critical_warning_temp_threshold"] = boolToInt(parseValue(stats.CriticalWarning)&(1<<1) != 0)
72 - mx["device_"+dev+"_critical_warning_nvm_subsystem_reliability"] = boolToInt(parseValue(stats.CriticalWarning)&(1<<2) != 0)
73 - mx["device_"+dev+"_critical_warning_read_only"] = boolToInt(parseValue(stats.CriticalWarning)&(1<<3) != 0)
74 - mx["device_"+dev+"_critical_warning_volatile_mem_backup_failed"] = boolToInt(parseValue(stats.CriticalWarning)&(1<<4) != 0)
75 - mx["device_"+dev+"_critical_warning_persistent_memory_read_only"] = boolToInt(parseValue(stats.CriticalWarning)&(1<<5) != 0)
72 + mx["device_"+dev+"_critical_warning_available_spare"] = metrix.Bool(parseValue(stats.CriticalWarning)&1 != 0)
73 + mx["device_"+dev+"_critical_warning_temp_threshold"] = metrix.Bool(parseValue(stats.CriticalWarning)&(1<<1) != 0)
74 + mx["device_"+dev+"_critical_warning_nvm_subsystem_reliability"] = metrix.Bool(parseValue(stats.CriticalWarning)&(1<<2) != 0)
75 + mx["device_"+dev+"_critical_warning_read_only"] = metrix.Bool(parseValue(stats.CriticalWarning)&(1<<3) != 0)
76 + mx["device_"+dev+"_critical_warning_volatile_mem_backup_failed"] = metrix.Bool(parseValue(stats.CriticalWarning)&(1<<4) != 0)
77 + mx["device_"+dev+"_critical_warning_persistent_memory_read_only"] = metrix.Bool(parseValue(stats.CriticalWarning)&(1<<5) != 0)
78
79 return nil
80 }
@@ -110,13 +112,6 @@ func extractDeviceFromPath(devicePath string) string {
112 return name
113 }
114
113 -func boolToInt(v bool) int64 {
114 - if v {
115 - return 1
116 - }
117 - return 0
118 -}
119 -
115 func parseValue(s nvmeNumber) int64 {
116 v, _ := strconv.ParseFloat(string(s), 64)
117 return int64(v)
src/go/plugin/go.d/modules/pihole/collect.go
+3 -9
@@ -13,6 +13,7 @@ import (
13 "sync"
14 "time"
15
16 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
17 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
18 )
19
@@ -72,8 +73,8 @@ func (p *Pihole) collectMetrics(mx map[string]int64, pmx *piholeMetrics) {
73 mx["queries_forwarded"] = pmx.summary.QueriesForwarded
74 mx["queries_cached"] = pmx.summary.QueriesCached
75 mx["unique_clients"] = pmx.summary.UniqueClients
75 - mx["blocking_status_enabled"] = boolToInt(pmx.summary.Status == "enabled")
76 - mx["blocking_status_disabled"] = boolToInt(pmx.summary.Status != "enabled")
76 + mx["blocking_status_enabled"] = metrix.Bool(pmx.summary.Status == "enabled")
77 + mx["blocking_status_disabled"] = metrix.Bool(pmx.summary.Status != "enabled")
78
79 tot := pmx.summary.QueriesCached + pmx.summary.AdsBlockedToday + pmx.summary.QueriesForwarded
80 mx["queries_cached_perc"] = calcPercentage(pmx.summary.QueriesCached, tot)
@@ -241,13 +242,6 @@ func isEmptyArray(data []byte) bool {
242 return len(data) == len(empty) && string(data) == empty
243 }
244
244 -func boolToInt(b bool) int64 {
245 - if !b {
246 - return 0
247 - }
248 - return 1
249 -}
250 -
245 func calcPercentage(value, total int64) (v int64) {
246 if total == 0 {
247 return 0
src/go/plugin/go.d/modules/postgres/metrics.go
+3 -3
@@ -2,7 +2,7 @@
2
3 package postgres
4
5 -import "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
5 +import "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
6
7 type pgMetrics struct {
8 srvMetrics
@@ -14,8 +14,8 @@ type pgMetrics struct {
14 }
15
16 type srvMetrics struct {
17 - xactTimeHist metrics.Histogram
18 - queryTimeHist metrics.Histogram
17 + xactTimeHist metrix.Histogram
18 + queryTimeHist metrix.Histogram
19
20 maxConnections int64
21 maxLocksHeld int64
src/go/plugin/go.d/modules/postgres/postgres.go
+3 -3
@@ -13,7 +13,7 @@ import (
13 "github.com/netdata/netdata/go/plugins/pkg/matcher"
14 "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
15 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
16 - "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
16 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
17
18 "github.com/jackc/pgx/v5/stdlib"
19 _ "github.com/jackc/pgx/v5/stdlib"
@@ -115,8 +115,8 @@ func (p *Postgres) Init() error {
115 }
116 p.dbSr = sr
117
118 - p.mx.xactTimeHist = metrics.NewHistogramWithRangeBuckets(p.XactTimeHistogram)
119 - p.mx.queryTimeHist = metrics.NewHistogramWithRangeBuckets(p.QueryTimeHistogram)
118 + p.mx.xactTimeHist = metrix.NewHistogramWithRangeBuckets(p.XactTimeHistogram)
119 + p.mx.queryTimeHist = metrix.NewHistogramWithRangeBuckets(p.QueryTimeHistogram)
120
121 return nil
122 }
src/go/plugin/go.d/modules/proxysql/collect.go
+6 -11
@@ -9,6 +9,8 @@ import (
9 "strconv"
10 "strings"
11 "time"
12 +
13 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
14 )
15
16 const (
@@ -161,10 +163,10 @@ func (p *ProxySQL) collectStatsMySQLConnectionPool(mx map[string]int64) error {
163 p.cache.getBackend(hg, host, port).updated = true
164 px = "backend_" + backendID(hg, host, port) + "_"
165 case "status":
164 - mx[px+"status_ONLINE"] = boolToInt(value == "1")
165 - mx[px+"status_SHUNNED"] = boolToInt(value == "2")
166 - mx[px+"status_OFFLINE_SOFT"] = boolToInt(value == "3")
167 - mx[px+"status_OFFLINE_HARD"] = boolToInt(value == "4")
166 + mx[px+"status_ONLINE"] = metrix.Bool(value == "1")
167 + mx[px+"status_SHUNNED"] = metrix.Bool(value == "2")
168 + mx[px+"status_OFFLINE_SOFT"] = metrix.Bool(value == "3")
169 + mx[px+"status_OFFLINE_HARD"] = metrix.Bool(value == "4")
170 default:
171 mx[px+column] = parseInt(value)
172 }
@@ -294,13 +296,6 @@ func calcPercentage(value, total int64) (v int64) {
296 return v
297 }
298
297 -func boolToInt(v bool) int64 {
298 - if v {
299 - return 1
300 - }
301 - return 0
302 -}
303 -
299 func backendID(hg, host, port string) string {
300 hg = strings.ReplaceAll(strings.ToLower(hg), " ", "_")
301 host = strings.ReplaceAll(host, ".", "_")
src/go/plugin/go.d/modules/rabbitmq/collect.go
-7
@@ -89,10 +89,3 @@ func (r *RabbitMQ) webClient() *web.Client {
89 return false, nil
90 })
91 }
92 -
93 -func boolToInt(b bool) int64 {
94 - if b {
95 - return 1
96 - }
97 - return 0
98 -}
src/go/plugin/go.d/modules/rabbitmq/collect_nodes.go
+9 -8
@@ -4,6 +4,7 @@ package rabbitmq
4
5 import (
6 "fmt"
7 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
8
9 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
10 )
@@ -25,8 +26,8 @@ func (r *RabbitMQ) collectNodes(mx map[string]int64) error {
26
27 px := fmt.Sprintf("node_%s_", node.Name)
28
28 - mx[px+"avail_status_running"] = boolToInt(node.Running)
29 - mx[px+"avail_status_down"] = boolToInt(!node.Running)
29 + mx[px+"avail_status_running"] = metrix.Bool(node.Running)
30 + mx[px+"avail_status_down"] = metrix.Bool(!node.Running)
31
32 if node.OsPid == "" {
33 continue
@@ -35,13 +36,13 @@ func (r *RabbitMQ) collectNodes(mx map[string]int64) error {
36 for _, v := range []string{"clear", "detected"} {
37 mx[px+"network_partition_status_"+v] = 0
38 }
38 - mx[px+"network_partition_status_clear"] = boolToInt(len(node.Partitions) == 0)
39 - mx[px+"network_partition_status_detected"] = boolToInt(len(node.Partitions) > 0)
39 + mx[px+"network_partition_status_clear"] = metrix.Bool(len(node.Partitions) == 0)
40 + mx[px+"network_partition_status_detected"] = metrix.Bool(len(node.Partitions) > 0)
41
41 - mx[px+"mem_alarm_status_clear"] = boolToInt(!node.MemAlarm)
42 - mx[px+"mem_alarm_status_triggered"] = boolToInt(node.MemAlarm)
43 - mx[px+"disk_free_alarm_status_clear"] = boolToInt(!node.DiskFreeAlarm)
44 - mx[px+"disk_free_alarm_status_triggered"] = boolToInt(node.DiskFreeAlarm)
42 + mx[px+"mem_alarm_status_clear"] = metrix.Bool(!node.MemAlarm)
43 + mx[px+"mem_alarm_status_triggered"] = metrix.Bool(node.MemAlarm)
44 + mx[px+"disk_free_alarm_status_clear"] = metrix.Bool(!node.DiskFreeAlarm)
45 + mx[px+"disk_free_alarm_status_triggered"] = metrix.Bool(node.DiskFreeAlarm)
46
47 mx[px+"fds_available"] = node.FDTotal - node.FDUsed
48 mx[px+"fds_used"] = node.FDUsed
src/go/plugin/go.d/modules/rabbitmq/collect_queues.go
+4 -4
@@ -5,6 +5,7 @@ package rabbitmq
5 import (
6 "fmt"
7
8 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
9 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/stm"
10 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11 )
@@ -31,14 +32,13 @@ func (r *RabbitMQ) collectQueues(mx map[string]int64) error {
32 }
33
34 // https://github.com/rabbitmq/rabbitmq-server/blob/8b554474a65857aa60b72b2dda4b6fa9b78f349b/deps/rabbitmq_management/priv/www/js/formatters.js#L552
34 - s := q.State
35 + st := q.State
36 if q.IdleSince != nil {
36 - s = "idle"
37 + st = "idle"
38 }
39 for _, v := range []string{"running", "idle", "terminated", "down", "crashed", "stopped", "minority"} {
39 - mx[px+"status_"+v] = 0
40 + mx[px+"status_"+v] = metrix.Bool(v == st)
41 }
41 - mx[px+"status_"+s] = 1
42 }
43
44 return nil
src/go/plugin/go.d/modules/rabbitmq/collect_vhosts.go
+3 -2
@@ -5,6 +5,7 @@ package rabbitmq
5 import (
6 "fmt"
7
8 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
9 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/stm"
10 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
11 )
@@ -30,10 +31,10 @@ func (r *RabbitMQ) collectVhosts(mx map[string]int64) error {
31 mx[px+k] = v
32 }
33
34 + st := getVhostStatus(vhost)
35 for _, v := range []string{"running", "stopped", "partial"} {
34 - mx[px+"status_"+v] = 0
36 + mx[px+"status_"+v] = metrix.Bool(v == st)
37 }
36 - mx[px+"status_"+getVhostStatus(vhost)] = 1
38 }
39
40 return nil
src/go/plugin/go.d/modules/redis/collect_info.go
+3 -9
@@ -10,6 +10,7 @@ import (
10 "time"
11
12 "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
13 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
14 )
15
16 const (
@@ -81,8 +82,8 @@ func (r *Redis) collectInfo(mx map[string]int64, info string) {
82 case field == "aof_enabled" && value == "1":
83 r.addAOFChartsOnce.Do(r.addAOFCharts)
84 case field == "master_link_status":
84 - mx["master_link_status_up"] = boolToInt(value == "up")
85 - mx["master_link_status_down"] = boolToInt(value == "down")
85 + mx["master_link_status_up"] = metrix.Bool(value == "up")
86 + mx["master_link_status_down"] = metrix.Bool(value == "down")
87 default:
88 collectNumericValue(mx, field, value)
89 }
@@ -249,10 +250,3 @@ func has(m map[string]int64, key string, keys ...string) bool {
250 return ok && has(m, keys[0], keys[1:]...)
251 }
252 }
252 -
253 -func boolToInt(v bool) int64 {
254 - if v {
255 - return 1
256 - }
257 - return 0
258 -}
src/go/plugin/go.d/modules/redis/redis.go
+3 -3
@@ -12,7 +12,7 @@ import (
12
13 "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
14 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
15 - "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
15 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
16 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/tlscfg"
17
18 "github.com/blang/semver/v4"
@@ -40,7 +40,7 @@ func New() *Redis {
40
41 addAOFChartsOnce: &sync.Once{},
42 addReplSlaveChartsOnce: &sync.Once{},
43 - pingSummary: metrics.NewSummary(),
43 + pingSummary: metrix.NewSummary(),
44 collectedCommands: make(map[string]bool),
45 collectedDbs: make(map[string]bool),
46 }
@@ -69,7 +69,7 @@ type (
69
70 server string
71 version *semver.Version
72 - pingSummary metrics.Summary
72 + pingSummary metrix.Summary
73 collectedCommands map[string]bool
74 collectedDbs map[string]bool
75 }
src/go/plugin/go.d/modules/sensors/collect.go
+3 -9
@@ -9,6 +9,7 @@ import (
9 "fmt"
10
11 "github.com/netdata/netdata/go/plugins/plugin/go.d/modules/sensors/lmsensors"
12 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
13 )
14
15 const precision = 1000
@@ -167,18 +168,11 @@ func writeMetric(mx map[string]int64, key string, value *float64) {
168
169 func writeMetricAlarm(mx map[string]int64, px string, value *bool) {
170 if value != nil {
170 - mx[px+"alarm_clear"] = boolToInt(!*value)
171 - mx[px+"alarm_triggered"] = boolToInt(*value)
171 + mx[px+"alarm_clear"] = metrix.Bool(!*value)
172 + mx[px+"alarm_triggered"] = metrix.Bool(*value)
173 }
174 }
175
176 func sensorPrefix(chip, sensor string) string {
177 return fmt.Sprintf("chip_%s_sensor_%s_", chip, sensor)
178 }
178 -
179 -func boolToInt(b bool) int64 {
180 - if b {
181 - return 1
182 - }
183 - return 0
184 -}
src/go/plugin/go.d/modules/squidlog/metrics.go
+43 -43
@@ -2,14 +2,14 @@
2
3 package squidlog
4
5 -import "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
5 +import "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
6
7 -func newSummary() metrics.Summary {
8 - return &summary{metrics.NewSummary()}
7 +func newSummary() metrix.Summary {
8 + return &summary{metrix.NewSummary()}
9 }
10
11 type summary struct {
12 - metrics.Summary
12 + metrix.Summary
13 }
14
15 func (s summary) WriteTo(rv map[string]int64, key string, mul, div int) {
@@ -36,37 +36,37 @@ const (
36 )
37
38 type metricsData struct {
39 - Requests metrics.Counter `stm:"requests"`
40 - Unmatched metrics.Counter `stm:"unmatched"`
39 + Requests metrix.Counter `stm:"requests"`
40 + Unmatched metrix.Counter `stm:"unmatched"`
41
42 - HTTPRespCode metrics.CounterVec `stm:"http_resp_code"`
43 - HTTPResp0xx metrics.Counter `stm:"http_resp_0xx"`
44 - HTTPResp1xx metrics.Counter `stm:"http_resp_1xx"`
45 - HTTPResp2xx metrics.Counter `stm:"http_resp_2xx"`
46 - HTTPResp3xx metrics.Counter `stm:"http_resp_3xx"`
47 - HTTPResp4xx metrics.Counter `stm:"http_resp_4xx"`
48 - HTTPResp5xx metrics.Counter `stm:"http_resp_5xx"`
49 - HTTPResp6xx metrics.Counter `stm:"http_resp_6xx"`
42 + HTTPRespCode metrix.CounterVec `stm:"http_resp_code"`
43 + HTTPResp0xx metrix.Counter `stm:"http_resp_0xx"`
44 + HTTPResp1xx metrix.Counter `stm:"http_resp_1xx"`
45 + HTTPResp2xx metrix.Counter `stm:"http_resp_2xx"`
46 + HTTPResp3xx metrix.Counter `stm:"http_resp_3xx"`
47 + HTTPResp4xx metrix.Counter `stm:"http_resp_4xx"`
48 + HTTPResp5xx metrix.Counter `stm:"http_resp_5xx"`
49 + HTTPResp6xx metrix.Counter `stm:"http_resp_6xx"`
50
51 - ReqSuccess metrics.Counter `stm:"req_type_success"`
52 - ReqRedirect metrics.Counter `stm:"req_type_redirect"`
53 - ReqBad metrics.Counter `stm:"req_type_bad"`
54 - ReqError metrics.Counter `stm:"req_type_error"`
51 + ReqSuccess metrix.Counter `stm:"req_type_success"`
52 + ReqRedirect metrix.Counter `stm:"req_type_redirect"`
53 + ReqBad metrix.Counter `stm:"req_type_bad"`
54 + ReqError metrix.Counter `stm:"req_type_error"`
55
56 - BytesSent metrics.Counter `stm:"bytes_sent"`
57 - RespTime metrics.Summary `stm:"resp_time,1000,1"`
58 - UniqueClients metrics.UniqueCounter `stm:"uniq_clients"`
56 + BytesSent metrix.Counter `stm:"bytes_sent"`
57 + RespTime metrix.Summary `stm:"resp_time,1000,1"`
58 + UniqueClients metrix.UniqueCounter `stm:"uniq_clients"`
59
60 - ReqMethod metrics.CounterVec `stm:"req_method"`
61 - CacheCode metrics.CounterVec `stm:"cache_result_code"`
62 - CacheCodeTransportTag metrics.CounterVec `stm:"cache_transport_tag"`
63 - CacheCodeHandlingTag metrics.CounterVec `stm:"cache_handling_tag"`
64 - CacheCodeObjectTag metrics.CounterVec `stm:"cache_object_tag"`
65 - CacheCodeLoadSourceTag metrics.CounterVec `stm:"cache_load_source_tag"`
66 - CacheCodeErrorTag metrics.CounterVec `stm:"cache_error_tag"`
67 - HierCode metrics.CounterVec `stm:"hier_code"`
68 - MimeType metrics.CounterVec `stm:"mime_type"`
69 - Server metrics.CounterVec `stm:"server_address"`
60 + ReqMethod metrix.CounterVec `stm:"req_method"`
61 + CacheCode metrix.CounterVec `stm:"cache_result_code"`
62 + CacheCodeTransportTag metrix.CounterVec `stm:"cache_transport_tag"`
63 + CacheCodeHandlingTag metrix.CounterVec `stm:"cache_handling_tag"`
64 + CacheCodeObjectTag metrix.CounterVec `stm:"cache_object_tag"`
65 + CacheCodeLoadSourceTag metrix.CounterVec `stm:"cache_load_source_tag"`
66 + CacheCodeErrorTag metrix.CounterVec `stm:"cache_error_tag"`
67 + HierCode metrix.CounterVec `stm:"hier_code"`
68 + MimeType metrix.CounterVec `stm:"mime_type"`
69 + Server metrix.CounterVec `stm:"server_address"`
70 }
71
72 func (m *metricsData) reset() {
@@ -77,17 +77,17 @@ func (m *metricsData) reset() {
77 func newMetricsData() *metricsData {
78 return &metricsData{
79 RespTime: newSummary(),
80 - UniqueClients: metrics.NewUniqueCounter(true),
81 - HTTPRespCode: metrics.NewCounterVec(),
82 - ReqMethod: metrics.NewCounterVec(),
83 - CacheCode: metrics.NewCounterVec(),
84 - CacheCodeTransportTag: metrics.NewCounterVec(),
85 - CacheCodeHandlingTag: metrics.NewCounterVec(),
86 - CacheCodeObjectTag: metrics.NewCounterVec(),
87 - CacheCodeLoadSourceTag: metrics.NewCounterVec(),
88 - CacheCodeErrorTag: metrics.NewCounterVec(),
89 - HierCode: metrics.NewCounterVec(),
90 - Server: metrics.NewCounterVec(),
91 - MimeType: metrics.NewCounterVec(),
80 + UniqueClients: metrix.NewUniqueCounter(true),
81 + HTTPRespCode: metrix.NewCounterVec(),
82 + ReqMethod: metrix.NewCounterVec(),
83 + CacheCode: metrix.NewCounterVec(),
84 + CacheCodeTransportTag: metrix.NewCounterVec(),
85 + CacheCodeHandlingTag: metrix.NewCounterVec(),
86 + CacheCodeObjectTag: metrix.NewCounterVec(),
87 + CacheCodeLoadSourceTag: metrix.NewCounterVec(),
88 + CacheCodeErrorTag: metrix.NewCounterVec(),
89 + HierCode: metrix.NewCounterVec(),
90 + Server: metrix.NewCounterVec(),
91 + MimeType: metrix.NewCounterVec(),
92 }
93 }
src/go/plugin/go.d/modules/squidlog/squidlog_test.go
+2 -3
@@ -9,8 +9,7 @@ import (
9
10 "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/logs"
12 - "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
13 -
12 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
13 "github.com/stretchr/testify/assert"
14 "github.com/stretchr/testify/require"
15 )
@@ -266,7 +265,7 @@ func ensureChartsDynamicDimsCreated(t *testing.T, squid *SquidLog) {
265 ensureDynamicDimsCreated(t, squid, mimeTypeChart.ID, pxMimeType, squid.mx.MimeType)
266 }
267
269 -func ensureDynamicDimsCreated(t *testing.T, squid *SquidLog, chartID, dimPrefix string, data metrics.CounterVec) {
268 +func ensureDynamicDimsCreated(t *testing.T, squid *SquidLog, chartID, dimPrefix string, data metrix.CounterVec) {
269 chart := squid.Charts().Get(chartID)
270 assert.NotNilf(t, chart, "chart '%s' is not created", chartID)
271 if chart == nil {
src/go/plugin/go.d/modules/uwsgi/collect.go
+5 -10
@@ -5,6 +5,8 @@ package uwsgi
5 import (
6 "encoding/json"
7 "fmt"
8 +
9 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
10 )
11
12 type statsResponse struct {
@@ -87,10 +89,10 @@ func (u *Uwsgi) collectStats(mx map[string]int64, stats []byte) error {
89 mx[px+"memory_vsz"] = w.VSZ
90
91 for _, v := range []string{"idle", "busy", "cheap", "pause", "sig"} {
90 - mx[px+"status_"+v] = boolToInt(w.Status == v)
92 + mx[px+"status_"+v] = metrix.Bool(w.Status == v)
93 }
92 - mx[px+"request_handling_status_accepting"] = boolToInt(w.Accepting == 1)
93 - mx[px+"request_handling_status_not_accepting"] = boolToInt(w.Accepting == 0)
94 + mx[px+"request_handling_status_accepting"] = metrix.Bool(w.Accepting == 1)
95 + mx[px+"request_handling_status_not_accepting"] = metrix.Bool(w.Accepting == 0)
96 }
97
98 for id := range u.seenWorkers {
@@ -102,10 +104,3 @@ func (u *Uwsgi) collectStats(mx map[string]int64, stats []byte) error {
104
105 return nil
106 }
105 -
106 -func boolToInt(b bool) int64 {
107 - if b {
108 - return 1
109 - }
110 - return 0
111 -}
src/go/plugin/go.d/modules/vcsa/collect.go
+4 -9
@@ -4,6 +4,8 @@ package vcsa
4
5 import (
6 "sync"
7 +
8 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
9 )
10
11 var componentHealthStatuses = []string{"green", "red", "yellow", "orange", "gray"}
@@ -81,15 +83,8 @@ func writeStatus(mx map[string]int64, key string, statuses []string, status *str
83
84 var found bool
85 for _, s := range statuses {
84 - mx[key+"_status_"+s] = boolToInt(s == *status)
86 + mx[key+"_status_"+s] = metrix.Bool(s == *status)
87 found = found || s == *status
88 }
87 - mx[key+"_status_unknown"] = boolToInt(!found)
88 -}
89 -
90 -func boolToInt(v bool) int64 {
91 - if v {
92 - return 1
93 - }
94 - return 0
89 + mx[key+"_status_unknown"] = metrix.Bool(!found)
90 }
src/go/plugin/go.d/modules/vsphere/collect.go
+3 -9
@@ -8,6 +8,7 @@ import (
8 "time"
9
10 rs "github.com/netdata/netdata/go/plugins/plugin/go.d/modules/vsphere/resources"
11 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
12
13 "github.com/vmware/govmomi/performance"
14 )
@@ -78,7 +79,7 @@ func writeHostMetrics(mx map[string]int64, host *rs.Host, metrics []performance.
79 }
80 for _, v := range overallStatuses {
81 key := fmt.Sprintf("%s_overall.status.%s", host.ID, v)
81 - mx[key] = boolToInt(host.OverallStatus == v)
82 + mx[key] = metrix.Bool(host.OverallStatus == v)
83 }
84 }
85
@@ -120,13 +121,6 @@ func writeVMMetrics(mx map[string]int64, vm *rs.VM, metrics []performance.Metric
121 }
122 for _, v := range overallStatuses {
123 key := fmt.Sprintf("%s_overall.status.%s", vm.ID, v)
123 - mx[key] = boolToInt(vm.OverallStatus == v)
124 + mx[key] = metrix.Bool(vm.OverallStatus == v)
125 }
126 }
126 -
127 -func boolToInt(v bool) int64 {
128 - if v {
129 - return 1
130 - }
131 - return 0
132 -}
src/go/plugin/go.d/modules/weblog/metrics.go
+68 -68
@@ -3,15 +3,15 @@
3 package weblog
4
5 import (
6 - "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
6 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
7 )
8
9 -func newWebLogSummary() metrics.Summary {
10 - return &weblogSummary{metrics.NewSummary()}
9 +func newWebLogSummary() metrix.Summary {
10 + return &weblogSummary{metrix.NewSummary()}
11 }
12
13 type weblogSummary struct {
14 - metrics.Summary
14 + metrix.Summary
15 }
16
17 // WriteTo redefines metrics.Summary.WriteTo
@@ -27,82 +27,82 @@ func (s weblogSummary) WriteTo(rv map[string]int64, key string, mul, div int) {
27
28 type (
29 metricsData struct {
30 - Requests metrics.Counter `stm:"requests"`
31 - ReqUnmatched metrics.Counter `stm:"req_unmatched"`
32 -
33 - RespCode metrics.CounterVec `stm:"resp_code"`
34 - Resp1xx metrics.Counter `stm:"resp_1xx"`
35 - Resp2xx metrics.Counter `stm:"resp_2xx"`
36 - Resp3xx metrics.Counter `stm:"resp_3xx"`
37 - Resp4xx metrics.Counter `stm:"resp_4xx"`
38 - Resp5xx metrics.Counter `stm:"resp_5xx"`
39 -
40 - ReqSuccess metrics.Counter `stm:"req_type_success"`
41 - ReqRedirect metrics.Counter `stm:"req_type_redirect"`
42 - ReqBad metrics.Counter `stm:"req_type_bad"`
43 - ReqError metrics.Counter `stm:"req_type_error"`
44 -
45 - UniqueIPv4 metrics.UniqueCounter `stm:"uniq_ipv4"`
46 - UniqueIPv6 metrics.UniqueCounter `stm:"uniq_ipv6"`
47 - BytesSent metrics.Counter `stm:"bytes_sent"`
48 - BytesReceived metrics.Counter `stm:"bytes_received"`
49 - ReqProcTime metrics.Summary `stm:"req_proc_time"`
50 - ReqProcTimeHist metrics.Histogram `stm:"req_proc_time_hist"`
51 - UpsRespTime metrics.Summary `stm:"upstream_resp_time"`
52 - UpsRespTimeHist metrics.Histogram `stm:"upstream_resp_time_hist"`
53 -
54 - ReqVhost metrics.CounterVec `stm:"req_vhost"`
55 - ReqPort metrics.CounterVec `stm:"req_port"`
56 - ReqMethod metrics.CounterVec `stm:"req_method"`
57 - ReqURLPattern metrics.CounterVec `stm:"req_url_ptn"`
58 - ReqVersion metrics.CounterVec `stm:"req_version"`
59 - ReqSSLProto metrics.CounterVec `stm:"req_ssl_proto"`
60 - ReqSSLCipherSuite metrics.CounterVec `stm:"req_ssl_cipher_suite"`
61 - ReqHTTPScheme metrics.Counter `stm:"req_http_scheme"`
62 - ReqHTTPSScheme metrics.Counter `stm:"req_https_scheme"`
63 - ReqIPv4 metrics.Counter `stm:"req_ipv4"`
64 - ReqIPv6 metrics.Counter `stm:"req_ipv6"`
65 -
66 - ReqCustomField map[string]metrics.CounterVec `stm:"custom_field"`
67 - URLPatternStats map[string]*patternMetrics `stm:"url_ptn"`
30 + Requests metrix.Counter `stm:"requests"`
31 + ReqUnmatched metrix.Counter `stm:"req_unmatched"`
32 +
33 + RespCode metrix.CounterVec `stm:"resp_code"`
34 + Resp1xx metrix.Counter `stm:"resp_1xx"`
35 + Resp2xx metrix.Counter `stm:"resp_2xx"`
36 + Resp3xx metrix.Counter `stm:"resp_3xx"`
37 + Resp4xx metrix.Counter `stm:"resp_4xx"`
38 + Resp5xx metrix.Counter `stm:"resp_5xx"`
39 +
40 + ReqSuccess metrix.Counter `stm:"req_type_success"`
41 + ReqRedirect metrix.Counter `stm:"req_type_redirect"`
42 + ReqBad metrix.Counter `stm:"req_type_bad"`
43 + ReqError metrix.Counter `stm:"req_type_error"`
44 +
45 + UniqueIPv4 metrix.UniqueCounter `stm:"uniq_ipv4"`
46 + UniqueIPv6 metrix.UniqueCounter `stm:"uniq_ipv6"`
47 + BytesSent metrix.Counter `stm:"bytes_sent"`
48 + BytesReceived metrix.Counter `stm:"bytes_received"`
49 + ReqProcTime metrix.Summary `stm:"req_proc_time"`
50 + ReqProcTimeHist metrix.Histogram `stm:"req_proc_time_hist"`
51 + UpsRespTime metrix.Summary `stm:"upstream_resp_time"`
52 + UpsRespTimeHist metrix.Histogram `stm:"upstream_resp_time_hist"`
53 +
54 + ReqVhost metrix.CounterVec `stm:"req_vhost"`
55 + ReqPort metrix.CounterVec `stm:"req_port"`
56 + ReqMethod metrix.CounterVec `stm:"req_method"`
57 + ReqURLPattern metrix.CounterVec `stm:"req_url_ptn"`
58 + ReqVersion metrix.CounterVec `stm:"req_version"`
59 + ReqSSLProto metrix.CounterVec `stm:"req_ssl_proto"`
60 + ReqSSLCipherSuite metrix.CounterVec `stm:"req_ssl_cipher_suite"`
61 + ReqHTTPScheme metrix.Counter `stm:"req_http_scheme"`
62 + ReqHTTPSScheme metrix.Counter `stm:"req_https_scheme"`
63 + ReqIPv4 metrix.Counter `stm:"req_ipv4"`
64 + ReqIPv6 metrix.Counter `stm:"req_ipv6"`
65 +
66 + ReqCustomField map[string]metrix.CounterVec `stm:"custom_field"`
67 + URLPatternStats map[string]*patternMetrics `stm:"url_ptn"`
68
69 ReqCustomTimeField map[string]*customTimeFieldMetrics `stm:"custom_time_field"`
70 ReqCustomNumericField map[string]*customNumericFieldMetrics `stm:"custom_numeric_field"`
71 }
72 customTimeFieldMetrics struct {
73 - Time metrics.Summary `stm:"time"`
74 - TimeHist metrics.Histogram `stm:"time_hist"`
73 + Time metrix.Summary `stm:"time"`
74 + TimeHist metrix.Histogram `stm:"time_hist"`
75 }
76 customNumericFieldMetrics struct {
77 - Summary metrics.Summary `stm:"summary"`
77 + Summary metrix.Summary `stm:"summary"`
78
79 multiplier int
80 divisor int
81 }
82 patternMetrics struct {
83 - RespCode metrics.CounterVec `stm:"resp_code"`
84 - ReqMethod metrics.CounterVec `stm:"req_method"`
85 - BytesSent metrics.Counter `stm:"bytes_sent"`
86 - BytesReceived metrics.Counter `stm:"bytes_received"`
87 - ReqProcTime metrics.Summary `stm:"req_proc_time"`
83 + RespCode metrix.CounterVec `stm:"resp_code"`
84 + ReqMethod metrix.CounterVec `stm:"req_method"`
85 + BytesSent metrix.Counter `stm:"bytes_sent"`
86 + BytesReceived metrix.Counter `stm:"bytes_received"`
87 + ReqProcTime metrix.Summary `stm:"req_proc_time"`
88 }
89 )
90
91 func newMetricsData(config Config) *metricsData {
92 return &metricsData{
93 - ReqVhost: metrics.NewCounterVec(),
94 - ReqPort: metrics.NewCounterVec(),
95 - ReqMethod: metrics.NewCounterVec(),
96 - ReqVersion: metrics.NewCounterVec(),
97 - RespCode: metrics.NewCounterVec(),
98 - ReqSSLProto: metrics.NewCounterVec(),
99 - ReqSSLCipherSuite: metrics.NewCounterVec(),
93 + ReqVhost: metrix.NewCounterVec(),
94 + ReqPort: metrix.NewCounterVec(),
95 + ReqMethod: metrix.NewCounterVec(),
96 + ReqVersion: metrix.NewCounterVec(),
97 + RespCode: metrix.NewCounterVec(),
98 + ReqSSLProto: metrix.NewCounterVec(),
99 + ReqSSLCipherSuite: metrix.NewCounterVec(),
100 ReqProcTime: newWebLogSummary(),
101 - ReqProcTimeHist: metrics.NewHistogram(convHistOptionsToMicroseconds(config.Histogram)),
101 + ReqProcTimeHist: metrix.NewHistogram(convHistOptionsToMicroseconds(config.Histogram)),
102 UpsRespTime: newWebLogSummary(),
103 - UpsRespTimeHist: metrics.NewHistogram(convHistOptionsToMicroseconds(config.Histogram)),
104 - UniqueIPv4: metrics.NewUniqueCounter(true),
105 - UniqueIPv6: metrics.NewUniqueCounter(true),
103 + UpsRespTimeHist: metrix.NewHistogram(convHistOptionsToMicroseconds(config.Histogram)),
104 + UniqueIPv4: metrix.NewUniqueCounter(true),
105 + UniqueIPv6: metrix.NewUniqueCounter(true),
106 ReqURLPattern: newCounterVecFromPatterns(config.URLPatterns),
107 ReqCustomField: newReqCustomField(config.CustomFields),
108 URLPatternStats: newURLPatternStats(config.URLPatterns),
@@ -127,8 +127,8 @@ func (m *metricsData) reset() {
127 }
128 }
129
130 -func newCounterVecFromPatterns(patterns []userPattern) metrics.CounterVec {
131 - c := metrics.NewCounterVec()
130 +func newCounterVecFromPatterns(patterns []userPattern) metrix.CounterVec {
131 + c := metrix.NewCounterVec()
132 for _, p := range patterns {
133 _, _ = c.GetP(p.Name)
134 }
@@ -139,16 +139,16 @@ func newURLPatternStats(patterns []userPattern) map[string]*patternMetrics {
139 stats := make(map[string]*patternMetrics)
140 for _, p := range patterns {
141 stats[p.Name] = &patternMetrics{
142 - RespCode: metrics.NewCounterVec(),
143 - ReqMethod: metrics.NewCounterVec(),
142 + RespCode: metrix.NewCounterVec(),
143 + ReqMethod: metrix.NewCounterVec(),
144 ReqProcTime: newWebLogSummary(),
145 }
146 }
147 return stats
148 }
149
150 -func newReqCustomField(fields []customField) map[string]metrics.CounterVec {
151 - cf := make(map[string]metrics.CounterVec)
150 +func newReqCustomField(fields []customField) map[string]metrix.CounterVec {
151 + cf := make(map[string]metrix.CounterVec)
152 for _, f := range fields {
153 cf[f.Name] = newCounterVecFromPatterns(f.Patterns)
154 }
@@ -160,7 +160,7 @@ func newReqCustomTimeField(fields []customTimeField) map[string]*customTimeField
160 for _, f := range fields {
161 cf[f.Name] = &customTimeFieldMetrics{
162 Time: newWebLogSummary(),
163 - TimeHist: metrics.NewHistogram(convHistOptionsToMicroseconds(f.Histogram)),
163 + TimeHist: metrix.NewHistogram(convHistOptionsToMicroseconds(f.Histogram)),
164 }
165 }
166 return cf
src/go/plugin/go.d/modules/weblog/weblog_test.go
+9 -9
@@ -13,7 +13,7 @@ import (
13
14 "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
15 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/logs"
16 - "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
16 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
17
18 "github.com/stretchr/testify/assert"
19 "github.com/stretchr/testify/require"
@@ -1104,13 +1104,13 @@ func testCustomNumericFieldCharts(t *testing.T, w *WebLog) {
1104
1105 var (
1106 emptySummary = newWebLogSummary()
1107 - emptyHistogram = metrics.NewHistogram(metrics.DefBuckets)
1107 + emptyHistogram = metrix.NewHistogram(metrix.DefBuckets)
1108 )
1109
1110 -func isEmptySummary(s metrics.Summary) bool { return reflect.DeepEqual(s, emptySummary) }
1111 -func isEmptyHistogram(h metrics.Histogram) bool { return reflect.DeepEqual(h, emptyHistogram) }
1110 +func isEmptySummary(s metrix.Summary) bool { return reflect.DeepEqual(s, emptySummary) }
1111 +func isEmptyHistogram(h metrix.Histogram) bool { return reflect.DeepEqual(h, emptyHistogram) }
1112
1113 -func isEmptyCounterVec(cv metrics.CounterVec) bool {
1113 +func isEmptyCounterVec(cv metrix.CounterVec) bool {
1114 for _, c := range cv {
1115 if c.Value() > 0 {
1116 return false
@@ -1179,10 +1179,10 @@ func prepareWebLogCollectFull(t *testing.T) *WebLog {
1179 CustomTimeFields: []customTimeField{
1180 {
1181 Name: "random_time_field",
1182 - Histogram: metrics.DefBuckets,
1182 + Histogram: metrix.DefBuckets,
1183 },
1184 },
1185 - Histogram: metrics.DefBuckets,
1185 + Histogram: metrix.DefBuckets,
1186 GroupRespCodes: true,
1187 }
1188 weblog := New()
@@ -1313,11 +1313,11 @@ func prepareWebLogCollectCustomTimeFields(t *testing.T) *WebLog {
1313 CustomTimeFields: []customTimeField{
1314 {
1315 Name: "time1",
1316 - Histogram: metrics.DefBuckets,
1316 + Histogram: metrix.DefBuckets,
1317 },
1318 {
1319 Name: "time2",
1320 - Histogram: metrics.DefBuckets,
1320 + Histogram: metrix.DefBuckets,
1321 },
1322 },
1323 Path: "testdata/custom_time_fields.log",
src/go/plugin/go.d/modules/windows/collect.go
-7
@@ -154,10 +154,3 @@ func hasKey(mx map[string]int64, key string, keys ...string) bool {
154 return ok && hasKey(mx, keys[0], keys[1:]...)
155 }
156 }
157 -
158 -func boolToInt(v bool) int64 {
159 - if v {
160 - return 1
161 - }
162 - return 0
163 -}
src/go/plugin/go.d/modules/windows/collect_exchange.go
+3 -2
@@ -5,6 +5,7 @@ package windows
5 import (
6 "strings"
7
8 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
9 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
10 )
11
@@ -143,8 +144,8 @@ func (w *Windows) collectExchangeAddWorkloadMetric(mx map[string]int64, pms prom
144 for _, pm := range pms.FindByName(metricExchangeWorkloadIsActive) {
145 if name := pm.Labels.Get("name"); name != "" {
146 seen[name] = true
146 - mx["exchange_workload_"+name+"_is_active"] += boolToInt(pm.Value == 1)
147 - mx["exchange_workload_"+name+"_is_paused"] += boolToInt(pm.Value == 0)
147 + mx["exchange_workload_"+name+"_is_active"] += metrix.Bool(pm.Value == 1)
148 + mx["exchange_workload_"+name+"_is_paused"] += metrix.Bool(pm.Value == 0)
149 }
150 }
151
src/go/plugin/go.d/pkg/metrix/counter.go renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -package metrics
3 +package metrix
4
5 import (
6 "errors"
src/go/plugin/go.d/pkg/metrix/counter_test.go renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -package metrics
3 +package metrix
4
5 import (
6 "testing"
src/go/plugin/go.d/pkg/metrix/gauge.go renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -package metrics
3 +package metrix
4
5 import (
6 "time"
src/go/plugin/go.d/pkg/metrix/gauge_test.go renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -package metrics
3 +package metrix
4
5 import (
6 "testing"
src/go/plugin/go.d/pkg/metrix/histogram.go renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -package metrics
3 +package metrix
4
5 import (
6 "fmt"
src/go/plugin/go.d/pkg/metrix/histogram_test.go renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -package metrics
3 +package metrix
4
5 import (
6 "testing"
src/go/plugin/go.d/pkg/metrix/metrics.go renamed
+8 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -package metrics
3 +package metrix
4
5 import "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/stm"
6
@@ -10,3 +10,10 @@ type Observer interface {
10 stm.Value
11 Observe(v float64)
12 }
13 +
14 +func Bool(b bool) int64 {
15 + if b {
16 + return 1
17 + }
18 + return 0
19 +}
src/go/plugin/go.d/pkg/metrix/summary.go renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -package metrics
3 +package metrix
4
5 import (
6 "math"
src/go/plugin/go.d/pkg/metrix/summary_test.go renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -package metrics
3 +package metrix
4
5 import (
6 "testing"
src/go/plugin/go.d/pkg/metrix/unique_counter.go renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -package metrics
3 +package metrix
4
5 import (
6 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/stm"
src/go/plugin/go.d/pkg/metrix/unique_counter_test.go renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -package metrics
3 +package metrix
4
5 import (
6 "fmt"
src/go/plugin/go.d/pkg/stm/stm_test.go
+8 -9
@@ -5,10 +5,9 @@ package stm_test
5 import (
6 "testing"
7
8 + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
9 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/stm"
10
10 - "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
11 -
11 "github.com/stretchr/testify/assert"
12 )
13
@@ -23,20 +22,20 @@ func TestToMap_empty(t *testing.T) {
22
23 func TestToMap_metrics(t *testing.T) {
24 s := struct {
26 - C metrics.Counter `stm:"c"`
27 - G metrics.Gauge `stm:"g,100"`
28 - H metrics.Histogram `stm:"h,100"`
29 - S metrics.Summary `stm:"s,200,2"`
25 + C metrix.Counter `stm:"c"`
26 + G metrix.Gauge `stm:"g,100"`
27 + H metrix.Histogram `stm:"h,100"`
28 + S metrix.Summary `stm:"s,200,2"`
29 }{}
30 s.C.Inc()
31 s.G.Set(3.14)
33 - s.H = metrics.NewHistogram([]float64{1, 5, 10})
32 + s.H = metrix.NewHistogram([]float64{1, 5, 10})
33
34 s.H.Observe(3.14)
35 s.H.Observe(6.28)
36 s.H.Observe(20)
37
39 - s.S = metrics.NewSummary()
38 + s.S = metrix.NewSummary()
39 s.S.Observe(3.14)
40 s.S.Observe(6.28)
41
@@ -328,7 +327,7 @@ func TestToMap_badTag(t *testing.T) {
327 func TestToMap_nilValue(t *testing.T) {
328 assert.Panics(t, func() {
329 s := struct {
331 - a metrics.CounterVec `stm:"a"`
330 + a metrix.CounterVec `stm:"a"`
331 }{nil}
332 stm.ToMap(s)
333 })