PrometheusMetrics.h 28.4 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

Y
yu yunfeng 已提交
18 19 20
#pragma once

#include <prometheus/exposer.h>
S
starlord 已提交
21
#include <prometheus/registry.h>
K
kun yu 已提交
22
#include <iostream>
S
starlord 已提交
23
#include <memory>
S
starlord 已提交
24
#include <string>
S
starlord 已提交
25
#include <vector>
26

27
#include "metrics/MetricBase.h"
S
starlord 已提交
28
#include "utils/Error.h"
Y
yu yunfeng 已提交
29 30

#define METRICS_NOW_TIME std::chrono::system_clock::now()
31
//#define server::Metrics::GetInstance() server::GetInstance()
S
starlord 已提交
32
#define METRICS_MICROSECONDS(a, b) (std::chrono::duration_cast<std::chrono::microseconds>(b - a)).count();
Y
yu yunfeng 已提交
33

J
jinhai 已提交
34
namespace milvus {
Y
yu yunfeng 已提交
35 36
namespace server {

S
starlord 已提交
37
class PrometheusMetrics : public MetricsBase {
Y
yu yunfeng 已提交
38
 public:
S
starlord 已提交
39
    static PrometheusMetrics&
Y
yu yunfeng 已提交
40 41 42 43 44
    GetInstance() {
        static PrometheusMetrics instance;
        return instance;
    }

S
starlord 已提交
45 46
    ErrorCode
    Init();
Y
yu yunfeng 已提交
47 48 49 50 51

