Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed May 10, 2024
1 parent e8ffb5b commit b7fa272
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <vector>

#include "../include/cinatra.hpp"
#include "cinatra/ylt/metric/guage.hpp"
#include "cinatra/ylt/metric/gauge.hpp"
#include "cinatra/ylt/metric/histogram.hpp"
#include "cinatra/ylt/metric/summary.hpp"

Expand Down Expand Up @@ -388,7 +388,7 @@ async_simple::coro::Lazy<void> basic_usage() {
void use_metric() {
auto c = std::make_shared<counter_t>("request_count", "request count",
std::vector{"method", "url"});
auto failed = std::make_shared<guage_t>("not_found_request_count",
auto failed = std::make_shared<gauge_t>("not_found_request_count",
"not found request count",
std::vector{"method", "code", "url"});
auto total =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
#include "counter.hpp"

namespace cinatra {
class guage_t : public counter_t {
class gauge_t : public counter_t {
public:
guage_t() = default;
guage_t(std::string name, std::string help,
gauge_t() = default;
gauge_t(std::string name, std::string help,
std::vector<std::string> labels_name = {})
: counter_t(std::move(name), std::move(help), std::move(labels_name)) {
set_metric_type(MetricType::Guage);
}

guage_t(const char* name, const char* help,
gauge_t(const char* name, const char* help,
std::vector<const char*> labels_name = {})
: guage_t(
: gauge_t(
std::string(name), std::string(help),
std::vector<std::string>(labels_name.begin(), labels_name.end())) {}

Expand Down
4 changes: 2 additions & 2 deletions include/cinatra/ylt/metric/histogram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class histogram_t : public metric_t {
histogram_t(std::string name, std::string help, std::vector<double> buckets)
: bucket_boundaries_(buckets),
metric_t(MetricType::Histogram, std::move(name), std::move(help)),
sum_(std::make_shared<guage_t>()) {
sum_(std::make_shared<gauge_t>()) {
if (!is_strict_sorted(begin(bucket_boundaries_), end(bucket_boundaries_))) {
throw std::invalid_argument("Bucket Boundaries must be strictly sorted");
}
Expand Down Expand Up @@ -118,6 +118,6 @@ class histogram_t : public metric_t {
std::vector<double> bucket_boundaries_;
std::mutex mutex_;
std::vector<std::shared_ptr<counter_t>> bucket_counts_;
std::shared_ptr<guage_t> sum_;
std::shared_ptr<gauge_t> sum_;
};
} // namespace cinatra
4 changes: 2 additions & 2 deletions lang/metrict_introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ prometheus_tsdb_wal_fsync_duration_seconds_sum 2.888716127000002
prometheus_tsdb_wal_fsync_duration_seconds_count 216
```

# 如何使用cinatra的 metric功能
# 如何使用metric功能

## 使用counter指标统计http 请求总数
http 请求数量随着时间推移是不断增加的,不可能会减少,因此使用counter类型的指标是合适的,如果数量可能会减少则应该使用guage类型的指标。
Expand Down Expand Up @@ -193,7 +193,7 @@ guage和counter的用法几乎一样,guage比counter多了一个dec方法用

创建一个guage:
```cpp
auto g = std::make_shared<guage_t>("not_found_request_count",
auto g = std::make_shared<gauge_t>("not_found_request_count",
"not found request count",
std::vector{"method", "code", "url"});
metric_t::regiter_metric(g);
Expand Down
10 changes: 5 additions & 5 deletions tests/test_metric.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "cinatra/ylt/metric/guage.hpp"
#include "cinatra/ylt/metric/gauge.hpp"
#define DOCTEST_CONFIG_IMPLEMENT
#include <random>

Expand Down Expand Up @@ -34,7 +34,7 @@ TEST_CASE("test counter") {
auto c = std::make_shared<counter_t>("get_count", "get counter",
std::vector{"method", "code"});
CHECK(c->name() == "get_count");
auto g = std::make_shared<guage_t>("get_count", "get counter",
auto g = std::make_shared<gauge_t>("get_count", "get counter",
std::vector{"method", "code"});
CHECK(g->name() == "get_count");
CHECK(g->metric_name() == "guage");
Expand Down Expand Up @@ -67,7 +67,7 @@ TEST_CASE("test counter") {

TEST_CASE("test guage") {
{
guage_t g("get_count", "get counter");
gauge_t g("get_count", "get counter");
CHECK(g.metric_type() == MetricType::Guage);
CHECK(g.labels_name().empty());
g.inc();
Expand All @@ -83,7 +83,7 @@ TEST_CASE("test guage") {
}

{
guage_t g("get_count", "get counter", {"method", "code", "url"});
gauge_t g("get_count", "get counter", {"method", "code", "url"});
CHECK(g.labels_name() == std::vector<std::string>{"method", "code", "url"});
// method, status code, url
g.inc({"GET", "200", "/"}, 1);
Expand Down Expand Up @@ -155,7 +155,7 @@ TEST_CASE("test register metric") {
metric_t::regiter_metric(c);
CHECK_THROWS_AS(metric_t::regiter_metric(c), std::invalid_argument);

auto g = std::make_shared<guage_t>(std::string("get_guage_count"),
auto g = std::make_shared<gauge_t>(std::string("get_guage_count"),
std::string("get counter"));
metric_t::regiter_metric(g);

Expand Down

0 comments on commit b7fa272

Please sign in to comment.