Skip to content

Commit 54a9569

Browse files
authored
Add required metrics and datapoint attributes for Process tab in Host UI (#34)
* remove executable * Add fields to start supporting Process tab * update comment * update comment * Update name of the process state
1 parent 3df0d4f commit 54a9569

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

remappers/hostmetrics/hostmetrics_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var (
4242
ProcPath string = "/bin/run"
4343
ProcName string = "runner"
4444
Cmdline string = "./dist/otelcol-ishleen-custom --config collector.yml"
45+
Processstate string = "undefined"
4546
Device string = "en0"
4647
Disk string = "nvme0n1p128"
4748
FilesystemDevice string = "dev/nvme0n1p1"
@@ -71,6 +72,7 @@ func doTestRemap(t *testing.T, id string, remapOpts ...Option) {
7172
m["process.executable"] = ProcPath
7273
m["process.name"] = ProcName
7374
m["system.process.cmdline"] = Cmdline
75+
m["system.process.state"] = Processstate
7476
case "network":
7577
m["system.network.name"] = Device
7678
case "disk":
@@ -223,6 +225,7 @@ func doTestRemap(t *testing.T, id string, remapOpts ...Option) {
223225
},
224226
expected: []internal.TestMetric{
225227
{Type: Sum, Name: "process.cpu.start_time", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(0)), Attrs: outAttr("process")}},
228+
{Type: Sum, Name: "system.process.cpu.start_time", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(0)), Attrs: outAttr("process")}},
226229
{Type: Sum, Name: "system.process.num_threads", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(7)), Attrs: outAttr("process")}},
227230
{Type: Gauge, Name: "system.process.memory.rss.pct", DP: internal.TestDP{Ts: now, Dbl: internal.Ptr(0.15), Attrs: outAttr("process")}},
228231
{Type: Sum, Name: "system.process.memory.rss.bytes", DP: internal.TestDP{Ts: now, Int: internal.Ptr(int64(2048)), Attrs: outAttr("process")}},

remappers/hostmetrics/process.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,20 @@ func remapProcessMetrics(
157157
cpuPct = cpuTimeValue / float64(processRuntime)
158158

159159
remappers.AddMetrics(out, dataset, addProcessResources(resource),
160+
// The timestamp metrics get converted from Int to Timestamp in Kibana
161+
// since these are mapped to timestamp datatype
160162
remappers.Metric{
161163
DataType: pmetric.MetricTypeSum,
162164
Name: "process.cpu.start_time",
163165
Timestamp: timestamp,
164166
IntValue: &startTime,
165167
},
168+
remappers.Metric{
169+
DataType: pmetric.MetricTypeSum,
170+
Name: "system.process.cpu.start_time",
171+
Timestamp: timestamp,
172+
IntValue: &startTime,
173+
},
166174
remappers.Metric{
167175
DataType: pmetric.MetricTypeSum,
168176
Name: "system.process.num_threads",
@@ -281,5 +289,8 @@ func addProcessResources(resource pcommon.Resource) func(pmetric.NumberDataPoint
281289
if cmdline.Str() != "" {
282290
dp.Attributes().PutStr("system.process.cmdline", cmdline.Str())
283291
}
292+
//Adding dummy value to process.state as "undefined", since this field is not
293+
//available through Hostmetrics receiver currently and Process tab in Curated UI's need this field as a prerequisite.
294+
dp.Attributes().PutStr("system.process.state", "undefined")
284295
}
285296
}

0 commit comments

Comments
 (0)