Add process start time metric

This commit is contained in:
Saikat Roychowdhury
2021-08-04 03:13:39 +00:00
parent 77adc85097
commit 3c216f78bb
2 changed files with 32 additions and 2 deletions

View File

@@ -44,8 +44,9 @@ var (
)
const (
httpPattern = "/metrics"
addr = "localhost:0"
httpPattern = "/metrics"
addr = "localhost:0"
processStartTimeMetric = "process_start_time_seconds"
)
type fakeOpStatus struct {
@@ -707,3 +708,24 @@ func containsMetrics(expectedMfs, gotMfs []*cmg.MetricFamily) bool {
return true
}
func TestProcessStartTimeMetricExist(t *testing.T) {
mgr, wg, srv := initMgr()
defer shutdown(srv, wg)
metricsFamilies, err := mgr.GetRegistry().Gather()
if err != nil {
t.Fatalf("Error fetching metrics: %v", err)
}
for _, metricsFamily := range metricsFamilies {
if metricsFamily.GetName() == processStartTimeMetric {
return
}
m := metricsFamily.GetMetric()
if m[0].GetGauge().GetValue() <= 0 {
t.Fatalf("Expected non zero timestamp for process start time")
}
}
t.Fatalf("Metrics does not contain %v. Scraped content: %v", processStartTimeMetric, metricsFamilies)
}