blob: 49f39ad95cedeafc516de0bd95f3d9fd07400651 [file] [log] [blame]
Jagpal Singh Gill7e11ab02023-12-08 11:41:41 -08001#pragma once
2
3#include <xyz/openbmc_project/Common/Threshold/server.hpp>
4
5#include <chrono>
6#include <limits>
7#include <map>
8#include <string>
9#include <vector>
10
11namespace phosphor::health::metric
12{
13
14using ThresholdIntf =
15 sdbusplus::server::xyz::openbmc_project::common::Threshold;
16
17enum class Type
18{
19 cpu,
20 memory,
21 storage,
22 inode,
23 unknown
24};
25
26enum class SubType
27{
28 // CPU subtypes
29 cpuKernel,
30 cpuTotal,
31 cpuUser,
32 // Memory subtypes
33 memoryAvailable,
34 memoryBufferedAndCached,
35 memoryFree,
36 memoryShared,
37 memoryTotal,
38 // Storage subtypes
39 storageReadWrite,
Jagpal Singh Gilldfe839f2024-02-16 09:54:02 -080040 storageTmp,
Jagpal Singh Gill7e11ab02023-12-08 11:41:41 -080041 NA
42};
43
44namespace config
45{
46
47using namespace std::literals::chrono_literals;
48
49struct Threshold
50{
51 double value = defaults::value;
52 bool log = false;
53 std::string target = defaults::target;
54
55 using map_t =
56 std::map<std::tuple<ThresholdIntf::Type, ThresholdIntf::Bound>,
57 Threshold>;
58
59 struct defaults
60 {
61 static constexpr auto value = std::numeric_limits<double>::quiet_NaN();
62 static constexpr auto target = "";
63 };
64};
65
66struct HealthMetric
67{
68 /** @brief The name of the metric. */
69 std::string name = "unnamed";
70 /** @brief The metric subtype. */
71 SubType subType = SubType::NA;
72 /** @brief The collection frequency for the metric. */
73 std::chrono::seconds collectionFreq = defaults::frequency;
74 /** @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 {
85 static constexpr auto frequency = 1s;
86 static constexpr auto windowSize = 1;
87 static constexpr auto path = "";
88 };
89};
90
91/** @brief Get the health metric configs. */
92auto getHealthMetricConfigs() -> HealthMetric::map_t;
93
94} // namespace config
95} // namespace phosphor::health::metric