Skip to content

Commit a46cfa7

Browse files
authored
Merge branch 'main' into repo_sync
2 parents e0573a6 + 10f4161 commit a46cfa7

8 files changed

+53
-17
lines changed

prometheus/collectors/go_collector_go121_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func withAllMetrics() []string {
6363
"go_godebug_non_default_behavior_multipartmaxheaders_events_total",
6464
"go_godebug_non_default_behavior_multipartmaxparts_events_total",
6565
"go_godebug_non_default_behavior_multipathtcp_events_total",
66+
"go_godebug_non_default_behavior_netedns0_events_total",
6667
"go_godebug_non_default_behavior_panicnil_events_total",
6768
"go_godebug_non_default_behavior_randautoseed_events_total",
6869
"go_godebug_non_default_behavior_tarinsecurepath_events_total",
@@ -158,6 +159,7 @@ func withDebugMetrics() []string {
158159
"go_godebug_non_default_behavior_multipartmaxheaders_events_total",
159160
"go_godebug_non_default_behavior_multipartmaxparts_events_total",
160161
"go_godebug_non_default_behavior_multipathtcp_events_total",
162+
"go_godebug_non_default_behavior_netedns0_events_total",
161163
"go_godebug_non_default_behavior_panicnil_events_total",
162164
"go_godebug_non_default_behavior_randautoseed_events_total",
163165
"go_godebug_non_default_behavior_tarinsecurepath_events_total",

prometheus/collectors/go_collector_go122_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func withAllMetrics() []string {
6666
"go_godebug_non_default_behavior_multipartmaxheaders_events_total",
6767
"go_godebug_non_default_behavior_multipartmaxparts_events_total",
6868
"go_godebug_non_default_behavior_multipathtcp_events_total",
69+
"go_godebug_non_default_behavior_netedns0_events_total",
6970
"go_godebug_non_default_behavior_panicnil_events_total",
7071
"go_godebug_non_default_behavior_randautoseed_events_total",
7172
"go_godebug_non_default_behavior_tarinsecurepath_events_total",
@@ -176,6 +177,7 @@ func withDebugMetrics() []string {
176177
"go_godebug_non_default_behavior_multipartmaxheaders_events_total",
177178
"go_godebug_non_default_behavior_multipartmaxparts_events_total",
178179
"go_godebug_non_default_behavior_multipathtcp_events_total",
180+
"go_godebug_non_default_behavior_netedns0_events_total",
179181
"go_godebug_non_default_behavior_panicnil_events_total",
180182
"go_godebug_non_default_behavior_randautoseed_events_total",
181183
"go_godebug_non_default_behavior_tarinsecurepath_events_total",

prometheus/collectors/go_collector_latest_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ import (
2020
"encoding/json"
2121
"log"
2222
"net/http"
23-
"reflect"
2423
"regexp"
2524
"sort"
2625
"testing"
2726

27+
"github.com/google/go-cmp/cmp"
28+
2829
"github.com/prometheus/client_golang/prometheus"
2930
"github.com/prometheus/client_golang/prometheus/promhttp"
3031
)
@@ -69,8 +70,8 @@ func TestWithGoCollectorMemStatsMetricsDisabled(t *testing.T) {
6970
got = append(got, r.GetName())
7071
}
7172

72-
if !reflect.DeepEqual(got, baseMetrics) {
73-
t.Errorf("got %v, want %v", got, baseMetrics)
73+
if diff := cmp.Diff(got, baseMetrics); diff != "" {
74+
t.Errorf("missmatch (-want +got):\n%s", diff)
7475
}
7576
}
7677

@@ -127,8 +128,8 @@ func TestGoCollectorAllowList(t *testing.T) {
127128
got = append(got, r.GetName())
128129
}
129130

130-
if !reflect.DeepEqual(got, test.expected) {
131-
t.Errorf("got %v, want %v", got, test.expected)
131+
if diff := cmp.Diff(got, test.expected); diff != "" {
132+
t.Errorf("missmatch (-want +got):\n%s", diff)
132133
}
133134
})
134135
}
@@ -181,8 +182,8 @@ func TestGoCollectorDenyList(t *testing.T) {
181182
got = append(got, r.GetName())
182183
}
183184

184-
if !reflect.DeepEqual(got, test.expected) {
185-
t.Errorf("got %v, want %v", got, test.expected)
185+
if diff := cmp.Diff(got, test.expected); diff != "" {
186+
t.Errorf("missmatch (-want +got):\n%s", diff)
186187
}
187188
})
188189
}

