forked from yqzhang/treadmill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreadmillFB303.h
73 lines (56 loc) · 1.71 KB
/
TreadmillFB303.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#pragma once
#include <memory>
#include <folly/SharedMutex.h>
#include <folly/Singleton.h>
#include "common/fb303/if/gen-cpp2/FacebookService.h"
#include "treadmill/StatisticsManager.h"
namespace facebook {
namespace windtunnel {
namespace treadmill {
// TODO(14039001): commonize this so other treadmills can use it
class TreadmillFB303 : public facebook::fb303::cpp2::FacebookServiceSvIf {
public:
using fb_status = facebook::fb303::cpp2::fb_status;
explicit TreadmillFB303()
: status_(fb_status::STARTING),
aliveSince_(time(nullptr)) {}
~TreadmillFB303() override {}
void setStatus(fb_status status) {
folly::SharedMutex::WriteHolder(mutex_);
status_ = status;
}
fb_status getStatus() override {
folly::SharedMutex::ReadHolder(mutex_);
return status_;
}
void getStatusDetails(std::string& _return) override {
_return = fb303::cpp2::_fb_status_VALUES_TO_NAMES.at(getStatus());
}
int64_t aliveSince() override {
folly::SharedMutex::ReadHolder(mutex_);
return aliveSince_;
}
void getCounters(std::map<std::string, int64_t>& _return) override {
_return = StatisticsManager::exportAllCounters();
}
static void make_fb303(
std::shared_ptr<std::thread>& server_thread,
int server_port);
private:
fb_status status_;
const int64_t aliveSince_;
folly::SharedMutex mutex_;
};
extern std::shared_ptr<TreadmillFB303> getGlobalTreadmillFB303();
}
}
}