 private:
    std::shared_ptr<prometheus::Exposer> exposer_ptr_;
    std::shared_ptr<prometheus::Registry> registry_ = std::make_shared<prometheus::Registry>();
    bool startup_ = false;
S
starlord 已提交
52

Y
yu yunfeng 已提交
53
 public:
S
starlord 已提交
54 55
    void
    SetStartup(bool startup) {
S
starlord 已提交
56 57 58
        startup_ = startup;
    }

S
starlord 已提交
59 60
    void
    AddVectorsSuccessTotalIncrement(double value = 1.0) override {
S
starlord 已提交
61 62 63 64 65
        if (startup_) {
            add_vectors_success_total_.Increment(value);
        }
    }

S
starlord 已提交
66 67
    void
    AddVectorsFailTotalIncrement(double value = 1.0) override {
S
starlord 已提交
68 69 70 71 72
        if (startup_) {
            add_vectors_fail_total_.Increment(value);
        }
    }

S
starlord 已提交
73 74
    void
    AddVectorsDurationHistogramOberve(double value) override {
S
starlord 已提交
75 76 77 78 79
        if (startup_) {
            add_vectors_duration_histogram_.Observe(value);
        }
    }

S
starlord 已提交
80 81
    void
    RawFileSizeHistogramObserve(double value) override {
S
starlord 已提交
82 83 84 85 86
        if (startup_) {
            raw_files_size_histogram_.Observe(value);
        }
    }

S
starlord 已提交
87 88
    void
    IndexFileSizeHistogramObserve(double value) override {
S
starlord 已提交
89 90 91 92 93
        if (startup_) {
            index_files_size_histogram_.Observe(value);
        }
    }

S
starlord 已提交
94 95
    void
    BuildIndexDurationSecondsHistogramObserve(double value) override {
S
starlord 已提交
96 97 98 99 100
        if (startup_) {
            build_index_duration_seconds_histogram_.Observe(value);
        }
    }

S
starlord 已提交
101 102
    void
    CpuCacheUsageGaugeSet(double value) override {
S
starlord 已提交
103 104 105 106 107
        if (startup_) {
            cpu_cache_usage_gauge_.Set(value);
        }
    }

S
starlord 已提交
108 109
    void
    GpuCacheUsageGaugeSet() override;
Y
yu yunfeng 已提交
110

S
starlord 已提交
111 112
    void
    MetaAccessTotalIncrement(double value = 1) override {
S
starlord 已提交
113 114 115 116 117
        if (startup_) {
            meta_access_total_.Increment(value);
        }
    }

S
starlord 已提交
118 119
    void
    MetaAccessDurationSecondsHistogramObserve(double value) override {
S
starlord 已提交
120 121 122 123 124
        if (startup_) {
            meta_access_duration_seconds_histogram_.Observe(value);
        }
    }

S
starlord 已提交
125 126
    void
    FaissDiskLoadDurationSecondsHistogramObserve(double value) override {
S
starlord 已提交
127 128 129 130 131
        if (startup_) {
            faiss_disk_load_duration_seconds_histogram_.Observe(value);
        }
    }

S
starlord 已提交
132 133
    void
    FaissDiskLoadSizeBytesHistogramObserve(double value) override {
S
starlord 已提交
134 135 136 137 138
        if (startup_) {
            faiss_disk_load_size_bytes_histogram_.Observe(value);
        }
    }

S
starlord 已提交
139 140
    void
    FaissDiskLoadIOSpeedGaugeSet(double value) override {
S
starlord 已提交
141 142 143 144 145
        if (startup_) {
            faiss_disk_load_IO_speed_gauge_.Set(value);
        }
    }

S
starlord 已提交
146 147
    void
    CacheAccessTotalIncrement(double value = 1) override {
S
starlord 已提交
148 149 150 151 152
        if (startup_) {
            cache_access_total_.Increment(value);
        }
    }

S
starlord 已提交
153 154
    void
    MemTableMergeDurationSecondsHistogramObserve(double value) override {
S
starlord 已提交
155 156 157 158 159
        if (startup_) {
            mem_table_merge_duration_seconds_histogram_.Observe(value);
        }
    }

S
starlord 已提交
160 161
    void
    SearchIndexDataDurationSecondsHistogramObserve(double value) override {
S
starlord 已提交
162 163 164 165 166
        if (startup_) {
            search_index_data_duration_seconds_histogram_.Observe(value);
        }
    }

S
starlord 已提交
167 168
    void
    SearchRawDataDurationSecondsHistogramObserve(double value) override {
S
starlord 已提交
169 170 171 172 173
        if (startup_) {
            search_raw_data_duration_seconds_histogram_.Observe(value);
        }
    }

S
starlord 已提交
174 175
    void
    IndexFileSizeTotalIncrement(double value = 1) override {
S
starlord 已提交
176 177 178 179 180
        if (startup_) {
            index_file_size_total_.Increment(value);
        }
    }

S
starlord 已提交
181 182
    void
    RawFileSizeTotalIncrement(double value = 1) override {
S
starlord 已提交
183 184 185 186 187
        if (startup_) {
            raw_file_size_total_.Increment(value);
        }
    }

S
starlord 已提交
188 189
    void
    IndexFileSizeGaugeSet(double value) override {
S
starlord 已提交
190 191 192 193 194
        if (startup_) {
            index_file_size_gauge_.Set(value);
        }
    }

S
starlord 已提交
195 196
    void
    RawFileSizeGaugeSet(double value) override {
S
starlord 已提交
197 198 199 200 201
        if (startup_) {
            raw_file_size_gauge_.Set(value);
        }
    }

S
starlord 已提交
202 203
    void
    QueryResponseSummaryObserve(double value) override {
S
starlord 已提交
204 205 206 207 208
        if (startup_) {
            query_response_summary_.Observe(value);
        }
    }

S
starlord 已提交
209 210
    void
    DiskStoreIOSpeedGaugeSet(double value) override {
S
starlord 已提交
211 212 213 214 215
        if (startup_) {
            disk_store_IO_speed_gauge_.Set(value);
        }
    }

S
starlord 已提交
216 217
    void
    DataFileSizeGaugeSet(double value) override {
S
starlord 已提交
218 219 220 221 222
        if (startup_) {
            data_file_size_gauge_.Set(value);
        }
    }

S
starlord 已提交
223 224
    void
    AddVectorsSuccessGaugeSet(double value) override {
S
starlord 已提交
225 226 227 228 229
        if (startup_) {
            add_vectors_success_gauge_.Set(value);
        }
    }

S
starlord 已提交
230 231
    void
    AddVectorsFailGaugeSet(double value) override {
S
starlord 已提交
232 233 234 235 236
        if (startup_) {
            add_vectors_fail_gauge_.Set(value);
        }
    }

S
starlord 已提交
237 238
    void
    QueryVectorResponseSummaryObserve(double value, int count = 1) override {
S
starlord 已提交
239 240 241 242 243 244 245
        if (startup_) {
            for (int i = 0; i < count; ++i) {
                query_vector_response_summary_.Observe(value);
            }
        }
    }

S
starlord 已提交
246 247
    void
    QueryVectorResponsePerSecondGaugeSet(double value) override {
S
starlord 已提交
248 249 250 251 252
        if (startup_) {
            query_vector_response_per_second_gauge_.Set(value);
        }
    }

S
starlord 已提交
253 254 255 256
    void
    CPUUsagePercentSet() override;
    void
    CPUCoreUsagePercentSet() override;
K
kun yu 已提交
257

S
starlord 已提交
258 259
    void
    RAMUsagePercentSet() override;
S
starlord 已提交
260

S
starlord 已提交
261 262
    void
    QueryResponsePerSecondGaugeSet(double value) override {
S
starlord 已提交
263 264 265 266 267
        if (startup_) {
            query_response_per_second_gauge.Set(value);
        }
    }

S
starlord 已提交
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
    void
    GPUPercentGaugeSet() override;
    void
    GPUMemoryUsageGaugeSet() override;
    void
    AddVectorsPerSecondGaugeSet(int num_vector, int dim, double time) override;
    void
    QueryIndexTypePerSecondSet(std::string type, double value) override;
    void
    ConnectionGaugeIncrement() override;
    void
    ConnectionGaugeDecrement() override;

