xref: /openbmc/phosphor-health-monitor/health_metric_config.hpp (revision 21883175886b6f2016e319225065b6eb2a838941)
17e11ab0aSJagpal Singh Gill #pragma once
27e11ab0aSJagpal Singh Gill 
367b8ebe0SPatrick Williams #include <sdbusplus/message.hpp>
47e11ab0aSJagpal Singh Gill #include <xyz/openbmc_project/Common/Threshold/server.hpp>
57e11ab0aSJagpal Singh Gill 
67e11ab0aSJagpal Singh Gill #include <chrono>
77e11ab0aSJagpal Singh Gill #include <limits>
87e11ab0aSJagpal Singh Gill #include <map>
97e11ab0aSJagpal Singh Gill #include <string>
107e11ab0aSJagpal Singh Gill #include <vector>
117e11ab0aSJagpal Singh Gill 
127e11ab0aSJagpal Singh Gill namespace phosphor::health::metric
137e11ab0aSJagpal Singh Gill {
147e11ab0aSJagpal Singh Gill 
157e11ab0aSJagpal Singh Gill using ThresholdIntf =
167e11ab0aSJagpal Singh Gill     sdbusplus::server::xyz::openbmc_project::common::Threshold;
177e11ab0aSJagpal Singh Gill 
187e11ab0aSJagpal Singh Gill enum class Type
197e11ab0aSJagpal Singh Gill {
207e11ab0aSJagpal Singh Gill     cpu,
217e11ab0aSJagpal Singh Gill     memory,
227e11ab0aSJagpal Singh Gill     storage,
237e11ab0aSJagpal Singh Gill     inode,
247e11ab0aSJagpal Singh Gill     unknown
257e11ab0aSJagpal Singh Gill };
267e11ab0aSJagpal Singh Gill 
277e11ab0aSJagpal Singh Gill enum class SubType
287e11ab0aSJagpal Singh Gill {
297e11ab0aSJagpal Singh Gill     // CPU subtypes
307e11ab0aSJagpal Singh Gill     cpuKernel,
317e11ab0aSJagpal Singh Gill     cpuTotal,
327e11ab0aSJagpal Singh Gill     cpuUser,
337e11ab0aSJagpal Singh Gill     // Memory subtypes
347e11ab0aSJagpal Singh Gill     memoryAvailable,
357e11ab0aSJagpal Singh Gill     memoryBufferedAndCached,
367e11ab0aSJagpal Singh Gill     memoryFree,
377e11ab0aSJagpal Singh Gill     memoryShared,
387e11ab0aSJagpal Singh Gill     memoryTotal,
3997582801SJagpal Singh Gill     // Types for which subtype is not applicable
407e11ab0aSJagpal Singh Gill     NA
417e11ab0aSJagpal Singh Gill };
427e11ab0aSJagpal Singh Gill 
4367b8ebe0SPatrick Williams auto to_string(Type) -> std::string;
4467b8ebe0SPatrick Williams auto to_string(SubType) -> std::string;
4567b8ebe0SPatrick Williams 
467e11ab0aSJagpal Singh Gill namespace config
477e11ab0aSJagpal Singh Gill {
487e11ab0aSJagpal Singh Gill 
497e11ab0aSJagpal Singh Gill using namespace std::literals::chrono_literals;
507e11ab0aSJagpal Singh Gill 
517e11ab0aSJagpal Singh Gill struct Threshold
527e11ab0aSJagpal Singh Gill {
537e11ab0aSJagpal Singh Gill     double value = defaults::value;
547e11ab0aSJagpal Singh Gill     bool log = false;
557e11ab0aSJagpal Singh Gill     std::string target = defaults::target;
567e11ab0aSJagpal Singh Gill 
577e11ab0aSJagpal Singh Gill     using map_t =
587e11ab0aSJagpal Singh Gill         std::map<std::tuple<ThresholdIntf::Type, ThresholdIntf::Bound>,
597e11ab0aSJagpal Singh Gill                  Threshold>;
607e11ab0aSJagpal Singh Gill 
617e11ab0aSJagpal Singh Gill     struct defaults
627e11ab0aSJagpal Singh Gill     {
637e11ab0aSJagpal Singh Gill         static constexpr auto value = std::numeric_limits<double>::quiet_NaN();
647e11ab0aSJagpal Singh Gill         static constexpr auto target = "";
657e11ab0aSJagpal Singh Gill     };
667e11ab0aSJagpal Singh Gill };
677e11ab0aSJagpal Singh Gill 
687e11ab0aSJagpal Singh Gill struct HealthMetric
697e11ab0aSJagpal Singh Gill {
707e11ab0aSJagpal Singh Gill     /** @brief The name of the metric. */
717e11ab0aSJagpal Singh Gill     std::string name = "unnamed";
727e11ab0aSJagpal Singh Gill     /** @brief The metric subtype. */
737e11ab0aSJagpal Singh Gill     SubType subType = SubType::NA;
747e11ab0aSJagpal Singh Gill     /** @brief The window size for the metric. */
757e11ab0aSJagpal Singh Gill     size_t windowSize = defaults::windowSize;
76a102762bSJagpal Singh Gill     /** @brief The hysteresis for the metric */
77a102762bSJagpal Singh Gill     double hysteresis = defaults::hysteresis;
787e11ab0aSJagpal Singh Gill     /** @brief The threshold configs for the metric. */
797e11ab0aSJagpal Singh Gill     Threshold::map_t thresholds{};
807e11ab0aSJagpal Singh Gill     /** @brief The path for filesystem metric */
817e11ab0aSJagpal Singh Gill     std::string path = defaults::path;
827e11ab0aSJagpal Singh Gill 
837e11ab0aSJagpal Singh Gill     using map_t = std::map<Type, std::vector<HealthMetric>>;
847e11ab0aSJagpal Singh Gill 
857e11ab0aSJagpal Singh Gill     struct defaults
867e11ab0aSJagpal Singh Gill     {
87*21883175SJagpal Singh Gill         static constexpr auto windowSize = 120;
887e11ab0aSJagpal Singh Gill         static constexpr auto path = "";
89a102762bSJagpal Singh Gill         static constexpr auto hysteresis = 1.0;
907e11ab0aSJagpal Singh Gill     };
917e11ab0aSJagpal Singh Gill };
927e11ab0aSJagpal Singh Gill 
937e11ab0aSJagpal Singh Gill /** @brief Get the health metric configs. */
947e11ab0aSJagpal Singh Gill auto getHealthMetricConfigs() -> HealthMetric::map_t;
957e11ab0aSJagpal Singh Gill 
967e11ab0aSJagpal Singh Gill } // namespace config
977e11ab0aSJagpal Singh Gill } // namespace phosphor::health::metric
98