mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-04 21:09:06 +08:00
add netio
Former-commit-id: 778661eb22ca5e6e697afe00df3dac4aca416125
This commit is contained in:
parent
25398285e3
commit
f30bb1d35d
@ -323,6 +323,7 @@ void DBImpl::BackgroundTimerTask(int interval) {
|
||||
server::Metrics::GetInstance().RAMUsagePercentSet();
|
||||
server::Metrics::GetInstance().GPUPercentGaugeSet();
|
||||
server::Metrics::GetInstance().GPUMemoryUsageGaugeSet();
|
||||
server::Metrics::GetInstance().OctetsSet();
|
||||
TrySchedule();
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +82,7 @@ class MetricsBase{
|
||||
virtual void ConnectionGaugeIncrement() {};
|
||||
virtual void ConnectionGaugeDecrement() {};
|
||||
virtual void KeepingAliveCounterIncrement(double value = 1) {};
|
||||
virtual void OctetsSet() {};
|
||||
};
|
||||
|
||||
|
||||
|
@ -33,6 +33,8 @@ PrometheusMetrics::Init() {
|
||||
return SERVER_UNEXPECTED_ERROR;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
return SERVER_SUCCESS;
|
||||
|
||||
}
|
||||
@ -110,15 +112,39 @@ void PrometheusMetrics::QueryIndexTypePerSecondSet(std::string type, double valu
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PrometheusMetrics::ConnectionGaugeIncrement() {
|
||||
if(!startup_) return;
|
||||
connection_gauge_.Increment();
|
||||
}
|
||||
|
||||
void PrometheusMetrics::ConnectionGaugeDecrement() {
|
||||
if(!startup_) return;
|
||||
connection_gauge_.Decrement();
|
||||
}
|
||||
|
||||
void PrometheusMetrics::OctetsSet() {
|
||||
if(!startup_) return;
|
||||
|
||||
// get old stats and reset them
|
||||
std::pair<unsigned long long, unsigned long long> in_and_out_octets = SystemInfo::GetInstance().Octets();
|
||||
SystemInfo::GetInstance().set_inoctets(in_and_out_octets.first);
|
||||
SystemInfo::GetInstance().set_outoctets(in_and_out_octets.second);
|
||||
SystemInfo::GetInstance().set_nettime();
|
||||
|
||||
//
|
||||
constexpr int micro_to_second = 1e-6;
|
||||
auto now_time = std::chrono::system_clock::now();
|
||||
unsigned long long old_inoctets = SystemInfo::GetInstance().get_inoctets();
|
||||
unsigned long long old_outoctets = SystemInfo::GetInstance().get_octets();
|
||||
auto old_time = SystemInfo::GetInstance().get_nettime();
|
||||
auto total_microsecond = METRICS_MICROSECONDS(old_time, now_time);
|
||||
auto total_second = total_microsecond*micro_to_second;
|
||||
if(total_second == 0) return;
|
||||
inoctets_gauge_.Set((in_and_out_octets.first-old_inoctets)/total_second);
|
||||
outoctets_gauge_.Set((in_and_out_octets.second-old_outoctets)/total_second);
|
||||
}
|
||||
|
||||
//void PrometheusMetrics::GpuPercentInit() {
|
||||
// int num_device = SystemInfo::GetInstance().num_device();
|
||||
// constexpr char device_number[] = "DeviceNum";
|
||||
|
@ -116,6 +116,7 @@ class PrometheusMetrics: public MetricsBase {
|
||||
void ConnectionGaugeIncrement() override ;
|
||||
void ConnectionGaugeDecrement() override ;
|
||||
void KeepingAliveCounterIncrement(double value = 1) override {if(startup_) keeping_alive_counter_.Increment(value);};
|
||||
void OctetsSet() override ;
|
||||
|
||||
|
||||
|
||||
@ -480,6 +481,13 @@ class PrometheusMetrics: public MetricsBase {
|
||||
.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"}});
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
@ -53,6 +53,11 @@ void SystemInfo::Init() {
|
||||
return ;
|
||||
}
|
||||
|
||||
//initialize network traffic information
|
||||
std::pair<unsigned long long, unsigned long long> in_and_out_octets = Octets();
|
||||
in_octets_ = in_and_out_octets.first;
|
||||
out_octets_ = in_and_out_octets.second;
|
||||
net_time_ = std::chrono::system_clock::now();
|
||||
}
|
||||
|
||||
long long
|
||||
@ -202,6 +207,42 @@ SystemInfo::GPUMemoryUsed() {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::pair<unsigned long long , unsigned long long >
|
||||
SystemInfo::Octets(){
|
||||
pid_t pid = getpid();
|
||||
// const std::string filename = "/proc/"+std::to_string(pid)+"/net/netstat";
|
||||
const std::string filename = "/proc/net/netstat";
|
||||
std::ifstream file(filename);
|
||||
std::string lastline = "";
|
||||
std::string line = "";
|
||||
while(file){
|
||||
getline(file, line);
|
||||
if(file.fail()){
|
||||
break;
|
||||
}
|
||||
lastline = line;
|
||||
}
|
||||
std::vector<size_t> space_position;
|
||||
size_t space_pos = lastline.find(" ");
|
||||
while(space_pos != std::string::npos){
|
||||
space_position.push_back(space_pos);
|
||||
space_pos = lastline.find(" ",space_pos+1);
|
||||
}
|
||||
// InOctets is between 6th and 7th " " and OutOctets is between 7th and 8th " "
|
||||
size_t inoctets_begin = space_position[6]+1;
|
||||
size_t inoctets_length = space_position[7]-inoctets_begin;
|
||||
size_t outoctets_begin = space_position[7]+1;
|
||||
size_t outoctets_length = space_position[8]-outoctets_begin;
|
||||
std::string inoctets = lastline.substr(inoctets_begin,inoctets_length);
|
||||
std::string outoctets = lastline.substr(outoctets_begin,outoctets_length);
|
||||
|
||||
|
||||
unsigned long long inoctets_bytes = std::stoull(inoctets);
|
||||
unsigned long long outoctets_bytes = std::stoull(outoctets);
|
||||
std::pair<unsigned long long , unsigned long long > res(inoctets_bytes, outoctets_bytes);
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
#include "string.h"
|
||||
#include "sys/times.h"
|
||||
#include "sys/vtimes.h"
|
||||
#include <chrono>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
@ -29,9 +30,12 @@ class SystemInfo {
|
||||
clock_t last_cpu_ = clock_t();
|
||||
clock_t last_sys_cpu_ = clock_t();
|
||||
clock_t last_user_cpu_ = clock_t();
|
||||
std::chrono::system_clock::time_point net_time_ = std::chrono::system_clock::now();
|
||||
int num_processors_ = 0;
|
||||
//number of GPU
|
||||
unsigned int num_device_ = 0;
|
||||
unsigned long long in_octets_ = 0;
|
||||
unsigned long long out_octets_ = 0;
|
||||
bool initialized_ = false;
|
||||
|
||||
public:
|
||||
@ -43,11 +47,18 @@ class SystemInfo {
|
||||
|
||||
void Init();
|
||||
int num_device() const {return num_device_;};
|
||||
unsigned long long get_inoctets() { return in_octets_;};
|
||||
unsigned long long get_octets() { return out_octets_;};
|
||||
std::chrono::system_clock::time_point get_nettime() { return net_time_;};
|
||||
void set_inoctets(unsigned long long value) { in_octets_ = value;};
|
||||
void set_outoctets(unsigned long long value) { out_octets_ = value;};
|
||||
void set_nettime() {net_time_ = std::chrono::system_clock::now();};
|
||||
long long ParseLine(char* line);
|
||||
unsigned long GetPhysicalMemory();
|
||||
unsigned long GetProcessUsedMemory();
|
||||
double MemoryPercent();
|
||||
double CPUPercent();
|
||||
std::pair<unsigned long long , unsigned long long > Octets();
|
||||
// std::unordered_map<int,std::vector<double>> GetGPUMemPercent() {};
|
||||
// std::vector<std::string> split(std::string input) {};
|
||||
std::vector<unsigned int> GPUPercent();
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <csignal>
|
||||
#include <numaif.h>
|
||||
//#include <numaif.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -27,12 +27,13 @@ using namespace zilliz::vecwise;
|
||||
|
||||
TEST_F(DBTest, Metric_Tes) {
|
||||
|
||||
|
||||
server::SystemInfo::GetInstance().Init();
|
||||
// server::Metrics::GetInstance().Init();
|
||||
// server::Metrics::GetInstance().exposer_ptr()->RegisterCollectable(server::Metrics::GetInstance().registry_ptr());
|
||||
server::Metrics::GetInstance().Init();
|
||||
|
||||
// server::PrometheusMetrics::GetInstance().exposer_ptr()->RegisterCollectable(server::PrometheusMetrics::GetInstance().registry_ptr());
|
||||
zilliz::vecwise::cache::CpuCacheMgr::GetInstance()->SetCapacity(2UL*1024*1024*1024);
|
||||
zilliz::vecwise::cache::CpuCacheMgr::GetInstance()->SetCapacity(4UL*1024*1024*1024);
|
||||
std::cout<<zilliz::vecwise::cache::CpuCacheMgr::GetInstance()->CacheCapacity()<<std::endl;
|
||||
static const std::string group_name = "test_group";
|
||||
static const int group_dim = 256;
|
||||
|
Loading…
Reference in New Issue
Block a user