    void
    KeepingAliveCounterIncrement(double value = 1) override {
S
starlord 已提交
283 284 285 286 287
        if (startup_) {
            keeping_alive_counter_.Increment(value);
        }
    }

S
starlord 已提交
288 289
    void
    OctetsSet() override;
Y
yu yunfeng 已提交
290

S
starlord 已提交
291 292 293 294
    void
    GPUTemperature() override;
    void
    CPUTemperature() override;
K
kun yu 已提交
295

S
starlord 已提交
296 297
    std::shared_ptr<prometheus::Exposer>&
    exposer_ptr() {
S
starlord 已提交
298 299 300
        return exposer_ptr_;
    }

S
starlord 已提交
301 302 303
    //    prometheus::Exposer& exposer() { return exposer_;}
    std::shared_ptr<prometheus::Registry>&
    registry_ptr() {
S
starlord 已提交
304 305
        return registry_;
    }
Y
yu yunfeng 已提交
306 307 308 309

    // .....
 private:
    ////all from db_connection.cpp
S
starlord 已提交
310 311 312 313 314
    //    prometheus::Family<prometheus::Counter> &connect_request_ = prometheus::BuildCounter()
    //        .Name("connection_total")
    //        .Help("total number of connection has been made")
    //        .Register(*registry_);
    //    prometheus::Counter &connection_total_ = connect_request_.Add({});
Y
yu yunfeng 已提交
315 316 317

    ////all from DBImpl.cpp
    using BucketBoundaries = std::vector<double>;
S
starlord 已提交
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
    // record add_group request
    prometheus::Family<prometheus::Counter>& add_group_request_ = prometheus::BuildCounter()
                                                                      .Name("add_group_request_total")
                                                                      .Help("the number of add_group request")
                                                                      .Register(*registry_);

    prometheus::Counter& add_group_success_total_ = add_group_request_.Add({{"outcome", "success"}});
    prometheus::Counter& add_group_fail_total_ = add_group_request_.Add({{"outcome", "fail"}});

    // record get_group request
    prometheus::Family<prometheus::Counter>& get_group_request_ = prometheus::BuildCounter()
                                                                      .Name("get_group_request_total")
                                                                      .Help("the number of get_group request")
                                                                      .Register(*registry_);

    prometheus::Counter& get_group_success_total_ = get_group_request_.Add({{"outcome", "success"}});
    prometheus::Counter& get_group_fail_total_ = get_group_request_.Add({{"outcome", "fail"}});

