fgerlits commented on a change in pull request #1152: URL: https://github.com/apache/nifi-minifi-cpp/pull/1152#discussion_r833187415
########## File path: extensions/procfs/processors/ProcFsMonitor.h ########## @@ -0,0 +1,131 @@ +/** + * 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 <memory> +#include <unordered_map> +#include <vector> +#include <optional> + +#include "../ProcFs.h" +#include "core/Processor.h" +#include "core/logging/LoggerConfiguration.h" +#include "core/logging/Logger.h" +#include "utils/Enum.h" + +#include "rapidjson/stream.h" +#include "rapidjson/document.h" + +namespace org::apache::nifi::minifi::extensions::procfs { + +class ProcFsMonitor : public core::Processor { + public: + explicit ProcFsMonitor(const std::string& name, utils::Identifier uuid = utils::Identifier()) + : Processor(name, uuid) { + } + ProcFsMonitor(const ProcFsMonitor&) = delete; + ProcFsMonitor(ProcFsMonitor&&) = delete; + ProcFsMonitor& operator=(const ProcFsMonitor&) = delete; + ProcFsMonitor& operator=(ProcFsMonitor&&) = delete; + ~ProcFsMonitor() override = default; + + static constexpr char const *ProcessorName = "ProcFsMonitor"; + + EXTENSIONAPI static const core::Property OutputFormatProperty; + EXTENSIONAPI static const core::Property OutputCompactnessProperty; + EXTENSIONAPI static const core::Property DecimalPlaces; + EXTENSIONAPI static const core::Property ResultRelativenessProperty; + + EXTENSIONAPI static const core::Relationship Success; + + + public: + void onSchedule(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSessionFactory>& sessionFactory) override; + + void onTrigger(core::ProcessContext *context, core::ProcessSession *session) override; + + void initialize() override; + + SMART_ENUM(OutputFormat, + (JSON, "JSON"), + (OPENTELEMETRY, "OpenTelemetry") + ) + + SMART_ENUM(OutputCompactness, + (COMPACT, "Compact"), + (PRETTY, "Pretty") + ) + + SMART_ENUM(ResultRelativeness, + (RELATIVE, "Relative"), + (ABSOLUTE, "Absolute") + ) + + private: + bool isSingleThreaded() const override { + return true; + } + + core::annotation::Input getInputRequirement() const override { + return core::annotation::Input::INPUT_FORBIDDEN; + } + + protected: + rapidjson::Value& prepareJSONBody(rapidjson::Document& root); + + void setupDecimalPlacesFromProperties(const core::ProcessContext& context); + + void processCPUInformation(const std::unordered_map<std::string, CpuStatData>& current_cpu_stats, + rapidjson::Value& body, + rapidjson::Document::AllocatorType& alloc); + void processDiskInformation(const std::unordered_map<std::string, DiskStatData>& current_disk_stats, + rapidjson::Value& body, + rapidjson::Document::AllocatorType& alloc); + void processNetworkInformation(const std::unordered_map<std::string, NetDevData>& current_net_devs, + rapidjson::Value& body, + rapidjson::Document::AllocatorType& alloc); + void processProcessInformation(const std::unordered_map<pid_t, ProcessStat>& current_process_stats, + std::optional<std::chrono::duration<double>> last_cpu_period, + rapidjson::Value& body, + rapidjson::Document::AllocatorType& alloc); + void processMemoryInformation(rapidjson::Value& body, + rapidjson::Document::AllocatorType& alloc); + + void refreshMembers(std::unordered_map<std::string, CpuStatData>&& current_cpu_stats, + std::unordered_map<std::string, DiskStatData>&& current_disk_stats, + std::unordered_map<std::string, NetDevData>&& current_net_devs, + std::unordered_map<pid_t, ProcessStat>&& current_process_stats); + + OutputFormat output_format_ = OutputFormat::JSON; + OutputCompactness output_compactness_ = OutputCompactness::PRETTY; + ResultRelativeness result_relativeness_ = ResultRelativeness::ABSOLUTE; + + std::optional<uint8_t> decimal_places_; + std::shared_ptr<core::logging::Logger> logger_ = core::logging::LoggerFactory<ProcFsMonitor>::getLogger(); + + ProcFs proc_fs_; + + std::unordered_map<std::string, CpuStatData> last_cpu_stats_; + std::unordered_map<std::string, NetDevData> last_net_devs_; + std::unordered_map<std::string, DiskStatData> last_disk_stats_; + std::unordered_map<pid_t, ProcessStat> last_process_stats_; + std::optional<std::chrono::steady_clock::time_point> last_trigger; Review comment: missing trailing `_` ########## File path: extensions/procfs/tests/CPUStatTests.cpp ########## @@ -0,0 +1,85 @@ +/** + * 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 "Catch.h" +#include "ProcFs.h" + +#include "rapidjson/stream.h" + +using org::apache::nifi::minifi::extensions::procfs::ProcFs; +using org::apache::nifi::minifi::extensions::procfs::CpuStatData; + +void cpu_stat_period_total_should_be_one(const CpuStatData& cpu_stat) { + double percentage = 0; + percentage += cpu_stat.getUser()/cpu_stat.getTotal(); + percentage += cpu_stat.getNice()/cpu_stat.getTotal(); + percentage += cpu_stat.getSystem()/cpu_stat.getTotal(); + percentage += cpu_stat.getIdle()/cpu_stat.getTotal(); + percentage += cpu_stat.getIoWait()/cpu_stat.getTotal(); + percentage += cpu_stat.getIrq()/cpu_stat.getTotal(); + percentage += cpu_stat.getSoftIrq()/cpu_stat.getTotal(); + percentage += cpu_stat.getSteal()/cpu_stat.getTotal(); + percentage += cpu_stat.getGuest()/cpu_stat.getTotal(); + percentage += cpu_stat.getGuestNice()/cpu_stat.getTotal(); + REQUIRE(percentage == Approx(1.0)); +} + +TEST_CASE("ProcFSTest stat test with mock", "[procfsstatmockabsolutetest]") { + ProcFs proc_fs_t0("./mockprocfs_t0"); + auto cpu_stats_t0 = proc_fs_t0.getCpuStats(); + REQUIRE(cpu_stats_t0.size() == 13); + for (auto& [cpu_name, cpu_stat] : cpu_stats_t0) { Review comment: I would change all the `auto&`s in for loops to `const auto&`, where possible ########## File path: extensions/procfs/tests/MemInfoTests.cpp ########## @@ -0,0 +1,34 @@ +/** + * 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 "Catch.h" +#include "ProcFs.h" + +using org::apache::nifi::minifi::extensions::procfs::ProcFs; +using org::apache::nifi::minifi::extensions::procfs::MemInfo; + +TEST_CASE("ProcFSTest meminfo test with mock", "[procfmeminfomocktest]") { + ProcFs proc_fs("./mockprocfs_t0"); + auto mem_info = proc_fs.getMemInfo(); + REQUIRE(mem_info); Review comment: in the mock case, please check that the fields are as expected, too ########## File path: extensions/procfs/tests/CMakeLists.txt ########## @@ -0,0 +1,40 @@ +# +# 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. +# + +file(GLOB PROCFS_TESTS "*.cpp") + +SET(PROCFS_TEST_COUNT 0) +FOREACH(testfile ${PROCFS_TESTS}) + get_filename_component(testfilename "${testfile}" NAME_WE) + add_executable("${testfilename}" "${testfile}") + target_include_directories(${testfilename} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/extensions/standard-processors") + target_include_directories(${testfilename} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/extensions/procfs") + target_include_directories(${testfilename} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/extensions/procfs/procfs_classes") + target_include_directories(${testfilename} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/libminifi/test/") + target_include_directories(${testfilename} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/extensions/standard-processors") + createTests("${testfilename}") + target_link_libraries(${testfilename} ${CATCH_MAIN_LIB}) + target_link_libraries(${testfilename} minifi-procfs) + target_link_libraries(${testfilename} minifi-standard-processors) + MATH(EXPR PROCFS_TEST_COUNT "${PROCFS_TEST_COUNT}+1") + add_test(NAME "${testfilename}" COMMAND "${testfilename}" "${MOCK_PROC_FS_PATH}") Review comment: what is `MOCK_PROC_FS_PATH`? I can't see it defined anywhere ########## File path: extensions/procfs/processors/ProcFsMonitor.cpp ########## @@ -0,0 +1,282 @@ +/** + * @file GenerateFlowFile.cpp + * GenerateFlowFile class implementation + * + * 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 "ProcFsMonitor.h" +#include <limits> +#include <utility> +#include <vector> +#include <unordered_map> + +#include "core/Resource.h" +#include "core/ProcessContext.h" +#include "core/ProcessSession.h" +#include "../ProcFsJsonSerialization.h" +#include "utils/JsonCallback.h" +#include "utils/OpenTelemetryLogDataModelUtils.h" +#include "utils/gsl.h" + +using namespace std::literals::chrono_literals; + +namespace org::apache::nifi::minifi::extensions::procfs { + +const core::Relationship ProcFsMonitor::Success("success", "All files are routed to success"); + +const core::Property ProcFsMonitor::OutputFormatProperty( + core::PropertyBuilder::createProperty("Output Format")-> + withDescription("The output type of the new flowfile")-> + withAllowableValues<std::string>(OutputFormat::values())-> + withDefaultValue(toString(OutputFormat::JSON))->build()); + +const core::Property ProcFsMonitor::OutputCompactnessProperty( + core::PropertyBuilder::createProperty("Output Compactness")-> + withDescription("The output format of the new flowfile")-> + withAllowableValues<std::string>(OutputCompactness::values())-> + withDefaultValue(toString(OutputCompactness::PRETTY))->build()); + +const core::Property ProcFsMonitor::DecimalPlaces( + core::PropertyBuilder::createProperty("Round to decimal places")-> + withDescription("The number of decimal places to round the values to (blank for no rounding)")->build()); + +const core::Property ProcFsMonitor::ResultRelativenessProperty( + core::PropertyBuilder::createProperty("Result Type")-> + withDescription("Absolute returns the current procfs values, relative calculates the usage between triggers")-> + withAllowableValues<std::string>(ResultRelativeness::values())-> + withDefaultValue(toString(ResultRelativeness::RELATIVE))->build()); + + +void ProcFsMonitor::initialize() { + setSupportedProperties({OutputFormatProperty, OutputCompactnessProperty, DecimalPlaces, ResultRelativenessProperty}); + setSupportedRelationships({ProcFsMonitor::Success}); +} + +void ProcFsMonitor::onSchedule(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSessionFactory>&) { + gsl_Expects(context); + context->getProperty(OutputFormatProperty.getName(), output_format_); + context->getProperty(OutputCompactnessProperty.getName(), output_compactness_); + context->getProperty(ResultRelativenessProperty.getName(), result_relativeness_); + setupDecimalPlacesFromProperties(*context); +} + +namespace { +size_t number_of_cores(const std::unordered_map<std::string, CpuStatData>& cpu_stat) { + return cpu_stat.size() > 1 ? cpu_stat.size() - 1 : 1; +} + +bool cpu_stats_are_valid(const std::unordered_map<std::string, CpuStatData>& cpu_stat) { + return cpu_stat.contains("cpu") && cpu_stat.size() > 1; // needs the aggregate and at least one core information to be valid +} + +std::optional<std::chrono::duration<double>> getAggregateCpuDiff(std::unordered_map<std::string, CpuStatData>& current_cpu_stats, + std::unordered_map<std::string, CpuStatData>& last_cpu_stats) { + if (current_cpu_stats.size() != last_cpu_stats.size()) + return std::nullopt; + if (!cpu_stats_are_valid(current_cpu_stats) || !cpu_stats_are_valid(last_cpu_stats)) + return std::nullopt; + + return (current_cpu_stats.at("cpu").getTotal()-last_cpu_stats.at("cpu").getTotal()) / number_of_cores(current_cpu_stats); +} +} // namespace + +void ProcFsMonitor::onTrigger(core::ProcessContext*, core::ProcessSession* session) { + gsl_Expects(session); + std::shared_ptr<core::FlowFile> flowFile = session->create(); + if (!flowFile) { + logger_->log_error("Failed to create flowfile!"); + yield(); + return; + } + + rapidjson::Document root = rapidjson::Document(rapidjson::kObjectType); + rapidjson::Value &body = prepareJSONBody(root); + auto current_cpu_stats = proc_fs_.getCpuStats(); + auto current_disk_stats = proc_fs_.getDiskStats(); + auto current_net_devs = proc_fs_.getNetDevs(); + auto current_process_stats = proc_fs_.getProcessStats(); + + auto last_cpu_period = getAggregateCpuDiff(current_cpu_stats, last_cpu_stats_); + + auto refresh_members = gsl::finally([&]{ refreshMembers(std::move(current_cpu_stats), + std::move(current_disk_stats), + std::move(current_net_devs), + std::move(current_process_stats));}); + + processCPUInformation(current_cpu_stats, body, root.GetAllocator()); + processDiskInformation(current_disk_stats, body, root.GetAllocator()); + processNetworkInformation(current_net_devs, body, root.GetAllocator()); + processProcessInformation(current_process_stats, last_cpu_period, body, root.GetAllocator()); + processMemoryInformation(body, root.GetAllocator()); + + if (output_compactness_ == OutputCompactness::PRETTY) { + utils::PrettyJsonOutputCallback callback(std::move(root), decimal_places_); + session->write(flowFile, &callback); + session->transfer(flowFile, Success); + } else if (output_compactness_ == OutputCompactness::COMPACT) { + utils::JsonOutputCallback callback(std::move(root), decimal_places_); + session->write(flowFile, &callback); + session->transfer(flowFile, Success); + } else { + throw Exception(GENERAL_EXCEPTION, "Invalid output compactness"); + } +} + +rapidjson::Value& ProcFsMonitor::prepareJSONBody(rapidjson::Document& root) { + if (output_format_ == OutputFormat::OPENTELEMETRY) { + utils::OpenTelemetryLogDataModel::appendEventInformation(root, "PerformanceData"); + utils::OpenTelemetryLogDataModel::appendHostInformation(root); + utils::OpenTelemetryLogDataModel::appendBody(root); + return root["Body"]; + } else if (output_format_ == OutputFormat::JSON) { + return root; + } else { + throw Exception(GENERAL_EXCEPTION, "Invalid output format"); + } +} + +void ProcFsMonitor::setupDecimalPlacesFromProperties(const core::ProcessContext& context) { + std::string decimal_places_str; + if (!context.getProperty(DecimalPlaces.getName(), decimal_places_str) || decimal_places_str.empty()) { + decimal_places_ = std::nullopt; + return; + } + + if (auto decimal_places = context.getProperty<int64_t>(DecimalPlaces)) { + if (*decimal_places > std::numeric_limits<uint8_t>::max()) + throw Exception(PROCESS_SCHEDULE_EXCEPTION, "ProcFsMonitor Decimal Places is out of range"); + decimal_places_ = *decimal_places; + } + if (decimal_places_) + logger_->log_trace("Rounding is enabled with %d decimal places", decimal_places_.value()); +} + +void ProcFsMonitor::processCPUInformation(const std::unordered_map<std::string, CpuStatData>& current_cpu_stats, + rapidjson::Value& body, + rapidjson::Document::AllocatorType& alloc) { + if (!cpu_stats_are_valid(current_cpu_stats)) + return; + + rapidjson::Value cpu_root{rapidjson::kObjectType}; + for (auto& [cpu_name, cpu_stat] : current_cpu_stats) { Review comment: could this be `const auto&`? ########## File path: extensions/procfs/tests/CMakeLists.txt ########## @@ -0,0 +1,40 @@ +# +# 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. +# + +file(GLOB PROCFS_TESTS "*.cpp") + +SET(PROCFS_TEST_COUNT 0) +FOREACH(testfile ${PROCFS_TESTS}) + get_filename_component(testfilename "${testfile}" NAME_WE) + add_executable("${testfilename}" "${testfile}") + target_include_directories(${testfilename} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/extensions/standard-processors") + target_include_directories(${testfilename} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/extensions/procfs") + target_include_directories(${testfilename} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/extensions/procfs/procfs_classes") Review comment: the `procfs_classes` directory does not exist ########## File path: extensions/procfs/processors/ProcFsMonitor.cpp ########## @@ -0,0 +1,282 @@ +/** + * @file GenerateFlowFile.cpp Review comment: I would remove this line ########## File path: extensions/procfs/processors/ProcFsMonitor.cpp ########## @@ -0,0 +1,282 @@ +/** + * @file GenerateFlowFile.cpp + * GenerateFlowFile class implementation + * + * 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 "ProcFsMonitor.h" +#include <limits> +#include <utility> +#include <vector> +#include <unordered_map> + +#include "core/Resource.h" +#include "core/ProcessContext.h" +#include "core/ProcessSession.h" +#include "../ProcFsJsonSerialization.h" +#include "utils/JsonCallback.h" +#include "utils/OpenTelemetryLogDataModelUtils.h" +#include "utils/gsl.h" + +using namespace std::literals::chrono_literals; + +namespace org::apache::nifi::minifi::extensions::procfs { + +const core::Relationship ProcFsMonitor::Success("success", "All files are routed to success"); + +const core::Property ProcFsMonitor::OutputFormatProperty( + core::PropertyBuilder::createProperty("Output Format")-> + withDescription("The output type of the new flowfile")-> + withAllowableValues<std::string>(OutputFormat::values())-> + withDefaultValue(toString(OutputFormat::JSON))->build()); + +const core::Property ProcFsMonitor::OutputCompactnessProperty( + core::PropertyBuilder::createProperty("Output Compactness")-> + withDescription("The output format of the new flowfile")-> + withAllowableValues<std::string>(OutputCompactness::values())-> + withDefaultValue(toString(OutputCompactness::PRETTY))->build()); + +const core::Property ProcFsMonitor::DecimalPlaces( + core::PropertyBuilder::createProperty("Round to decimal places")-> + withDescription("The number of decimal places to round the values to (blank for no rounding)")->build()); + +const core::Property ProcFsMonitor::ResultRelativenessProperty( + core::PropertyBuilder::createProperty("Result Type")-> + withDescription("Absolute returns the current procfs values, relative calculates the usage between triggers")-> + withAllowableValues<std::string>(ResultRelativeness::values())-> + withDefaultValue(toString(ResultRelativeness::RELATIVE))->build()); Review comment: typo ```suggestion withDefaultValue(toString(ResultRelativeness::ABSOLUTE))->build()); ``` ########## File path: extensions/procfs/processors/ProcFsMonitor.h ########## @@ -0,0 +1,131 @@ +/** + * 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 <memory> +#include <unordered_map> +#include <vector> +#include <optional> + +#include "../ProcFs.h" +#include "core/Processor.h" +#include "core/logging/LoggerConfiguration.h" +#include "core/logging/Logger.h" +#include "utils/Enum.h" + +#include "rapidjson/stream.h" +#include "rapidjson/document.h" + +namespace org::apache::nifi::minifi::extensions::procfs { + +class ProcFsMonitor : public core::Processor { + public: + explicit ProcFsMonitor(const std::string& name, utils::Identifier uuid = utils::Identifier()) + : Processor(name, uuid) { + } + ProcFsMonitor(const ProcFsMonitor&) = delete; + ProcFsMonitor(ProcFsMonitor&&) = delete; + ProcFsMonitor& operator=(const ProcFsMonitor&) = delete; + ProcFsMonitor& operator=(ProcFsMonitor&&) = delete; + ~ProcFsMonitor() override = default; + + static constexpr char const *ProcessorName = "ProcFsMonitor"; + + EXTENSIONAPI static const core::Property OutputFormatProperty; + EXTENSIONAPI static const core::Property OutputCompactnessProperty; + EXTENSIONAPI static const core::Property DecimalPlaces; + EXTENSIONAPI static const core::Property ResultRelativenessProperty; + + EXTENSIONAPI static const core::Relationship Success; + + + public: + void onSchedule(const std::shared_ptr<core::ProcessContext>& context, const std::shared_ptr<core::ProcessSessionFactory>& sessionFactory) override; + + void onTrigger(core::ProcessContext *context, core::ProcessSession *session) override; + + void initialize() override; + + SMART_ENUM(OutputFormat, + (JSON, "JSON"), + (OPENTELEMETRY, "OpenTelemetry") + ) + + SMART_ENUM(OutputCompactness, + (COMPACT, "Compact"), + (PRETTY, "Pretty") + ) + + SMART_ENUM(ResultRelativeness, + (RELATIVE, "Relative"), + (ABSOLUTE, "Absolute") + ) + + private: + bool isSingleThreaded() const override { + return true; + } + + core::annotation::Input getInputRequirement() const override { + return core::annotation::Input::INPUT_FORBIDDEN; + } + + protected: Review comment: could these functions and fields be private? ```suggestion ``` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
