blob: 5943878a5145317492c918646201618fddbed9df [file] [log] [blame]
Jagpal Singh Gill7e11ab02023-12-08 11:41:41 -08001#pragma once
2
Patrick Williams67b8ebe2024-02-23 20:40:52 -06003#include <sdbusplus/message.hpp>
Jagpal Singh Gill7e11ab02023-12-08 11:41:41 -08004#include <xyz/openbmc_project/Common/Threshold/server.hpp>
5
6#include <chrono>
7#include <limits>
8#include <map>
9#include <string>
10#include <vector>
11
12namespace phosphor::health::metric
13{
14
15using ThresholdIntf =
16 sdbusplus::server::xyz::openbmc_project::common::Threshold;
17
18enum class Type
19{
20 cpu,
21 memory,
22 storage,
23 inode,
24 unknown
25};
26
27enum class SubType
28{
29 // CPU subtypes
30 cpuKernel,
31 cpuTotal,
32 cpuUser,
33 // Memory subtypes
34 memoryAvailable,
35 memoryBufferedAndCached,
36 memoryFree,
37 memoryShared,
38 memoryTotal,
Jagpal Singh Gill97582802024-02-27 13:59:11 -080039 // Types for which subtype is not applicable
Jagpal Singh Gill7e11ab02023-12-08 11:41:41 -080040 NA
41};
42
Patrick Williams67b8ebe2024-02-23 20:40:52 -060043auto to_string(Type) -> std::string;
44auto to_string(SubType) -> std::string;
45
Jagpal Singh Gill7e11ab02023-12-08 11:41:41 -080046namespace config
47{
48
49using namespace std::literals::chrono_literals;
50
51struct Threshold
52{
53 double value = defaults::value;
54 bool log = false;
55 std::string target = defaults::target;
56
57 using map_t =
58 std::map<std::tuple<ThresholdIntf::Type, ThresholdIntf::Bound>,
59 Threshold>;
60
61 struct defaults
62 {
63 static constexpr auto value = std::numeric_limits<double>::quiet_NaN();
64 static constexpr auto target = "";
65 };
66};
67
68struct HealthMetric
69{
70 /** @brief The name of the metric. */
71 std::string name = "unnamed";
72 /** @brief The metric subtype. */
73 SubType subType = SubType::NA;
Jagpal Singh Gill7e11ab02023-12-08 11:41:41 -080074 /** @brief The window size for the metric. */
75 size_t windowSize = defaults::windowSize;
76 /** @brief The threshold configs for the metric. */
77 Threshold::map_t thresholds{};
78 /** @brief The path for filesystem metric */
79 std::string path = defaults::path;
80
81 using map_t = std::map<Type, std::vector<HealthMetric>>;
82
83 struct defaults
84 {
Jagpal Singh Gill7e11ab02023-12-08 11:41:41 -080085 static constexpr auto windowSize = 1;
86 static constexpr auto path = "";
87 };
88};
89
90/** @brief Get the health metric configs. */
91auto getHealthMetricConfigs() -> HealthMetric::map_t;
92
93} // namespace config
94} // namespace phosphor::health::metric