    // record has_group request
    prometheus::Family<prometheus::Counter>& has_group_request_ = prometheus::BuildCounter()
                                                                      .Name("has_group_request_total")
                                                                      .Help("the number of has_group request")
                                                                      .Register(*registry_);

    prometheus::Counter& has_group_success_total_ = has_group_request_.Add({{"outcome", "success"}});
    prometheus::Counter& has_group_fail_total_ = has_group_request_.Add({{"outcome", "fail"}});

    // record get_group_files
    prometheus::Family<prometheus::Counter>& get_group_files_request_ =
        prometheus::BuildCounter()
            .Name("get_group_files_request_total")
            .Help("the number of get_group_files request")
            .Register(*registry_);

    prometheus::Counter& get_group_files_success_total_ = get_group_files_request_.Add({{"outcome", "success"}});
    prometheus::Counter& get_group_files_fail_total_ = get_group_files_request_.Add({{"outcome", "fail"}});

    // record add_vectors count and average time
    // need to be considered
    prometheus::Family<prometheus::Counter>& add_vectors_request_ = prometheus::BuildCounter()
                                                                        .Name("add_vectors_request_total")
                                                                        .Help("the number of vectors added")
                                                                        .Register(*registry_);
    prometheus::Counter& add_vectors_success_total_ = add_vectors_request_.Add({{"outcome", "success"}});
    prometheus::Counter& add_vectors_fail_total_ = add_vectors_request_.Add({{"outcome", "fail"}});

    prometheus::Family<prometheus::Histogram>& add_vectors_duration_seconds_ =
        prometheus::BuildHistogram()
            .Name("add_vector_duration_microseconds")
            .Help("average time of adding every vector")
            .Register(*registry_);
    prometheus::Histogram& add_vectors_duration_histogram_ =
S
starlord 已提交
370
        add_vectors_duration_seconds_.Add({}, BucketBoundaries{0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.08, 0.1, 0.5, 1});
Y
yu yunfeng 已提交
371

S
starlord 已提交
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
    // record search count and average time
    prometheus::Family<prometheus::Counter>& search_request_ = prometheus::BuildCounter()
                                                                   .Name("search_request_total")
                                                                   .Help("the number of search request")
                                                                   .Register(*registry_);
    prometheus::Counter& search_success_total_ = search_request_.Add({{"outcome", "success"}});
    prometheus::Counter& search_fail_total_ = search_request_.Add({{"outcome", "fail"}});

    prometheus::Family<prometheus::Histogram>& search_request_duration_seconds_ =
        prometheus::BuildHistogram()
            .Name("search_request_duration_microsecond")
            .Help("histogram of processing time for each search")
            .Register(*registry_);
    prometheus::Histogram& search_duration_histogram_ =
        search_request_duration_seconds_.Add({}, BucketBoundaries{0.1, 1.0, 10.0});

    // record raw_files size histogram
    prometheus::Family<prometheus::Histogram>& raw_files_size_ = prometheus::BuildHistogram()
                                                                     .Name("search_raw_files_bytes")
                                                                     .Help("histogram of raw files size by bytes")
                                                                     .Register(*registry_);
    prometheus::Histogram& raw_files_size_histogram_ =
        raw_files_size_.Add({}, BucketBoundaries{1e9, 2e9, 4e9, 6e9, 8e9, 1e10});

    // record index_files size histogram
    prometheus::Family<prometheus::Histogram>& index_files_size_ = prometheus::BuildHistogram()
                                                                       .Name("search_index_files_bytes")
                                                                       .Help("histogram of index files size by bytes")
                                                                       .Register(*registry_);
    prometheus::Histogram& index_files_size_histogram_ =
        index_files_size_.Add({}, BucketBoundaries{1e9, 2e9, 4e9, 6e9, 8e9, 1e10});

    // record index and raw files size counter
    prometheus::Family<prometheus::Counter>& file_size_total_ = prometheus::BuildCounter()
                                                                    .Name("search_file_size_total")
                                                                    .Help("searched index and raw file size")
                                                                    .Register(*registry_);
    prometheus::Counter& index_file_size_total_ = file_size_total_.Add({{"type", "index"}});
    prometheus::Counter& raw_file_size_total_ = file_size_total_.Add({{"type", "raw"}});

