You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2022/03/18 17:15:33 UTC

[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #1152: MINIFICPP-1593 ProcFsMonitor to monitor /proc pseduo filesystem

fgerlits commented on a change in pull request #1152:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1152#discussion_r829878815



##########
File path: extensions/procfs/DiskStat.cpp
##########
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "DiskStat.h"
+#include <utility>
+#include "utils/gsl.h"
+
+using namespace std::literals::chrono_literals;
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+DiskStatData::MonotonicIncreasingMembers DiskStatData::MonotonicIncreasingMembers::operator-(const MonotonicIncreasingMembers& rhs) const {
+  MonotonicIncreasingMembers diff;
+  diff.reads_completed_ = reads_completed_ - rhs.reads_completed_;
+  diff.reads_merged_ = reads_merged_ - rhs.reads_merged_;
+  diff.sectors_read_ = sectors_read_ - rhs.sectors_read_;
+  diff.milliseconds_spent_reading_ = milliseconds_spent_reading_ - rhs.milliseconds_spent_reading_;
+  diff.writes_completed_ = writes_completed_ - rhs.writes_completed_;
+  diff.writes_merges_ = writes_merges_ - rhs.writes_merges_;
+  diff.sectors_written_ = sectors_written_ - rhs.sectors_written_;
+  diff.milliseconds_spent_writing_ = milliseconds_spent_writing_ - rhs.milliseconds_spent_writing_;
+  diff.milliseconds_spent_io_ = milliseconds_spent_io_ - rhs.milliseconds_spent_io_;
+  diff.weighted_milliseconds_spent_io_ = weighted_milliseconds_spent_io_ - rhs.weighted_milliseconds_spent_io_;
+  return diff;
+}
+
+std::optional<std::pair<std::string, DiskStatData>> DiskStatData::parseDiskStatLine(std::istream& iss) {
+  DiskStatData disk_stat_data;
+  std::string disk_name;
+  iss >> disk_stat_data.major_device_number_ >> disk_stat_data.minor_device_number_ >> disk_name >> disk_stat_data.monotonic_increasing_members_.reads_completed_
+      >> disk_stat_data.monotonic_increasing_members_.reads_merged_ >> disk_stat_data.monotonic_increasing_members_.sectors_read_
+      >> disk_stat_data.monotonic_increasing_members_.milliseconds_spent_reading_ >> disk_stat_data.monotonic_increasing_members_.writes_completed_
+      >> disk_stat_data.monotonic_increasing_members_.writes_merges_ >> disk_stat_data.monotonic_increasing_members_.sectors_written_
+      >> disk_stat_data.monotonic_increasing_members_.milliseconds_spent_reading_ >> disk_stat_data.monotonic_increasing_members_.writes_completed_
+      >> disk_stat_data.monotonic_increasing_members_.writes_merges_ >> disk_stat_data.monotonic_increasing_members_.sectors_written_
+      >> disk_stat_data.monotonic_increasing_members_.milliseconds_spent_writing_ >> disk_stat_data.ios_in_progress_ >> disk_stat_data.ios_in_progress_
+      >> disk_stat_data.monotonic_increasing_members_.milliseconds_spent_io_ >> disk_stat_data.monotonic_increasing_members_.weighted_milliseconds_spent_io_;

Review comment:
       This would be easier to read with one variable per line.
   
   That way, it would also be more visible that
   - lines 48-49 are duplicates of lines 46-47 and should be deleted, and
   - `ios_in_progress_` is read twice on line 50.

##########
File path: extensions/procfs/ProcFs.cpp
##########
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ProcFs.h"
+#include <istream>
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+namespace {
+bool is_number(const std::string& s) {
+  return !s.empty() && std::all_of(s.begin(), s.end(), ::isdigit);
+}
+}  // namespace
+
+std::unordered_map<pid_t, ProcessStat> ProcFs::getProcessStats() const {
+  std::unordered_map<pid_t, ProcessStat> process_stats;
+  for (const auto &entry : std::filesystem::directory_iterator(root_path_)) {
+    if (entry.is_directory() && is_number(entry.path().filename())) {
+      auto stat_file_path = entry.path() / STAT_FILE;
+      std::ifstream stat_file(stat_file_path);
+      if (auto process_stat_data = ProcessStatData::parseProcessStatFile(stat_file)) {
+        process_stats.emplace(process_stat_data->getPid(), ProcessStat(*process_stat_data, page_size_));
+      }
+    }
+  }
+  return process_stats;
+}
+
+std::unordered_map<std::string, CpuStatData> ProcFs::getCpuStats() const {
+  std::unordered_map<std::string, CpuStatData> cpu_stats;
+  auto stat_file_path = root_path_ / STAT_FILE;
+  std::ifstream stat_file;
+  stat_file.open(stat_file_path);
+  std::string line;
+  while (std::getline(stat_file, line)) {
+    std::istringstream iss(line);
+    std::string entry_name;
+    iss >> entry_name;
+    if (entry_name.starts_with("cpu")) {
+      if (auto cpu_stat_data = CpuStatData::parseCpuStatLine(iss))
+        cpu_stats.emplace(entry_name, *cpu_stat_data);
+    }
+  }
+  return cpu_stats;
+}
+
+std::optional<MemInfo> ProcFs::getMemInfo() const {
+  auto mem_info_file_path = root_path_ / MEMINFO_FILE;
+  std::ifstream mem_info_file(mem_info_file_path);
+  return MemInfo::parseMemInfoFile(mem_info_file);
+}
+
+std::unordered_map<std::string, NetDevData> ProcFs::getNetDevs() const {
+  std::unordered_map<std::string, NetDevData>net_devs;
+  auto stat_file_path = root_path_ / NET_DEV_FILE;
+  std::ifstream stat_file;
+  stat_file.open(stat_file_path);
+  std::string line;
+  std::getline(stat_file, line);
+  std::getline(stat_file, line);
+  while (std::getline(stat_file, line)) {
+    std::istringstream iss(line);
+    std::string entry_name;
+    iss >> entry_name;
+    if (iss.fail())
+      continue;
+    entry_name.pop_back();

Review comment:
       a comment would be useful here, eg. `// remove the ':' from the end of 'eth0:' etc`

##########
File path: libminifi/test/SingleProcessorTestController.h
##########
@@ -54,6 +51,12 @@ class SingleInputTestController : public TestController {
     return result;
   }
 
+  auto trigger(const std::string_view input_flow_file_content, std::unordered_map<std::string, std::string> input_flow_file_attributes = {}) {
+    const auto new_flow_file = createFlowFile(input_flow_file_content, std::move(input_flow_file_attributes));
+    input_->put(new_flow_file);
+    return trigger();
+  }

Review comment:
       I think it would be nicer to rename this `enqueueFlowFile()` and remove line 57 (users would call `trigger()` separately after a call to `enqueueFlowFile()`).

##########
File path: extensions/procfs/ProcFsSerialization.h
##########
@@ -0,0 +1,164 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+#include <concepts>
+
+#include "CpuStat.h"
+#include "DiskStat.h"
+#include "MemInfo.h"
+#include "NetDev.h"
+#include "ProcessStat.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+void SerializeCPUStatData(const CpuStatData& cpu_stat_data,
+                          std::invocable<const char(&)[], const uint64_t> auto serializer) {
+  serializer("user time", cpu_stat_data.getUser().count());
+  serializer("nice time", cpu_stat_data.getNice().count());
+  serializer("system time", cpu_stat_data.getSystem().count());
+  serializer("idle time", cpu_stat_data.getIdle().count());
+  serializer("io wait time", cpu_stat_data.getIoWait().count());
+  serializer("irq time", cpu_stat_data.getIrq().count());
+  serializer("soft irq time", cpu_stat_data.getSoftIrq().count());
+  serializer("steal time", cpu_stat_data.getSteal().count());
+  serializer("guest time", cpu_stat_data.getGuest().count());
+  serializer("guest nice time", cpu_stat_data.getGuestNice().count());
+}
+
+void SerializeNormalizedCPUStat(const CpuStatData& cpu_stat_data,
+                                std::invocable<const char(&)[], const double> auto serializer) {
+  gsl_Expects(cpu_stat_data.getTotal() > 0ms);
+  serializer("user time %", cpu_stat_data.getUser()/cpu_stat_data.getTotal());
+  serializer("nice time %", cpu_stat_data.getNice()/cpu_stat_data.getTotal());
+  serializer("system time %", cpu_stat_data.getSystem()/cpu_stat_data.getTotal());
+  serializer("idle time %", cpu_stat_data.getIdle()/cpu_stat_data.getTotal());
+  serializer("io wait time %", cpu_stat_data.getIoWait()/cpu_stat_data.getTotal());
+  serializer("irq time %", cpu_stat_data.getIrq()/cpu_stat_data.getTotal());
+  serializer("soft irq %", cpu_stat_data.getSoftIrq()/cpu_stat_data.getTotal());
+  serializer("steal time %", cpu_stat_data.getSteal()/cpu_stat_data.getTotal());
+  serializer("guest time %", cpu_stat_data.getGuest()/cpu_stat_data.getTotal());
+  serializer("guest nice time %", cpu_stat_data.getGuestNice()/cpu_stat_data.getTotal());
+}
+
+void SerializeDiskStatData(const DiskStatData& disk_stat_data,
+                           std::invocable<const char(&)[], const uint64_t> auto serializer) {
+  serializer("Major Device Number", disk_stat_data.getMajorDeviceNumber());
+  serializer("Minor Device Number", disk_stat_data.getMinorDeviceNumber());
+  serializer("Reads Completed", disk_stat_data.getReadsCompleted());
+  serializer("Reads Merged", disk_stat_data.getReadsMerged());
+  serializer("Sectors Read", disk_stat_data.getSectorsRead());
+  serializer("Writes Completed", disk_stat_data.getWritesCompleted());
+  serializer("Writes Merged", disk_stat_data.getWritesMerged());
+  serializer("Sectors Written", disk_stat_data.getSectorsWritten());
+  serializer("IO-s in progress", disk_stat_data.getIosInProgress());
+}
+
+void SerializeDiskStatDataPerSec(const DiskStatData& disk_stat_data,
+                                 const std::chrono::duration<double> duration,
+                                 std::invocable<const char(&)[], const double> auto serializer) {
+  gsl_Expects(duration > 0ms);
+  serializer("Major Device Number", disk_stat_data.getMajorDeviceNumber());
+  serializer("Minor Device Number", disk_stat_data.getMinorDeviceNumber());
+  serializer("Reads Completed/sec", disk_stat_data.getReadsCompleted()/duration.count());
+  serializer("Reads Merged/sec", disk_stat_data.getReadsMerged()/duration.count());
+  serializer("Sectors Read/sec", disk_stat_data.getSectorsRead()/duration.count());
+  serializer("Writes Completed/sec", disk_stat_data.getWritesCompleted()/duration.count());
+  serializer("Writes Merged/sec", disk_stat_data.getWritesMerged()/duration.count());
+  serializer("Sectors Written/sec", disk_stat_data.getSectorsWritten()/duration.count());
+  serializer("IO-s in progress", disk_stat_data.getIosInProgress()/duration.count());
+}
+
+void SerializeMemInfo(const MemInfo& mem_info,
+                      std::invocable<const char(&)[], const uint64_t> auto serializer) {
+  serializer("MemTotal", mem_info.getTotalMemory());
+  serializer("MemFree", mem_info.getAvailableMemory());
+  serializer("MemAvailable", mem_info.getFreeMemory());
+  serializer("MemFree", mem_info.getAvailableMemory());
+  serializer("SwapFree", mem_info.getFreeSwap());
+  serializer("SwapTotal", mem_info.getTotalSwap());

Review comment:
       this is all messed up
   ```suggestion
     serializer("MemTotal", mem_info.getTotalMemory());
     serializer("MemFree", mem_info.getFreeMemory());
     serializer("MemAvailable", mem_info.getAvailableMemory());
     serializer("SwapTotal", mem_info.getTotalSwap());
     serializer("SwapFree", mem_info.getFreeSwap());
   ```

##########
File path: extensions/procfs/ProcFs.cpp
##########
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ProcFs.h"
+#include <istream>
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+namespace {
+bool is_number(const std::string& s) {
+  return !s.empty() && std::all_of(s.begin(), s.end(), ::isdigit);
+}
+}  // namespace
+
+std::unordered_map<pid_t, ProcessStat> ProcFs::getProcessStats() const {
+  std::unordered_map<pid_t, ProcessStat> process_stats;
+  for (const auto &entry : std::filesystem::directory_iterator(root_path_)) {
+    if (entry.is_directory() && is_number(entry.path().filename())) {
+      auto stat_file_path = entry.path() / STAT_FILE;
+      std::ifstream stat_file(stat_file_path);
+      if (auto process_stat_data = ProcessStatData::parseProcessStatFile(stat_file)) {
+        process_stats.emplace(process_stat_data->getPid(), ProcessStat(*process_stat_data, page_size_));
+      }
+    }
+  }
+  return process_stats;
+}
+
+std::unordered_map<std::string, CpuStatData> ProcFs::getCpuStats() const {
+  std::unordered_map<std::string, CpuStatData> cpu_stats;
+  auto stat_file_path = root_path_ / STAT_FILE;
+  std::ifstream stat_file;
+  stat_file.open(stat_file_path);
+  std::string line;
+  while (std::getline(stat_file, line)) {
+    std::istringstream iss(line);
+    std::string entry_name;
+    iss >> entry_name;
+    if (entry_name.starts_with("cpu")) {
+      if (auto cpu_stat_data = CpuStatData::parseCpuStatLine(iss))
+        cpu_stats.emplace(entry_name, *cpu_stat_data);
+    }
+  }
+  return cpu_stats;
+}
+
+std::optional<MemInfo> ProcFs::getMemInfo() const {
+  auto mem_info_file_path = root_path_ / MEMINFO_FILE;
+  std::ifstream mem_info_file(mem_info_file_path);
+  return MemInfo::parseMemInfoFile(mem_info_file);
+}
+
+std::unordered_map<std::string, NetDevData> ProcFs::getNetDevs() const {
+  std::unordered_map<std::string, NetDevData>net_devs;

Review comment:
       missing space before `net_devs` (why doesn't the linter catch this?)

##########
File path: extensions/procfs/MemInfo.h
##########
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>

Review comment:
       `#include <string>` could be moved to the cpp file, and you could add `#include <stdint.h>` for `uint64_t`
   

##########
File path: extensions/procfs/ProcFsSerialization.h
##########
@@ -0,0 +1,164 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+#include <concepts>
+
+#include "CpuStat.h"
+#include "DiskStat.h"
+#include "MemInfo.h"
+#include "NetDev.h"
+#include "ProcessStat.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+void SerializeCPUStatData(const CpuStatData& cpu_stat_data,
+                          std::invocable<const char(&)[], const uint64_t> auto serializer) {
+  serializer("user time", cpu_stat_data.getUser().count());
+  serializer("nice time", cpu_stat_data.getNice().count());
+  serializer("system time", cpu_stat_data.getSystem().count());
+  serializer("idle time", cpu_stat_data.getIdle().count());
+  serializer("io wait time", cpu_stat_data.getIoWait().count());
+  serializer("irq time", cpu_stat_data.getIrq().count());
+  serializer("soft irq time", cpu_stat_data.getSoftIrq().count());
+  serializer("steal time", cpu_stat_data.getSteal().count());
+  serializer("guest time", cpu_stat_data.getGuest().count());
+  serializer("guest nice time", cpu_stat_data.getGuestNice().count());
+}
+
+void SerializeNormalizedCPUStat(const CpuStatData& cpu_stat_data,
+                                std::invocable<const char(&)[], const double> auto serializer) {
+  gsl_Expects(cpu_stat_data.getTotal() > 0ms);
+  serializer("user time %", cpu_stat_data.getUser()/cpu_stat_data.getTotal());
+  serializer("nice time %", cpu_stat_data.getNice()/cpu_stat_data.getTotal());
+  serializer("system time %", cpu_stat_data.getSystem()/cpu_stat_data.getTotal());
+  serializer("idle time %", cpu_stat_data.getIdle()/cpu_stat_data.getTotal());
+  serializer("io wait time %", cpu_stat_data.getIoWait()/cpu_stat_data.getTotal());
+  serializer("irq time %", cpu_stat_data.getIrq()/cpu_stat_data.getTotal());
+  serializer("soft irq %", cpu_stat_data.getSoftIrq()/cpu_stat_data.getTotal());
+  serializer("steal time %", cpu_stat_data.getSteal()/cpu_stat_data.getTotal());
+  serializer("guest time %", cpu_stat_data.getGuest()/cpu_stat_data.getTotal());
+  serializer("guest nice time %", cpu_stat_data.getGuestNice()/cpu_stat_data.getTotal());
+}
+
+void SerializeDiskStatData(const DiskStatData& disk_stat_data,
+                           std::invocable<const char(&)[], const uint64_t> auto serializer) {
+  serializer("Major Device Number", disk_stat_data.getMajorDeviceNumber());
+  serializer("Minor Device Number", disk_stat_data.getMinorDeviceNumber());
+  serializer("Reads Completed", disk_stat_data.getReadsCompleted());
+  serializer("Reads Merged", disk_stat_data.getReadsMerged());
+  serializer("Sectors Read", disk_stat_data.getSectorsRead());
+  serializer("Writes Completed", disk_stat_data.getWritesCompleted());
+  serializer("Writes Merged", disk_stat_data.getWritesMerged());
+  serializer("Sectors Written", disk_stat_data.getSectorsWritten());
+  serializer("IO-s in progress", disk_stat_data.getIosInProgress());
+}
+
+void SerializeDiskStatDataPerSec(const DiskStatData& disk_stat_data,
+                                 const std::chrono::duration<double> duration,
+                                 std::invocable<const char(&)[], const double> auto serializer) {
+  gsl_Expects(duration > 0ms);
+  serializer("Major Device Number", disk_stat_data.getMajorDeviceNumber());
+  serializer("Minor Device Number", disk_stat_data.getMinorDeviceNumber());
+  serializer("Reads Completed/sec", disk_stat_data.getReadsCompleted()/duration.count());
+  serializer("Reads Merged/sec", disk_stat_data.getReadsMerged()/duration.count());
+  serializer("Sectors Read/sec", disk_stat_data.getSectorsRead()/duration.count());
+  serializer("Writes Completed/sec", disk_stat_data.getWritesCompleted()/duration.count());
+  serializer("Writes Merged/sec", disk_stat_data.getWritesMerged()/duration.count());
+  serializer("Sectors Written/sec", disk_stat_data.getSectorsWritten()/duration.count());
+  serializer("IO-s in progress", disk_stat_data.getIosInProgress()/duration.count());
+}
+
+void SerializeMemInfo(const MemInfo& mem_info,
+                      std::invocable<const char(&)[], const uint64_t> auto serializer) {
+  serializer("MemTotal", mem_info.getTotalMemory());
+  serializer("MemFree", mem_info.getAvailableMemory());
+  serializer("MemAvailable", mem_info.getFreeMemory());
+  serializer("MemFree", mem_info.getAvailableMemory());
+  serializer("SwapFree", mem_info.getFreeSwap());
+  serializer("SwapTotal", mem_info.getTotalSwap());
+}
+
+void SerializeNetDevData(const NetDevData& net_dev_data,
+                         std::invocable<const char(&)[], const uint64_t> auto serializer) {
+  serializer("Bytes Received", net_dev_data.getBytesReceived());
+  serializer("Packets Received", net_dev_data.getPacketsReceived());
+  serializer("Receive Errors", net_dev_data.getReceiveErrors());
+  serializer("Receive Drop Errors", net_dev_data.getReceiveDropErrors());
+  serializer("Receive Fifo Errors", net_dev_data.getReceiveFifoErrors());
+  serializer("Receive Frame Errors", net_dev_data.getReceiveFrameErrors());
+  serializer("Compressed Packets Received", net_dev_data.getCompressedPacketsReceived());
+  serializer("Multicast Frames Received", net_dev_data.getMulticastFramesReceived());
+
+  serializer("Bytes Transmitted", net_dev_data.getBytesTransmitted());
+  serializer("Packets Transmitted", net_dev_data.getPacketsTransmitted());
+  serializer("Transmit errors", net_dev_data.getTransmitErrors());
+  serializer("Transmit drop errors", net_dev_data.getTransmitDropErrors());
+  serializer("Transmit fifo errors", net_dev_data.getTransmitFifoErrors());
+  serializer("Transmit collisions", net_dev_data.getTransmitCollisions());
+  serializer("Transmit carrier losses", net_dev_data.getTransmitCarrierLosses());
+  serializer("Compressed Packets Transmitted", net_dev_data.getCompressedPacketsTransmitted());
+}
+
+void SerializeNetDevDataPerSec(const NetDevData& net_dev_data,
+                               const std::chrono::duration<double> duration,
+                               std::invocable<const char(&)[], const double> auto serializer) {
+  gsl_Expects(duration > 0ms);
+  serializer("Bytes Received/sec", net_dev_data.getBytesReceived()/duration.count());
+  serializer("Packets Received/sec", net_dev_data.getPacketsReceived()/duration.count());
+  serializer("Receive Errors/sec", net_dev_data.getReceiveErrors()/duration.count());
+  serializer("Receive Drop Errors/sec", net_dev_data.getReceiveDropErrors()/duration.count());
+  serializer("Receive Fifo Errors/sec", net_dev_data.getReceiveFifoErrors()/duration.count());
+  serializer("Receive Frame Errors/sec", net_dev_data.getReceiveFrameErrors()/duration.count());
+  serializer("Compressed Packets Received/sec", net_dev_data.getCompressedPacketsReceived()/duration.count());
+  serializer("Multicast Frames Received/sec", net_dev_data.getMulticastFramesReceived()/duration.count());
+
+  serializer("Bytes Transmitted/sec", net_dev_data.getBytesTransmitted()/duration.count());
+  serializer("Packets Transmitted/sec", net_dev_data.getPacketsTransmitted()/duration.count());
+  serializer("Transmit errors/sec", net_dev_data.getTransmitErrors()/duration.count());
+  serializer("Transmit drop errors/sec", net_dev_data.getTransmitDropErrors()/duration.count());
+  serializer("Transmit fifo errors/sec", net_dev_data.getTransmitFifoErrors()/duration.count());
+  serializer("Transmit collisions/sec", net_dev_data.getTransmitCollisions()/duration.count());
+  serializer("Transmit carrier losses/sec", net_dev_data.getTransmitCarrierLosses()/duration.count());
+  serializer("Compressed Packets Transmitted/sec", net_dev_data.getCompressedPacketsTransmitted()/duration.count());
+}
+
+void SerializeProcessStat(const ProcessStat& process_stat,
+                          std::invocable<const char(&)[], const uint64_t> auto uint64_t_serializer,
+                          std::invocable<const char(&)[], const std::string_view&> auto string_serializer) {
+  string_serializer("COMM", process_stat.getComm());

Review comment:
       is "COMM" standard in this context?  if not, I would prefer "command" or "COMMAND", as too many words start with "comm": common, communication, commercial etc

##########
File path: extensions/procfs/ProcFs.cpp
##########
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ProcFs.h"
+#include <istream>
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+namespace {
+bool is_number(const std::string& s) {
+  return !s.empty() && std::all_of(s.begin(), s.end(), ::isdigit);
+}
+}  // namespace
+
+std::unordered_map<pid_t, ProcessStat> ProcFs::getProcessStats() const {
+  std::unordered_map<pid_t, ProcessStat> process_stats;
+  for (const auto &entry : std::filesystem::directory_iterator(root_path_)) {
+    if (entry.is_directory() && is_number(entry.path().filename())) {
+      auto stat_file_path = entry.path() / STAT_FILE;
+      std::ifstream stat_file(stat_file_path);
+      if (auto process_stat_data = ProcessStatData::parseProcessStatFile(stat_file)) {
+        process_stats.emplace(process_stat_data->getPid(), ProcessStat(*process_stat_data, page_size_));
+      }
+    }
+  }
+  return process_stats;
+}
+
+std::unordered_map<std::string, CpuStatData> ProcFs::getCpuStats() const {
+  std::unordered_map<std::string, CpuStatData> cpu_stats;
+  auto stat_file_path = root_path_ / STAT_FILE;
+  std::ifstream stat_file;
+  stat_file.open(stat_file_path);
+  std::string line;
+  while (std::getline(stat_file, line)) {
+    std::istringstream iss(line);
+    std::string entry_name;
+    iss >> entry_name;
+    if (entry_name.starts_with("cpu")) {
+      if (auto cpu_stat_data = CpuStatData::parseCpuStatLine(iss))
+        cpu_stats.emplace(entry_name, *cpu_stat_data);
+    }
+  }
+  return cpu_stats;
+}
+
+std::optional<MemInfo> ProcFs::getMemInfo() const {
+  auto mem_info_file_path = root_path_ / MEMINFO_FILE;
+  std::ifstream mem_info_file(mem_info_file_path);
+  return MemInfo::parseMemInfoFile(mem_info_file);
+}
+
+std::unordered_map<std::string, NetDevData> ProcFs::getNetDevs() const {
+  std::unordered_map<std::string, NetDevData>net_devs;
+  auto stat_file_path = root_path_ / NET_DEV_FILE;
+  std::ifstream stat_file;
+  stat_file.open(stat_file_path);
+  std::string line;
+  std::getline(stat_file, line);
+  std::getline(stat_file, line);
+  while (std::getline(stat_file, line)) {
+    std::istringstream iss(line);
+    std::string entry_name;
+    iss >> entry_name;
+    if (iss.fail())
+      continue;
+    entry_name.pop_back();
+    if (auto net_dev_data = NetDevData::parseNetDevLine(iss))
+      net_devs.emplace(entry_name, *net_dev_data);

Review comment:
       Here, and everywhere else where parsing can fail, it would be useful to log the line which has failed to parse.  If the line is not available, only the file name, I would still log that, although that is less useful.

##########
File path: extensions/procfs/ProcFsJsonSerialization.h
##########
@@ -0,0 +1,179 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <string_view>
+
+#include "ProcFsSerialization.h"
+#include "rapidjson/stream.h"
+#include "rapidjson/document.h"
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+namespace details {
+class UInt64Serializer {
+ public:
+  UInt64Serializer(rapidjson::Value& json, rapidjson::Document::AllocatorType& alloc) :
+      json_(json), alloc_(alloc) {
+  }
+  void operator()(const char(&key)[], const uint64_t value) {
+    json_.AddMember(rapidjson::StringRef(key), value, alloc_);
+  }
+ private:
+  rapidjson::Value& json_;
+  rapidjson::Document::AllocatorType& alloc_;
+};
+
+class DoubleSerializer {
+ public:
+  DoubleSerializer(rapidjson::Value& json, rapidjson::Document::AllocatorType& alloc) :
+      json_(json), alloc_(alloc) {
+  }
+  void operator()(const char(&key)[], const double value) {
+    json_.AddMember(rapidjson::StringRef(key), value, alloc_);
+  }
+ private:
+  rapidjson::Value& json_;
+  rapidjson::Document::AllocatorType& alloc_;
+};
+
+class StringSerializer {
+ public:
+  StringSerializer(rapidjson::Value& json, rapidjson::Document::AllocatorType& alloc) :
+      json_(json), alloc_(alloc) {
+  }
+  void operator()(const char(&key)[], const std::string_view& value) {
+    rapidjson::Value value_json(value.data(), value.size(), alloc_);
+    json_.AddMember(rapidjson::StringRef(key), value_json, alloc_);
+  }
+ private:
+  rapidjson::Value& json_;
+  rapidjson::Document::AllocatorType& alloc_;
+};
+}  // namespace details
+
+void addCPUStatToJson(const std::string& cpu_name,
+                      const CpuStatData& cpu_stat,
+                      rapidjson::Value& cpu_root,
+                      rapidjson::Document::AllocatorType& alloc) {
+  rapidjson::Value cpu_key(cpu_name.c_str(), cpu_name.length(), alloc);
+  cpu_root.AddMember(cpu_key.Move(), rapidjson::kObjectType, alloc);
+  rapidjson::Value& cpu_stat_json = cpu_root[cpu_name.c_str()];
+  SerializeCPUStatData(cpu_stat,
+                       details::UInt64Serializer(cpu_stat_json, alloc));
+}
+
+void addCPUStatPeriodToJson(const std::string& cpu_name,
+                            const CpuStatData& start,
+                            const CpuStatData& end,
+                            rapidjson::Value& cpu_root,
+                            rapidjson::Document::AllocatorType& alloc) {
+  rapidjson::Value cpu_key(cpu_name.c_str(), cpu_name.length(), alloc);
+  cpu_root.AddMember(cpu_key.Move(), rapidjson::kObjectType, alloc);
+  rapidjson::Value& cpu_stat_json = cpu_root[cpu_name.c_str()];
+  SerializeNormalizedCPUStat(end-start,
+                             details::DoubleSerializer(cpu_stat_json, alloc));
+}
+
+void addDiskStatToJson(const std::string& disk_name,
+                       const DiskStatData& disk_stat,
+                       rapidjson::Value& disk_root,
+                       rapidjson::Document::AllocatorType& alloc) {
+  rapidjson::Value disk_key(disk_name.c_str(), disk_name.length(), alloc);
+  disk_root.AddMember(disk_key.Move(), rapidjson::kObjectType, alloc);
+  rapidjson::Value& disk_json = disk_root[disk_name.c_str()];
+  SerializeDiskStatData(disk_stat,
+                        details::UInt64Serializer(disk_json, alloc));
+}
+
+void addDiskStatPerSecToJson(const std::string& disk_name,
+                             const DiskStatData disk_stat,
+                             const std::chrono::duration<double> duration,
+                             rapidjson::Value& disk_root,
+                             rapidjson::Document::AllocatorType& alloc) {
+  rapidjson::Value disk_key(disk_name.c_str(), disk_name.length(), alloc);
+  disk_root.AddMember(disk_key.Move(), rapidjson::kObjectType, alloc);
+  rapidjson::Value& disk_json = disk_root[disk_name.c_str()];
+  SerializeDiskStatDataPerSec(disk_stat,
+                              duration,
+                              details::DoubleSerializer(disk_json, alloc));
+}
+
+
+void addNetDevToJson(const std::string& net_name,

Review comment:
       very minor, but I would call this `interface_name` (as that's what it is, eg. "eth0")

##########
File path: extensions/procfs/CpuStat.h
##########
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <istream>
+#include <optional>
+#include <string>
+
+#include "SystemClockDuration.h"
+
+using namespace std::literals::chrono_literals;
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+class CpuStatData {
+  CpuStatData() = default;

Review comment:
       minor, but I would prefer to make this explicitly `private`, either by moving it to the `private:` section or by adding `private:` before it
   
   (also in the other info/stat headers)

##########
File path: extensions/procfs/ProcFsSerialization.h
##########
@@ -0,0 +1,164 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+#include <concepts>
+
+#include "CpuStat.h"
+#include "DiskStat.h"
+#include "MemInfo.h"
+#include "NetDev.h"
+#include "ProcessStat.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+void SerializeCPUStatData(const CpuStatData& cpu_stat_data,
+                          std::invocable<const char(&)[], const uint64_t> auto serializer) {
+  serializer("user time", cpu_stat_data.getUser().count());
+  serializer("nice time", cpu_stat_data.getNice().count());
+  serializer("system time", cpu_stat_data.getSystem().count());
+  serializer("idle time", cpu_stat_data.getIdle().count());
+  serializer("io wait time", cpu_stat_data.getIoWait().count());
+  serializer("irq time", cpu_stat_data.getIrq().count());
+  serializer("soft irq time", cpu_stat_data.getSoftIrq().count());
+  serializer("steal time", cpu_stat_data.getSteal().count());
+  serializer("guest time", cpu_stat_data.getGuest().count());
+  serializer("guest nice time", cpu_stat_data.getGuestNice().count());
+}
+
+void SerializeNormalizedCPUStat(const CpuStatData& cpu_stat_data,
+                                std::invocable<const char(&)[], const double> auto serializer) {
+  gsl_Expects(cpu_stat_data.getTotal() > 0ms);
+  serializer("user time %", cpu_stat_data.getUser()/cpu_stat_data.getTotal());
+  serializer("nice time %", cpu_stat_data.getNice()/cpu_stat_data.getTotal());
+  serializer("system time %", cpu_stat_data.getSystem()/cpu_stat_data.getTotal());
+  serializer("idle time %", cpu_stat_data.getIdle()/cpu_stat_data.getTotal());
+  serializer("io wait time %", cpu_stat_data.getIoWait()/cpu_stat_data.getTotal());
+  serializer("irq time %", cpu_stat_data.getIrq()/cpu_stat_data.getTotal());
+  serializer("soft irq %", cpu_stat_data.getSoftIrq()/cpu_stat_data.getTotal());
+  serializer("steal time %", cpu_stat_data.getSteal()/cpu_stat_data.getTotal());
+  serializer("guest time %", cpu_stat_data.getGuest()/cpu_stat_data.getTotal());
+  serializer("guest nice time %", cpu_stat_data.getGuestNice()/cpu_stat_data.getTotal());
+}
+
+void SerializeDiskStatData(const DiskStatData& disk_stat_data,
+                           std::invocable<const char(&)[], const uint64_t> auto serializer) {
+  serializer("Major Device Number", disk_stat_data.getMajorDeviceNumber());
+  serializer("Minor Device Number", disk_stat_data.getMinorDeviceNumber());
+  serializer("Reads Completed", disk_stat_data.getReadsCompleted());
+  serializer("Reads Merged", disk_stat_data.getReadsMerged());
+  serializer("Sectors Read", disk_stat_data.getSectorsRead());
+  serializer("Writes Completed", disk_stat_data.getWritesCompleted());
+  serializer("Writes Merged", disk_stat_data.getWritesMerged());
+  serializer("Sectors Written", disk_stat_data.getSectorsWritten());
+  serializer("IO-s in progress", disk_stat_data.getIosInProgress());

Review comment:
       "IO-s" looks strange; I would write "IOs" or "IO operations" or possibly "IO's" (in both places)

##########
File path: extensions/procfs/DiskStat.h
##########
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <chrono>
+#include <istream>
+#include <optional>
+#include <string>
+#include <utility>
+
+using namespace std::literals::chrono_literals;
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+class DiskStatData {
+  DiskStatData() = default;
+
+ public:
+  struct MonotonicIncreasingMembers {
+    uint64_t reads_completed_;
+    uint64_t reads_merged_;
+    uint64_t sectors_read_;
+    uint64_t milliseconds_spent_reading_;
+    uint64_t writes_completed_;
+    uint64_t writes_merges_;

Review comment:
       typo:
   ```suggestion
       uint64_t writes_merged_;
   ```

##########
File path: extensions/procfs/NetDev.cpp
##########
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "NetDev.h"
+
+using namespace std::literals::chrono_literals;
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+std::optional<NetDevData> NetDevData::parseNetDevLine(std::istream& iss) {
+  NetDevData net_dev_data;
+  iss >> net_dev_data.bytes_received_ >> net_dev_data.packets_received_ >> net_dev_data.errs_received_ >> net_dev_data.drop_errors_received_
+      >> net_dev_data.fifo_errors_received_ >> net_dev_data.frame_errors_received_ >> net_dev_data.compressed_packets_received_
+      >> net_dev_data.multicast_frames_received_>> net_dev_data.bytes_transmitted_ >> net_dev_data.packets_transmitted_
+      >> net_dev_data.errs_transmitted_ >> net_dev_data.drop_errors_transmitted_ >> net_dev_data.fifo_errors_transmitted_
+      >> net_dev_data.collisions_transmitted_ >> net_dev_data.carrier_losses_transmitted_ >> net_dev_data.compressed_packets_transmitted_;

Review comment:
       one variable per line would be more readable here, too

##########
File path: extensions/procfs/ProcFsJsonSerialization.h
##########
@@ -0,0 +1,179 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <string_view>
+
+#include "ProcFsSerialization.h"
+#include "rapidjson/stream.h"
+#include "rapidjson/document.h"
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+namespace details {
+class UInt64Serializer {
+ public:
+  UInt64Serializer(rapidjson::Value& json, rapidjson::Document::AllocatorType& alloc) :
+      json_(json), alloc_(alloc) {
+  }
+  void operator()(const char(&key)[], const uint64_t value) {

Review comment:
       Is this a new C++20 feature?  Do you have a link to a description of how it works?  It's pretty cool; clang 13.0.1 doesn't support it, yet, but clang trunk does, so I don't mind keeping it as a "temporarily gcc-only feature".  On the other hand, it may be simpler to use `const char* key`.

##########
File path: extensions/procfs/CpuStat.cpp
##########
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "CpuStat.h"
+
+using namespace std::literals::chrono_literals;
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+std::optional<CpuStatData> CpuStatData::parseCpuStatLine(std::istream& iss) {
+  CpuStatData data;
+  iss >> data.user_ >> data.nice_ >> data.system_ >> data.idle_ >> data.io_wait_ >> data.irq_ >> data.soft_irq_ >> data.steal_ >> data.guest_ >> data.guest_nice_;
+  if (iss.fail())
+    return std::nullopt;
+  data.user_ -= data.guest_;  // Guest time is already accounted in usertime
+  data.nice_ -= data.guest_nice_;

Review comment:
       Are you sure we want to do this?  As a user, I would expect the "user time" and "nice time" reported by ProcFsMonitor to be the same as the number in `/proc/stat` (and might subtract the guest time from it again).

##########
File path: extensions/procfs/ProcFsSerialization.h
##########
@@ -0,0 +1,164 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+#include <concepts>
+
+#include "CpuStat.h"
+#include "DiskStat.h"
+#include "MemInfo.h"
+#include "NetDev.h"
+#include "ProcessStat.h"
+#include "utils/gsl.h"
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+void SerializeCPUStatData(const CpuStatData& cpu_stat_data,
+                          std::invocable<const char(&)[], const uint64_t> auto serializer) {
+  serializer("user time", cpu_stat_data.getUser().count());
+  serializer("nice time", cpu_stat_data.getNice().count());
+  serializer("system time", cpu_stat_data.getSystem().count());
+  serializer("idle time", cpu_stat_data.getIdle().count());
+  serializer("io wait time", cpu_stat_data.getIoWait().count());
+  serializer("irq time", cpu_stat_data.getIrq().count());
+  serializer("soft irq time", cpu_stat_data.getSoftIrq().count());
+  serializer("steal time", cpu_stat_data.getSteal().count());
+  serializer("guest time", cpu_stat_data.getGuest().count());
+  serializer("guest nice time", cpu_stat_data.getGuestNice().count());
+}
+
+void SerializeNormalizedCPUStat(const CpuStatData& cpu_stat_data,
+                                std::invocable<const char(&)[], const double> auto serializer) {
+  gsl_Expects(cpu_stat_data.getTotal() > 0ms);
+  serializer("user time %", cpu_stat_data.getUser()/cpu_stat_data.getTotal());
+  serializer("nice time %", cpu_stat_data.getNice()/cpu_stat_data.getTotal());
+  serializer("system time %", cpu_stat_data.getSystem()/cpu_stat_data.getTotal());
+  serializer("idle time %", cpu_stat_data.getIdle()/cpu_stat_data.getTotal());
+  serializer("io wait time %", cpu_stat_data.getIoWait()/cpu_stat_data.getTotal());
+  serializer("irq time %", cpu_stat_data.getIrq()/cpu_stat_data.getTotal());
+  serializer("soft irq %", cpu_stat_data.getSoftIrq()/cpu_stat_data.getTotal());
+  serializer("steal time %", cpu_stat_data.getSteal()/cpu_stat_data.getTotal());
+  serializer("guest time %", cpu_stat_data.getGuest()/cpu_stat_data.getTotal());
+  serializer("guest nice time %", cpu_stat_data.getGuestNice()/cpu_stat_data.getTotal());
+}
+
+void SerializeDiskStatData(const DiskStatData& disk_stat_data,
+                           std::invocable<const char(&)[], const uint64_t> auto serializer) {
+  serializer("Major Device Number", disk_stat_data.getMajorDeviceNumber());
+  serializer("Minor Device Number", disk_stat_data.getMinorDeviceNumber());
+  serializer("Reads Completed", disk_stat_data.getReadsCompleted());
+  serializer("Reads Merged", disk_stat_data.getReadsMerged());
+  serializer("Sectors Read", disk_stat_data.getSectorsRead());
+  serializer("Writes Completed", disk_stat_data.getWritesCompleted());
+  serializer("Writes Merged", disk_stat_data.getWritesMerged());
+  serializer("Sectors Written", disk_stat_data.getSectorsWritten());
+  serializer("IO-s in progress", disk_stat_data.getIosInProgress());
+}
+
+void SerializeDiskStatDataPerSec(const DiskStatData& disk_stat_data,
+                                 const std::chrono::duration<double> duration,
+                                 std::invocable<const char(&)[], const double> auto serializer) {
+  gsl_Expects(duration > 0ms);
+  serializer("Major Device Number", disk_stat_data.getMajorDeviceNumber());
+  serializer("Minor Device Number", disk_stat_data.getMinorDeviceNumber());
+  serializer("Reads Completed/sec", disk_stat_data.getReadsCompleted()/duration.count());
+  serializer("Reads Merged/sec", disk_stat_data.getReadsMerged()/duration.count());
+  serializer("Sectors Read/sec", disk_stat_data.getSectorsRead()/duration.count());
+  serializer("Writes Completed/sec", disk_stat_data.getWritesCompleted()/duration.count());
+  serializer("Writes Merged/sec", disk_stat_data.getWritesMerged()/duration.count());
+  serializer("Sectors Written/sec", disk_stat_data.getSectorsWritten()/duration.count());
+  serializer("IO-s in progress", disk_stat_data.getIosInProgress()/duration.count());
+}
+
+void SerializeMemInfo(const MemInfo& mem_info,
+                      std::invocable<const char(&)[], const uint64_t> auto serializer) {
+  serializer("MemTotal", mem_info.getTotalMemory());
+  serializer("MemFree", mem_info.getAvailableMemory());
+  serializer("MemAvailable", mem_info.getFreeMemory());
+  serializer("MemFree", mem_info.getAvailableMemory());
+  serializer("SwapFree", mem_info.getFreeSwap());
+  serializer("SwapTotal", mem_info.getTotalSwap());
+}
+
+void SerializeNetDevData(const NetDevData& net_dev_data,
+                         std::invocable<const char(&)[], const uint64_t> auto serializer) {
+  serializer("Bytes Received", net_dev_data.getBytesReceived());
+  serializer("Packets Received", net_dev_data.getPacketsReceived());
+  serializer("Receive Errors", net_dev_data.getReceiveErrors());
+  serializer("Receive Drop Errors", net_dev_data.getReceiveDropErrors());
+  serializer("Receive Fifo Errors", net_dev_data.getReceiveFifoErrors());
+  serializer("Receive Frame Errors", net_dev_data.getReceiveFrameErrors());
+  serializer("Compressed Packets Received", net_dev_data.getCompressedPacketsReceived());
+  serializer("Multicast Frames Received", net_dev_data.getMulticastFramesReceived());
+
+  serializer("Bytes Transmitted", net_dev_data.getBytesTransmitted());
+  serializer("Packets Transmitted", net_dev_data.getPacketsTransmitted());
+  serializer("Transmit errors", net_dev_data.getTransmitErrors());
+  serializer("Transmit drop errors", net_dev_data.getTransmitDropErrors());
+  serializer("Transmit fifo errors", net_dev_data.getTransmitFifoErrors());
+  serializer("Transmit collisions", net_dev_data.getTransmitCollisions());
+  serializer("Transmit carrier losses", net_dev_data.getTransmitCarrierLosses());
+  serializer("Compressed Packets Transmitted", net_dev_data.getCompressedPacketsTransmitted());
+}
+
+void SerializeNetDevDataPerSec(const NetDevData& net_dev_data,
+                               const std::chrono::duration<double> duration,
+                               std::invocable<const char(&)[], const double> auto serializer) {
+  gsl_Expects(duration > 0ms);
+  serializer("Bytes Received/sec", net_dev_data.getBytesReceived()/duration.count());
+  serializer("Packets Received/sec", net_dev_data.getPacketsReceived()/duration.count());
+  serializer("Receive Errors/sec", net_dev_data.getReceiveErrors()/duration.count());
+  serializer("Receive Drop Errors/sec", net_dev_data.getReceiveDropErrors()/duration.count());
+  serializer("Receive Fifo Errors/sec", net_dev_data.getReceiveFifoErrors()/duration.count());
+  serializer("Receive Frame Errors/sec", net_dev_data.getReceiveFrameErrors()/duration.count());
+  serializer("Compressed Packets Received/sec", net_dev_data.getCompressedPacketsReceived()/duration.count());
+  serializer("Multicast Frames Received/sec", net_dev_data.getMulticastFramesReceived()/duration.count());
+
+  serializer("Bytes Transmitted/sec", net_dev_data.getBytesTransmitted()/duration.count());
+  serializer("Packets Transmitted/sec", net_dev_data.getPacketsTransmitted()/duration.count());
+  serializer("Transmit errors/sec", net_dev_data.getTransmitErrors()/duration.count());
+  serializer("Transmit drop errors/sec", net_dev_data.getTransmitDropErrors()/duration.count());
+  serializer("Transmit fifo errors/sec", net_dev_data.getTransmitFifoErrors()/duration.count());
+  serializer("Transmit collisions/sec", net_dev_data.getTransmitCollisions()/duration.count());
+  serializer("Transmit carrier losses/sec", net_dev_data.getTransmitCarrierLosses()/duration.count());
+  serializer("Compressed Packets Transmitted/sec", net_dev_data.getCompressedPacketsTransmitted()/duration.count());
+}
+
+void SerializeProcessStat(const ProcessStat& process_stat,
+                          std::invocable<const char(&)[], const uint64_t> auto uint64_t_serializer,
+                          std::invocable<const char(&)[], const std::string_view&> auto string_serializer) {
+  string_serializer("COMM", process_stat.getComm());
+  uint64_t_serializer("RES", process_stat.getMemory());
+  uint64_t_serializer("CPUTIME", process_stat.getCpuTime().count());
+}
+
+void SerializeNormalizedProcessStat(const ProcessStat& process_stat_start,
+                                    const ProcessStat& process_stat_end,
+                                    const std::chrono::duration<double> all_cpu_time,
+                                    std::invocable<const char(&)[], const uint64_t> auto uint64_t_serializer,
+                                    std::invocable<const char(&)[], const std::string_view&> auto string_serializer,
+                                    std::invocable<const char(&)[], const double> auto double_serializer) {
+  gsl_Expects(all_cpu_time > 0ms);
+  gsl_Expects(process_stat_start.getComm() == process_stat_end.getComm());
+  gsl_Expects(process_stat_end.getCpuTime() >= process_stat_start.getCpuTime());
+  auto cpu_time_diff = process_stat_end.getCpuTime()-process_stat_end.getCpuTime();
+  string_serializer("COMM", process_stat_start.getComm());
+  uint64_t_serializer("RES", process_stat_start.getMemory());

Review comment:
       I think
   ```suggestion
     uint64_t_serializer("RES", process_stat_end.getMemory());
   ```
   would be more natural




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org