blob: 6391462041abcb6915825ba531a729faf8abb643 [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,
39 // Storage subtypes
40 storageReadWrite,
Jagpal Singh Gilldfe839f2024-02-16 09:54:02 -080041 storageTmp,
Jagpal Singh Gill7e11ab02023-12-08 11:41:41 -080042 NA
43};
44
Patrick Williams67b8ebe2024-02-23 20:40:52 -060045auto to_string(Type) -> std::string;
46auto to_string(SubType) -> std::string;
47
Jagpal Singh Gill7e11ab02023-12-08 11:41:41 -080048namespace config
49{
50
51using namespace std::literals::chrono_literals;
52
53struct Threshold
54{
55 double value = defaults::value;
56 bool log = false;
57 std::string target = defaults::target;
58
59 using map_t =
60 std::map<std::tuple<ThresholdIntf::Type, ThresholdIntf::Bound>,
61 Threshold>;
62
63 struct defaults
64 {
65 static constexpr auto value = std::numeric_limits<double>::quiet_NaN();
66 static constexpr auto target = "";
67 };
68};
69
70struct HealthMetric
71{
72 /** @brief The name of the metric. */
73 std::string name = "unnamed";
74 /** @brief The metric subtype. */
75 SubType subType = SubType::NA;
76 /** @brief The collection frequency for the metric. */
77 std::chrono::seconds collectionFreq = defaults::frequency;
78 /** @brief The window size for the metric. */
79 size_t windowSize = defaults::windowSize;
80 /** @brief The threshold configs for the metric. */
81 Threshold::map_t thresholds{};
82 /** @brief The path for filesystem metric */
83 std::string path = defaults::path;
84
85 using map_t = std::map<Type, std::vector<HealthMetric>>;
86
87 struct defaults
88 {
89 static constexpr auto frequency = 1s;
90 static constexpr auto windowSize = 1;
91 static constexpr auto path = "";
92 };
93};
94
95/** @brief Get the health metric configs. */
96auto getHealthMetricConfigs() -> HealthMetric::map_t;
97
98} // namespace config
99} // namespace phosphor::health::metric