    // record index and raw files size counter
    prometheus::Family<prometheus::Gauge>& file_size_gauge_ = prometheus::BuildGauge()
                                                                  .Name("search_file_size_gauge")
                                                                  .Help("searched current index and raw file size")
                                                                  .Register(*registry_);
    prometheus::Gauge& index_file_size_gauge_ = file_size_gauge_.Add({{"type", "index"}});
    prometheus::Gauge& raw_file_size_gauge_ = file_size_gauge_.Add({{"type", "raw"}});

    // record processing time for building index
    prometheus::Family<prometheus::Histogram>& build_index_duration_seconds_ =
        prometheus::BuildHistogram()
            .Name("build_index_duration_microseconds")
            .Help("histogram of processing time for building index")
            .Register(*registry_);
    prometheus::Histogram& build_index_duration_seconds_histogram_ =
S
starlord 已提交
427
        build_index_duration_seconds_.Add({}, BucketBoundaries{5e5, 2e6, 4e6, 6e6, 8e6, 1e7});
Y
yu yunfeng 已提交
428

S
starlord 已提交
429 430 431 432 433 434 435
    // record processing time for all building index
    prometheus::Family<prometheus::Histogram>& all_build_index_duration_seconds_ =
        prometheus::BuildHistogram()
            .Name("all_build_index_duration_microseconds")
            .Help("histogram of processing time for building index")
            .Register(*registry_);
    prometheus::Histogram& all_build_index_duration_seconds_histogram_ =
S
starlord 已提交
436
        all_build_index_duration_seconds_.Add({}, BucketBoundaries{2e6, 4e6, 6e6, 8e6, 1e7});
Y
yu yunfeng 已提交
437

S
starlord 已提交
438 439 440 441 442 443 444
    // record duration of merging mem table
    prometheus::Family<prometheus::Histogram>& mem_table_merge_duration_seconds_ =
        prometheus::BuildHistogram()
            .Name("mem_table_merge_duration_microseconds")
            .Help("histogram of processing time for merging mem tables")
            .Register(*registry_);
    prometheus::Histogram& mem_table_merge_duration_seconds_histogram_ =
S
starlord 已提交
445
        mem_table_merge_duration_seconds_.Add({}, BucketBoundaries{5e4, 1e5, 2e5, 4e5, 6e5, 8e5, 1e6});
Y
yu yunfeng 已提交
446

S
starlord 已提交
447 448 449 450 451 452 453
    // record search index and raw data duration
    prometheus::Family<prometheus::Histogram>& search_data_duration_seconds_ =
        prometheus::BuildHistogram()
            .Name("search_data_duration_microseconds")
            .Help("histograms of processing time for search index and raw data")
            .Register(*registry_);
    prometheus::Histogram& search_index_data_duration_seconds_histogram_ =
S
starlord 已提交
454
        search_data_duration_seconds_.Add({{"type", "index"}}, BucketBoundaries{1e5, 2e5, 4e5, 6e5, 8e5});
S
starlord 已提交
455
    prometheus::Histogram& search_raw_data_duration_seconds_histogram_ =
S
starlord 已提交
456
        search_data_duration_seconds_.Add({{"type", "raw"}}, BucketBoundaries{1e5, 2e5, 4e5, 6e5, 8e5});
Y
yu yunfeng 已提交
457 458

    ////all form Cache.cpp
S
starlord 已提交
459
    // record cache usage, when insert/erase/clear/free
Y
yu yunfeng 已提交
460 461

    ////all from Meta.cpp
S
starlord 已提交
462 463 464 465 466 467 468 469 470 471 472 473 474
    // record meta visit count and time
    //    prometheus::Family<prometheus::Counter> &meta_visit_ = prometheus::BuildCounter()
    //        .Name("meta_visit_total")
    //        .Help("the number of accessing Meta")
    //        .Register(*registry_);
    //    prometheus::Counter &meta_visit_total_ = meta_visit_.Add({{}});
    //
    //    prometheus::Family<prometheus::Histogram> &meta_visit_duration_seconds_ = prometheus::BuildHistogram()
    //        .Name("meta_visit_duration_seconds")
    //        .Help("histogram of processing time to get data from mata")
    //        .Register(*registry_);
    //    prometheus::Histogram &meta_visit_duration_seconds_histogram_ =
    //          meta_visit_duration_seconds_.Add({{}}, BucketBoundaries{0.1, 1.0, 10.0});
Y
yu yunfeng 已提交
475 476

