Skip to content

Commit 185d620

Browse files
committed
remove metric
1 parent d2f51ea commit 185d620

File tree

4 files changed

+1
-266
lines changed

4 files changed

+1
-266
lines changed

include/ylt/standalone/cinatra/coro_http_connection.hpp

+1-63
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,9 @@
2121
#include "sha1.hpp"
2222
#include "string_resize.hpp"
2323
#include "websocket.hpp"
24-
#include "ylt/metric/counter.hpp"
25-
#include "ylt/metric/gauge.hpp"
26-
#include "ylt/metric/histogram.hpp"
27-
#include "ylt/metric/metric.hpp"
2824
#ifdef CINATRA_ENABLE_GZIP
2925
#include "gzip.hpp"
3026
#endif
31-
#include "metric_conf.hpp"
3227
#include "ylt/coro_io/coro_file.hpp"
3328
#include "ylt/coro_io/coro_io.hpp"
3429

@@ -52,14 +47,9 @@ class coro_http_connection
5247
request_(parser_, this),
5348
response_(this) {
5449
buffers_.reserve(3);
55-
56-
cinatra_metric_conf::server_total_fd_inc();
5750
}
5851

59-
~coro_http_connection() {
60-
cinatra_metric_conf::server_total_fd_dec();
61-
close();
62-
}
52+
~coro_http_connection() { close(); }
6353

6454
#ifdef CINATRA_ENABLE_SSL
6555
bool init_ssl(const std::string &cert_file, const std::string &key_file,
@@ -126,20 +116,13 @@ class coro_http_connection
126116
CINATRA_LOG_WARNING << "read http header error: " << ec.message();
127117
}
128118

129-
cinatra_metric_conf::server_failed_req_inc();
130119
close();
131120
break;
132121
}
133122

134-
if (cinatra_metric_conf::enable_metric) {
135-
start = std::chrono::system_clock::now();
136-
cinatra_metric_conf::server_total_req_inc();
137-
}
138-
139123
const char *data_ptr = asio::buffer_cast<const char *>(head_buf_.data());
140124
int head_len = parser_.parse_request(data_ptr, size, 0);
141125
if (head_len <= 0) {
142-
cinatra_metric_conf::server_failed_req_inc();
143126
CINATRA_LOG_ERROR << "parse http header error";
144127
close();
145128
break;
@@ -153,9 +136,6 @@ class coro_http_connection
153136
if (type != content_type::chunked && type != content_type::multipart) {
154137
size_t body_len = parser_.body_len();
155138
if (body_len == 0) {
156-
if (cinatra_metric_conf::enable_metric) {
157-
cinatra_metric_conf::server_total_recv_bytes_inc(head_len);
158-
}
159139
if (parser_.method() == "GET"sv) {
160140
if (request_.is_upgrade()) {
161141
#ifdef CINATRA_ENABLE_GZIP
@@ -175,16 +155,6 @@ class coro_http_connection
175155
}
176156
response_.set_delay(true);
177157
}
178-
else {
179-
if (cinatra_metric_conf::enable_metric) {
180-
mid = std::chrono::system_clock::now();
181-
double count =
182-
std::chrono::duration_cast<std::chrono::microseconds>(mid -
183-
start)
184-
.count();
185-
cinatra_metric_conf::server_read_latency_observe(count);
186-
}
187-
}
188158
}
189159
}
190160
else if (body_len <= head_buf_.size()) {
@@ -194,7 +164,6 @@ class coro_http_connection
194164
memcpy(body_.data(), data_ptr, body_len);
195165
head_buf_.consume(head_buf_.size());
196166
}
197-
cinatra_metric_conf::server_total_recv_bytes_inc(head_len + body_len);
198167
}
199168
else {
200169
size_t part_size = head_buf_.size();
@@ -209,22 +178,9 @@ class coro_http_connection
209178
size_to_read);
210179
if (ec) {
211180
CINATRA_LOG_ERROR << "async_read error: " << ec.message();
212-
cinatra_metric_conf::server_failed_req_inc();
213181
close();
214182
break;
215183
}
216-
else {
217-
if (cinatra_metric_conf::enable_metric) {
218-
cinatra_metric_conf::server_total_recv_bytes_inc(head_len +
219-
body_len);
220-
mid = std::chrono::system_clock::now();
221-
double count =
222-
std::chrono::duration_cast<std::chrono::microseconds>(mid -
223-
start)
224-
.count();
225-
cinatra_metric_conf::server_read_latency_observe(count);
226-
}
227-
}
228184
}
229185
}
230186

@@ -409,14 +365,6 @@ class coro_http_connection
409365
}
410366
}
411367

412-
if (cinatra_metric_conf::enable_metric) {
413-
mid = std::chrono::system_clock::now();
414-
double count =
415-
std::chrono::duration_cast<std::chrono::microseconds>(mid - start)
416-
.count();
417-
cinatra_metric_conf::server_req_latency_observe(count);
418-
}
419-
420368
response_.clear();
421369
request_.clear();
422370
buffers_.clear();
@@ -430,10 +378,6 @@ class coro_http_connection
430378
}
431379

