generated from Warchant/cmake-hunter-seed
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: turuslan <turuslan.devbox@gmail.com>
- Loading branch information
Showing
11 changed files
with
279 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <prometheus/histogram.h> | ||
#include <prometheus/registry.h> | ||
|
||
namespace fc { | ||
inline auto &prometheusRegistry() { | ||
static prometheus::Registry x; | ||
return x; | ||
} | ||
|
||
constexpr std::initializer_list<double> kDefaultPrometheusMsBuckets{ | ||
0.01, 0.05, 0.1, 0.3, 0.6, 0.8, 1, 2, 3, 4, 5, | ||
6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, | ||
80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, | ||
1000, 2000, 3000, 4000, 5000, 7500, 10000, 20000, 50000, 100000, | ||
}; | ||
} // namespace fc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "api/rpc/rpc.hpp" | ||
#include "common/prometheus/metrics.hpp" | ||
#include "common/prometheus/since.hpp" | ||
|
||
namespace fc::api::rpc { | ||
inline auto &metricApiTime() { | ||
static auto &x{prometheus::BuildHistogram() | ||
.Name("lotus_api_request_duration_ms") | ||
.Help("Duration of API requests") | ||
.Register(prometheusRegistry())}; | ||
return x; | ||
} | ||
|
||
inline Method metricApiTime(std::string name, Method f) { | ||
return [name{std::move(name)}, f{std::move(f)}]( | ||
const Value &value, | ||
Respond respond, | ||
MakeChan make_chan, | ||
Send send, | ||
const Permissions &permissions) { | ||
f( | ||
value, | ||
[name{std::move(name)}, respond{std::move(respond)}, since{Since{}}]( | ||
auto &&value) { | ||
const auto time{since.ms()}; | ||
metricApiTime() | ||
.Add({{"endpoint", name}}, kDefaultPrometheusMsBuckets) | ||
.Observe(time); | ||
respond(std::move(value)); | ||
}, | ||
std::move(make_chan), | ||
std::move(send), | ||
permissions); | ||
}; | ||
} | ||
|
||
inline void metricApiTime(Rpc &rpc) { | ||
for (auto &[name, value] : rpc.ms) { | ||
value = metricApiTime(name, value); | ||
} | ||
} | ||
} // namespace fc::api::rpc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <chrono> | ||
|
||
namespace fc { | ||
struct Since { | ||
using Clock = std::chrono::steady_clock; | ||
|
||
Clock::time_point start{Clock::now()}; | ||
|
||
template <typename T = double> | ||
T ms() const { | ||
return std::chrono::duration_cast<std::chrono::duration<T, std::milli>>( | ||
Clock::now() - start) | ||
.count(); | ||
} | ||
}; | ||
} // namespace fc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.