prometheus/go_collector_metrics_go121_test.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prometheus/go_collector_metrics_go122_test.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prometheus/process_collector.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ import (
2222
)
2323

2424
type processCollector struct {
25-
collectFn func(chan<- Metric)
26-
pidFn func() (int, error)
27-
reportErrors bool
28-
cpuTotal *Desc
29-
openFDs, maxFDs *Desc
30-
vsize, maxVsize *Desc
31-
rss *Desc
32-
startTime *Desc
25+
collectFn func(chan<- Metric)
26+
pidFn func() (int, error)
27+
reportErrors bool
28+
cpuTotal *Desc
29+
openFDs, maxFDs *Desc
30+
vsize, maxVsize *Desc
31+
rss *Desc
32+
startTime *Desc
33+
inBytes, outBytes *Desc
3334
}
3435

3536
// ProcessCollectorOpts defines the behavior of a process metrics collector
@@ -100,6 +101,16 @@ func NewProcessCollector(opts ProcessCollectorOpts) Collector {
100101
"Start time of the process since unix epoch in seconds.",
101102
nil, nil,
102103
),
104+
inBytes: NewDesc(
105+
ns+"process_network_receive_bytes_total",
106+
"Number of bytes received by the process over the network.",
107+
nil, nil,
108+
),
109+
outBytes: NewDesc(
110+
ns+"process_network_transmit_bytes_total",
111+
"Number of bytes sent by the process over the network.",
112+
nil, nil,
113+
),
103114
}
104115

105116
if opts.PidFn == nil {

prometheus/process_collector_other.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,18 @@ func (c *processCollector) processCollect(ch chan<- Metric) {
6363
} else {
6464
c.reportError(ch, nil, err)
6565
}
66+
67+
if netstat, err := p.Netstat(); err == nil {
68+
var inOctets, outOctets float64
69+
if netstat.IpExt.InOctets != nil {
70+
inOctets = *netstat.IpExt.InOctets
71+
}
72+
if netstat.IpExt.OutOctets != nil {
73+
outOctets = *netstat.IpExt.OutOctets
74+
}
75+
ch <- MustNewConstMetric(c.inBytes, CounterValue, inOctets)
76+
ch <- MustNewConstMetric(c.outBytes, CounterValue, outOctets)
77+
} else {
78+
c.reportError(ch, nil, err)
79+
}
6680
}

prometheus/process_collector_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,17 @@ func TestProcessCollector(t *testing.T) {
6969
regexp.MustCompile("\nprocess_virtual_memory_bytes [1-9]"),
7070
regexp.MustCompile("\nprocess_resident_memory_bytes [1-9]"),
7171
regexp.MustCompile("\nprocess_start_time_seconds [0-9.]{10,}"),
72+
regexp.MustCompile("\nprocess_network_receive_bytes_total [0-9]+"),
73+
regexp.MustCompile("\nprocess_network_transmit_bytes_total [0-9]+"),
7274
regexp.MustCompile("\nfoobar_process_cpu_seconds_total [0-9]"),
7375
regexp.MustCompile("\nfoobar_process_max_fds [1-9]"),
7476
regexp.MustCompile("\nfoobar_process_open_fds [1-9]"),
7577
regexp.MustCompile("\nfoobar_process_virtual_memory_max_bytes (-1|[1-9])"),
7678
regexp.MustCompile("\nfoobar_process_virtual_memory_bytes [1-9]"),
7779
regexp.MustCompile("\nfoobar_process_resident_memory_bytes [1-9]"),
7880
regexp.MustCompile("\nfoobar_process_start_time_seconds [0-9.]{10,}"),
81+
regexp.MustCompile("\nfoobar_process_network_receive_bytes_total [0-9]+"),
82+
regexp.MustCompile("\nfoobar_process_network_transmit_bytes_total [0-9]+"),
7983
} {
8084
if !re.Match(buf.Bytes()) {
8185
t.Errorf("want body to match %s\n%s", re, buf.String())

0 commit comments

Comments
 (0)