    ////all from MemManager.cpp
S
starlord 已提交
477 478 479 480 481 482 483 484 485
    // record memory usage percent
    prometheus::Family<prometheus::Gauge>& mem_usage_percent_ =
        prometheus::BuildGauge().Name("memory_usage_percent").Help("memory usage percent").Register(*registry_);
    prometheus::Gauge& mem_usage_percent_gauge_ = mem_usage_percent_.Add({});

    // record memory usage toal
    prometheus::Family<prometheus::Gauge>& mem_usage_total_ =
        prometheus::BuildGauge().Name("memory_usage_total").Help("memory usage total").Register(*registry_);
    prometheus::Gauge& mem_usage_total_gauge_ = mem_usage_total_.Add({});
Y
yu yunfeng 已提交
486 487

    ////all from DBMetaImpl.cpp
S
starlord 已提交
488 489 490 491 492 493 494 495 496 497 498 499
    // record meta access count
    prometheus::Family<prometheus::Counter>& meta_access_ =
        prometheus::BuildCounter().Name("meta_access_total").Help("the number of meta accessing").Register(*registry_);
    prometheus::Counter& meta_access_total_ = meta_access_.Add({});

    // record meta access duration
    prometheus::Family<prometheus::Histogram>& meta_access_duration_seconds_ =
        prometheus::BuildHistogram()
            .Name("meta_access_duration_microseconds")
            .Help("histogram of processing time for accessing mata")
            .Register(*registry_);
    prometheus::Histogram& meta_access_duration_seconds_histogram_ =
S
starlord 已提交
500
        meta_access_duration_seconds_.Add({}, BucketBoundaries{100, 300, 500, 700, 900, 2000, 4000, 6000, 8000, 20000});
Y
yu yunfeng 已提交
501 502

    ////all from FaissExecutionEngine.cpp
S
starlord 已提交
503 504 505 506 507 508 509
    // record data loading from disk count, size, duration, IO speed
    prometheus::Family<prometheus::Histogram>& disk_load_duration_second_ =
        prometheus::BuildHistogram()
            .Name("disk_load_duration_microseconds")
            .Help("Histogram of processing time for loading data from disk")
            .Register(*registry_);
    prometheus::Histogram& faiss_disk_load_duration_seconds_histogram_ =
S
starlord 已提交
510
        disk_load_duration_second_.Add({{"DB", "Faiss"}}, BucketBoundaries{2e5, 4e5, 6e5, 8e5});
Y
yu yunfeng 已提交
511

S
starlord 已提交
512 513 514 515 516 517
    prometheus::Family<prometheus::Histogram>& disk_load_size_bytes_ =
        prometheus::BuildHistogram()
            .Name("disk_load_size_bytes")
            .Help("Histogram of data size by bytes for loading data from disk")
            .Register(*registry_);
    prometheus::Histogram& faiss_disk_load_size_bytes_histogram_ =
S
starlord 已提交
518
        disk_load_size_bytes_.Add({{"DB", "Faiss"}}, BucketBoundaries{1e9, 2e9, 4e9, 6e9, 8e9});
Y
yu yunfeng 已提交
519

S
starlord 已提交
520 521 522 523 524 525
    //    prometheus::Family<prometheus::Histogram> &disk_load_IO_speed_ = prometheus::BuildHistogram()
    //        .Name("disk_load_IO_speed_byte_per_sec")
    //        .Help("Histogram of IO speed for loading data from disk")
    //        .Register(*registry_);
    //    prometheus::Histogram &faiss_disk_load_IO_speed_histogram_ =
    //          disk_load_IO_speed_.Add({{"DB","Faiss"}},BucketBoundaries{1000, 2000, 3000, 4000, 6000, 8000});
Y
yu yunfeng 已提交
526

S
starlord 已提交
527 528 529 530 531
    prometheus::Family<prometheus::Gauge>& faiss_disk_load_IO_speed_ = prometheus::BuildGauge()
                                                                           .Name("disk_load_IO_speed_byte_per_microsec")
                                                                           .Help("disk IO speed ")
                                                                           .Register(*registry_);
    prometheus::Gauge& faiss_disk_load_IO_speed_gauge_ = faiss_disk_load_IO_speed_.Add({{"DB", "Faiss"}});
Y
yu yunfeng 已提交
532

K
kun yu 已提交
533
    ////all from CacheMgr.cpp
S
starlord 已提交
534 535 536 537 538 539
    // record cache access count
    prometheus::Family<prometheus::Counter>& cache_access_ = prometheus::BuildCounter()
                                                                 .Name("cache_access_total")
                                                                 .Help("the count of accessing cache ")
                                                                 .Register(*registry_);
    prometheus::Counter& cache_access_total_ = cache_access_.Add({});
Y
yu yunfeng 已提交
540

Y
Yu Kun 已提交
541
    // record CPU cache usage and %
S
starlord 已提交
542 543 544 545 546 547 548 549 550
    prometheus::Family<prometheus::Gauge>& cpu_cache_usage_ =
        prometheus::BuildGauge().Name("cache_usage_bytes").Help("current cache usage by bytes").Register(*registry_);
    prometheus::Gauge& cpu_cache_usage_gauge_ = cpu_cache_usage_.Add({});

