Remove typedef decl errors
[hiphop-php.git] / hphp / util / health-monitor-types.h
blobb4cac08b7d3bb11a37b9da5c2c45b724946ff226
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_HOST_HEALTH_MONITOR_TYPES_H_
18 #define incl_HPHP_HOST_HEALTH_MONITOR_TYPES_H_
20 #include <string>
22 #include <folly/Likely.h>
24 namespace HPHP {
25 ////////////////////////////////////////////////////////////////////////////////
28 * The enum type for describing various system health level. The
29 * system health monitor will expose one of the listed health level.
31 * Beware if you change the order or the numerical values, as we
32 * assume smaller numbers indicating better health condition here.
34 enum class HealthLevel {
35 Bold = 0,
36 Moderate = 1,
37 Cautious = 2,
38 NoMore = 3,
39 BackOff = 4,
40 NumLevels = 5 // insert new values before NumLevels
44 * The interface of specific system metrics used by the system health
45 * monitor.
47 struct IHealthMonitorMetric {
48 virtual ~IHealthMonitorMetric() {}
49 virtual HealthLevel evaluate() = 0;
50 virtual bool enabled() = 0;
51 void registerSelf(); // register the metric in the monitor
55 * The interface for observers which subscribe the output of the
56 * system health monitor.
58 struct IHostHealthObserver {
59 virtual ~IHostHealthObserver() {}
60 virtual void notifyNewStatus(HealthLevel newStatus) = 0;
61 virtual HealthLevel getHealthLevel() = 0;
65 * Helper function to convert HealthLevel enum value to integer number that is
66 * bigger for better health condition.
68 inline int64_t healthLevelToInt(HealthLevel level) {
69 constexpr int32_t kMaxHealth = 100;
70 // Smaller HealthLevel indicates better health condition, under
71 // which this function returns a bigger number.
72 static_assert(static_cast<int>(HealthLevel::Bold) == 0, "");
73 constexpr int32_t kMaxLevel =
74 static_cast<int32_t>(HealthLevel::NumLevels) - 1;
75 if (LIKELY(level == HealthLevel::Bold)) {
76 return kMaxHealth;
78 auto const result = kMaxHealth *
79 (kMaxLevel - static_cast<int32_t>(level)) / kMaxLevel;
80 return result;
83 ////////////////////////////////////////////////////////////////////////////////
86 #endif