]>
git.proxmox.com Git - ceph.git/blob - ceph/src/exporter/util.cc
3 #include <boost/algorithm/string/classification.hpp>
4 #include <boost/algorithm/string/replace.hpp>
11 #include "common/debug.h"
13 #define dout_context g_ceph_context
14 #define dout_subsys ceph_subsys_ceph_exporter
16 BlockTimer::BlockTimer(std::string file
, std::string function
)
17 : file(file
), function(function
), stopped(false) {
18 t1
= std::chrono::high_resolution_clock::now();
20 BlockTimer::~BlockTimer() {
21 dout(20) << file
<< ":" << function
<< ": " << ms
.count() << "ms" << dendl
;
25 double BlockTimer::get_ms() {
29 // Manually stop the timer as you might want to get the time
30 void BlockTimer::stop() {
33 t2
= std::chrono::high_resolution_clock::now();
38 bool string_is_digit(std::string s
) {
40 while (std::isdigit(s
[i
]) && i
< s
.size()) {
46 std::string
read_file_to_string(std::string path
) {
47 std::ifstream
is(path
);
48 std::stringstream buffer
;
53 // Must be kept in sync with promethize() in src/pybind/mgr/prometheus/module.py
54 void promethize(std::string
&name
) {
55 if (name
[name
.size() - 1] == '-') {
56 name
[name
.size() - 1] = '_';
60 auto should_be_underscore
= [](char ch
) {
61 return ch
== '.' || ch
== '/' || ch
== ' ' || ch
== '-';
63 std::replace_if(name
.begin(), name
.end(), should_be_underscore
, '_');
65 boost::replace_all(name
, "::", "_");
66 boost::replace_all(name
, "+", "_plus");
68 name
= "ceph_" + name
;