    // record GPU cache usage and %
    prometheus::Family<prometheus::Gauge>& gpu_cache_usage_ = prometheus::BuildGauge()
                                                                  .Name("gpu_cache_usage_bytes")
                                                                  .Help("current gpu cache usage by bytes")
                                                                  .Register(*registry_);
Y
yu yunfeng 已提交
551 552 553

    // record query response
    using Quantiles = std::vector<prometheus::detail::CKMSQuantiles::Quantile>;
S
starlord 已提交
554 555 556 557 558 559 560 561 562 563
    prometheus::Family<prometheus::Summary>& query_response_ =
        prometheus::BuildSummary().Name("query_response_summary").Help("query response summary").Register(*registry_);
    prometheus::Summary& query_response_summary_ =
        query_response_.Add({}, Quantiles{{0.95, 0.00}, {0.9, 0.05}, {0.8, 0.1}});

    prometheus::Family<prometheus::Summary>& query_vector_response_ = prometheus::BuildSummary()
                                                                          .Name("query_vector_response_summary")
                                                                          .Help("query each vector response summary")
                                                                          .Register(*registry_);
    prometheus::Summary& query_vector_response_summary_ =
S
starlord 已提交
564
        query_vector_response_.Add({}, Quantiles{{0.95, 0.00}, {0.9, 0.05}, {0.8, 0.1}});
Y
yu yunfeng 已提交
565

S
starlord 已提交
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
    prometheus::Family<prometheus::Gauge>& query_vector_response_per_second_ =
        prometheus::BuildGauge()
            .Name("query_vector_response_per_microsecond")
            .Help("the number of vectors can be queried every second ")
            .Register(*registry_);
    prometheus::Gauge& query_vector_response_per_second_gauge_ = query_vector_response_per_second_.Add({});

    prometheus::Family<prometheus::Gauge>& query_response_per_second_ =
        prometheus::BuildGauge()
            .Name("query_response_per_microsecond")
            .Help("the number of queries can be processed every microsecond")
            .Register(*registry_);
    prometheus::Gauge& query_response_per_second_gauge = query_response_per_second_.Add({});

    prometheus::Family<prometheus::Gauge>& disk_store_IO_speed_ =
        prometheus::BuildGauge()
            .Name("disk_store_IO_speed_bytes_per_microseconds")
            .Help("disk_store_IO_speed")
            .Register(*registry_);
    prometheus::Gauge& disk_store_IO_speed_gauge_ = disk_store_IO_speed_.Add({});

