Fix namespace of process collector metrics

This commit is contained in:
Tobias Schmidt 2016-11-02 14:09:24 -04:00
parent 9753225510
commit 99d64f8879
2 changed files with 23 additions and 18 deletions

View File

@ -44,37 +44,42 @@ func NewProcessCollectorPIDFn(
pidFn func() (int, error), pidFn func() (int, error),
namespace string, namespace string,
) Collector { ) Collector {
ns := ""
if len(namespace) > 0 {
ns = namespace + "_"
}
c := processCollector{ c := processCollector{
pidFn: pidFn, pidFn: pidFn,
collectFn: func(chan<- Metric) {}, collectFn: func(chan<- Metric) {},
cpuTotal: NewDesc( cpuTotal: NewDesc(
namespace+"_process_cpu_seconds_total", ns+"process_cpu_seconds_total",
"Total user and system CPU time spent in seconds.", "Total user and system CPU time spent in seconds.",
nil, nil, nil, nil,
), ),
openFDs: NewDesc( openFDs: NewDesc(
namespace+"_process_open_fds", ns+"process_open_fds",
"Number of open file descriptors.", "Number of open file descriptors.",
nil, nil, nil, nil,
), ),
maxFDs: NewDesc( maxFDs: NewDesc(
namespace+"_process_max_fds", ns+"process_max_fds",
"Maximum number of open file descriptors.", "Maximum number of open file descriptors.",
nil, nil, nil, nil,
), ),
vsize: NewDesc( vsize: NewDesc(
namespace+"_process_virtual_memory_bytes", ns+"process_virtual_memory_bytes",
"Virtual memory size in bytes.", "Virtual memory size in bytes.",
nil, nil, nil, nil,
), ),
rss: NewDesc( rss: NewDesc(
namespace+"_process_resident_memory_bytes", ns+"process_resident_memory_bytes",
"Resident memory size in bytes.", "Resident memory size in bytes.",
nil, nil, nil, nil,
), ),
startTime: NewDesc( startTime: NewDesc(
namespace+"_process_start_time_seconds", ns+"process_start_time_seconds",
"Start time of the process since unix epoch in seconds.", "Start time of the process since unix epoch in seconds.",
nil, nil, nil, nil,
), ),

View File

@ -38,18 +38,18 @@ func TestProcessCollector(t *testing.T) {
} }
for _, re := range []*regexp.Regexp{ for _, re := range []*regexp.Regexp{
regexp.MustCompile("process_cpu_seconds_total [0-9]"), regexp.MustCompile("\nprocess_cpu_seconds_total [0-9]"),
regexp.MustCompile("process_max_fds [1-9]"), regexp.MustCompile("\nprocess_max_fds [1-9]"),
regexp.MustCompile("process_open_fds [1-9]"), regexp.MustCompile("\nprocess_open_fds [1-9]"),
regexp.MustCompile("process_virtual_memory_bytes [1-9]"), regexp.MustCompile("\nprocess_virtual_memory_bytes [1-9]"),
regexp.MustCompile("process_resident_memory_bytes [1-9]"), regexp.MustCompile("\nprocess_resident_memory_bytes [1-9]"),
regexp.MustCompile("process_start_time_seconds [0-9.]{10,}"), regexp.MustCompile("\nprocess_start_time_seconds [0-9.]{10,}"),
regexp.MustCompile("foobar_process_cpu_seconds_total [0-9]"), regexp.MustCompile("\nfoobar_process_cpu_seconds_total [0-9]"),
regexp.MustCompile("foobar_process_max_fds [1-9]"), regexp.MustCompile("\nfoobar_process_max_fds [1-9]"),
regexp.MustCompile("foobar_process_open_fds [1-9]"), regexp.MustCompile("\nfoobar_process_open_fds [1-9]"),
regexp.MustCompile("foobar_process_virtual_memory_bytes [1-9]"), regexp.MustCompile("\nfoobar_process_virtual_memory_bytes [1-9]"),
regexp.MustCompile("foobar_process_resident_memory_bytes [1-9]"), regexp.MustCompile("\nfoobar_process_resident_memory_bytes [1-9]"),
regexp.MustCompile("foobar_process_start_time_seconds [0-9.]{10,}"), regexp.MustCompile("\nfoobar_process_start_time_seconds [0-9.]{10,}"),
} { } {
if !re.Match(buf.Bytes()) { if !re.Match(buf.Bytes()) {
t.Errorf("want body to match %s\n%s", re, buf.String()) t.Errorf("want body to match %s\n%s", re, buf.String())