432380
async_simple::coro::Lazy<bool> reply(bool need_to_bufffer = true) {
433-
if (response_.status() >= status_type::bad_request) {
434-
if (cinatra_metric_conf::enable_metric)
435-
cinatra_metric_conf::server_failed_req_inc();
436-
}
437381
std::error_code ec;
438382
size_t size;
439383
if (multi_buf_) {
@@ -444,18 +388,12 @@ class coro_http_connection
444388
for (auto &buf : buffers_) {
445389
send_size += buf.size();
446390
}
447-
if (cinatra_metric_conf::enable_metric) {
448-
cinatra_metric_conf::server_total_send_bytes_inc(send_size);
449-
}
450391
std::tie(ec, size) = co_await async_write(buffers_);
451392
}
452393
else {
453394
if (need_to_bufffer) {
454395
response_.build_resp_str(resp_str_);
455396
}
456-
if (cinatra_metric_conf::enable_metric) {
457-
cinatra_metric_conf::server_total_send_bytes_inc(resp_str_.size());
458-
}
459397
std::tie(ec, size) = co_await async_write(asio::buffer(resp_str_));
460398
}
461399

include/ylt/standalone/cinatra/coro_http_server.hpp

-50
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "ylt/coro_io/coro_io.hpp"
1212
#include "ylt/coro_io/io_context_pool.hpp"
1313
#include "ylt/coro_io/load_blancer.hpp"
14-
#include "ylt/metric/system_metric.hpp"
1514

1615
namespace cinatra {
1716
enum class file_resp_format_type {
@@ -182,29 +181,6 @@ class coro_http_server {
182181
}
183182
}
184183

185-
void use_metrics(bool enable_json = false,
186-
std::string url_path = "/metrics") {
187-
init_metrics();
188-
using root = ylt::metric::metric_collector_t<
189-
ylt::metric::default_static_metric_manager,
190-
ylt::metric::system_metric_manager>;
191-
set_http_handler<http_method::GET>(
192-
url_path,
193-
[enable_json](coro_http_request &req, coro_http_response &res) {
194-
std::string str;
195-
#ifdef CINATRA_ENABLE_METRIC_JSON
196-
if (enable_json) {
197-
str = root::serialize_to_json();
198-
res.set_content_type<resp_content_type::json>();
199-
}
200-
else
201-
#endif
202-
str = root::serialize();
203-
204-
res.set_status_and_content(status_type::ok, std::move(str));
205-
});
206-
}
207-
208184
template <http_method... method, typename... Aspects>
209185
void set_http_proxy_handler(std::string url_path,
210186
std::vector<std::string_view> hosts,
@@ -928,32 +904,6 @@ class coro_http_server {
928904
address_ = std::move(address);
929905
}
930906

931-
private:
932-
void init_metrics() {
933-
using namespace ylt::metric;
934-
935-
cinatra_metric_conf::enable_metric = true;
936-
default_static_metric_manager::instance().create_metric_static<counter_t>(
937-
cinatra_metric_conf::server_total_req, "");
938-
default_static_metric_manager::instance().create_metric_static<counter_t>(
939-
cinatra_metric_conf::server_failed_req, "");
940-
default_static_metric_manager::instance().create_metric_static<counter_t>(
941-
cinatra_metric_conf::server_total_recv_bytes, "");
942-
default_static_metric_manager::instance().create_metric_static<counter_t>(
943-
cinatra_metric_conf::server_total_send_bytes, "");
944-
default_static_metric_manager::instance().create_metric_static<gauge_t>(
945-
cinatra_metric_conf::server_total_fd, "");
946-
default_static_metric_manager::instance().create_metric_static<histogram_t>(
947-
cinatra_metric_conf::server_req_latency, "",
948-
std::vector<double>{30, 40, 50, 60, 70, 80, 90, 100, 150});
949-
default_static_metric_manager::instance().create_metric_static<histogram_t>(
950-
cinatra_metric_conf::server_read_latency, "",
951-
std::vector<double>{3, 5, 7, 9, 13, 18, 23, 35, 50});
952-
#if defined(__GNUC__)
953-
ylt::metric::start_system_metric();
954-
#endif
955-
}
956-
957907
private:
958908
std::unique_ptr<coro_io::io_context_pool> pool_;
959909
asio::io_context *out_ctx_ = nullptr;

include/ylt/standalone/cinatra/metric_conf.hpp

-130
This file was deleted.

website/docs/zh/metric/metric_introduction.md

-23
Original file line numberDiff line numberDiff line change
@@ -618,26 +618,3 @@ test_summary_count 100
618618
然后启动prometheus,prometheus会定时访问`http://127.0.0.1:9001/metrics` 拉取所有指标数据。
619619
620620
在本地浏览器输入:127.0.0.1:9090, 打开prometheus前端,在前端页面的搜索框中输入指标的名称request_count之后就能看到table和graph 结果了。
621-
622-
# cinatra http server中启用内置的metric指标
623-
624-
http server 内置的指标:
625-
```cpp
626-
server_total_req: server总的请求数;
627-
server_failed_req:server总的失败请求数;
628-
server_total_fd:server使用的总的句柄数;
629-
server_total_recv_bytes:server总共收到的字节数;
630-
server_total_send_bytes:server总共发送的字节数;
631-
server_req_latency:http 请求的延迟,从收到请求到发送响应的时间间隔
632-
server_read_latency:http 读请求的延迟,读到完整的http数据的时间间隔
633-
```
634-
635-
```cpp
636-
coro_http_server server(1, 9001);
637-
server.use_metrics("/metrics");//这个url默认就是/metrics,可以不填
638-
```
639-
在浏览器中输入`http://127.0.0.1:9001/metrics` 即可看到所有的指标。
640-
641-
查看当前server的client pool中有多少client,调用`pool.free_client_count()`
642-
643-
查看当前server内部线程池中有多少线程,调用`coro_io::get_total_thread_num()`

0 commit comments

Comments
 (0)