    prometheus::Family<prometheus::Gauge>& data_file_size_ =
        prometheus::BuildGauge().Name("data_file_size_bytes").Help("data file size by bytes").Register(*registry_);
    prometheus::Gauge& data_file_size_gauge_ = data_file_size_.Add({});

    prometheus::Family<prometheus::Gauge>& add_vectors_ =
        prometheus::BuildGauge().Name("add_vectors").Help("current added vectors").Register(*registry_);
    prometheus::Gauge& add_vectors_success_gauge_ = add_vectors_.Add({{"outcome", "success"}});
    prometheus::Gauge& add_vectors_fail_gauge_ = add_vectors_.Add({{"outcome", "fail"}});

    prometheus::Family<prometheus::Gauge>& add_vectors_per_second_ = prometheus::BuildGauge()
                                                                         .Name("add_vectors_throughput_per_microsecond")
                                                                         .Help("add vectors throughput per microsecond")
                                                                         .Register(*registry_);
    prometheus::Gauge& add_vectors_per_second_gauge_ = add_vectors_per_second_.Add({});

    prometheus::Family<prometheus::Gauge>& CPU_ = prometheus::BuildGauge()
                                                      .Name("CPU_usage_percent")
                                                      .Help("CPU usage percent by this this process")
                                                      .Register(*registry_);
    prometheus::Gauge& CPU_usage_percent_ = CPU_.Add({{"CPU", "avg"}});

    prometheus::Family<prometheus::Gauge>& RAM_ = prometheus::BuildGauge()
                                                      .Name("RAM_usage_percent")
                                                      .Help("RAM usage percent by this process")
                                                      .Register(*registry_);
    prometheus::Gauge& RAM_usage_percent_ = RAM_.Add({});

    // GPU Usage Percent
    prometheus::Family<prometheus::Gauge>& GPU_percent_ =
        prometheus::BuildGauge().Name("Gpu_usage_percent").Help("GPU_usage_percent ").Register(*registry_);

    // GPU Mempry used
    prometheus::Family<prometheus::Gauge>& GPU_memory_usage_ =
        prometheus::BuildGauge().Name("GPU_memory_usage_total").Help("GPU memory usage total ").Register(*registry_);

    prometheus::Family<prometheus::Gauge>& query_index_type_per_second_ =
        prometheus::BuildGauge()
            .Name("query_index_throughtout_per_microsecond")
            .Help("query index throughtout per microsecond")
            .Register(*registry_);
    prometheus::Gauge& query_index_IVF_type_per_second_gauge_ =
        query_index_type_per_second_.Add({{"IndexType", "IVF"}});
    prometheus::Gauge& query_index_IDMAP_type_per_second_gauge_ =
        query_index_type_per_second_.Add({{"IndexType", "IDMAP"}});

    prometheus::Family<prometheus::Gauge>& connection_ =
        prometheus::BuildGauge().Name("connection_number").Help("the number of connections").Register(*registry_);
    prometheus::Gauge& connection_gauge_ = connection_.Add({});

    prometheus::Family<prometheus::Counter>& keeping_alive_ = prometheus::BuildCounter()
                                                                  .Name("keeping_alive_seconds_total")
                                                                  .Help("total seconds of the serve alive")
                                                                  .Register(*registry_);
    prometheus::Counter& keeping_alive_counter_ = keeping_alive_.Add({});

    prometheus::Family<prometheus::Gauge>& octets_ =
        prometheus::BuildGauge().Name("octets_bytes_per_second").Help("octets bytes per second").Register(*registry_);
    prometheus::Gauge& inoctets_gauge_ = octets_.Add({{"type", "inoctets"}});
    prometheus::Gauge& outoctets_gauge_ = octets_.Add({{"type", "outoctets"}});

    prometheus::Family<prometheus::Gauge>& GPU_temperature_ =
        prometheus::BuildGauge().Name("GPU_temperature").Help("GPU temperature").Register(*registry_);

    prometheus::Family<prometheus::Gauge>& CPU_temperature_ =
        prometheus::BuildGauge().Name("CPU_temperature").Help("CPU temperature").Register(*registry_);
Y
yu yunfeng 已提交
652 653
};

S
starlord 已提交
654 655
}  // namespace server
}  // namespace milvus