Add sparkd memory use metric
This commit is contained in:
1 parent
03864caa09
commit
b75496e665
2 files changed
+60
-7
No files matched your search
@@ -63,7 +63,7 @@ namespace http {
|
||||
_ctx(ctx),
|
||||
_metrics(metrics),
|
||||
_mtimer(std::make_shared<metrics::HistogramMetric<4>>("spark_metrics_query_duration_us",
|
||||
std::array<double,4>({ 10.0, 20.0, 40.0, 80.0 })))
|
||||
std::array<double,4>({ 50.0, 100.0, 200.0, 500.0 })))
|
||||
{
|
||||
_www = os::sparkdata_path("www");
|
||||
_conf = os::sparkdata_path("conf");
|
||||
|
||||
@@ -5,28 +5,81 @@
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <unistd.h>
|
||||
#include <fstream>
|
||||
|
||||
namespace bts {
|
||||
namespace metrics {
|
||||
|
||||
struct ProcessStats {
|
||||
int pid;
|
||||
std::string comm, state, ppid, pgrp, session, tty_nr;
|
||||
std::string tpgid, flags, minflt, cminflt, majflt, cmajflt;
|
||||
std::string utime, stime, cutime, cstime, priority, nice;
|
||||
std::string O, itrealvalue, starttime;
|
||||
// virtual size
|
||||
uint64_t vsize;
|
||||
// resident set
|
||||
int64_t rss;
|
||||
};
|
||||
|
||||
void read_stats(ProcessStats& stats) {
|
||||
std::ifstream stat_stream("/proc/self/stat", std::ios_base::in);
|
||||
stat_stream
|
||||
>> stats.pid >> stats.comm >> stats.state >> stats.ppid >> stats.pgrp >> stats.session >> stats.tty_nr
|
||||
>> stats.tpgid >> stats.flags >> stats.minflt >> stats.cminflt >> stats.majflt >> stats.cmajflt
|
||||
>> stats.utime >> stats.stime >> stats.cutime >> stats.cstime >> stats.priority >> stats.nice
|
||||
>> stats.O >> stats.itrealvalue >> stats.starttime >> stats.vsize >> stats.rss;
|
||||
stat_stream.close();
|
||||
}
|
||||
|
||||
void process_mem_usage(double& vm, double& resident) {
|
||||
using std::ios_base;
|
||||
using std::ifstream;
|
||||
vm = resident = 0.0;
|
||||
|
||||
ProcessStats stats;
|
||||
read_stats(stats);
|
||||
|
||||
long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024;
|
||||
vm = stats.vsize / 1024.0;
|
||||
resident = stats.rss * page_size_kb;
|
||||
}
|
||||
|
||||
|
||||
void publish_system_metrics(MetricsContainer& stats) {
|
||||
auto cm = std::make_shared<CounterMetric<long>>("spark_test_counter", std::vector<Label> {{"test", "ok"}});
|
||||
stats.publish(cm);
|
||||
// auto cm = std::make_shared<CounterMetric<long>>("spark_test_counter", std::vector<Label> {{"test", "ok"}});
|
||||
// stats.publish(cm);
|
||||
// auto lcm = std::make_shared<LazyCounterMetric>("lazy_metric",[](){ return 42; });
|
||||
// stats.publish(lcm);
|
||||
|
||||
// publish version
|
||||
std::vector<Label> labels;
|
||||
labels.push_back({"version", config::get<config::System>().version()});
|
||||
auto version = std::make_shared<CounterMetric<int>>("spark_version", labels);
|
||||
// std::vector<Label> labels;
|
||||
// labels.push_back({"version", config::get<config::System>().version()});
|
||||
auto version = std::make_shared<CounterMetric<int>>("spark_version", std::vector<Label> ({{"version", config::get<config::System>().version()}}));
|
||||
version->set(1);
|
||||
stats.publish(version);
|
||||
|
||||
// publish system cpu use
|
||||
// publish sparkd cpu use
|
||||
// publish sparkd memory use
|
||||
|
||||
//
|
||||
// sparkd memory use
|
||||
// Note: It would be nice to have 2 metrics work on the same 'read' call
|
||||
stats.publish(
|
||||
std::make_shared<LazyCounterMetric>("spark_memory_res_kb", []() {
|
||||
double vm,res;
|
||||
process_mem_usage(vm,res);
|
||||
return res;
|
||||
}));
|
||||
|
||||
stats.publish(
|
||||
std::make_shared<LazyCounterMetric>("spark_memory_vm_kb", []() {
|
||||
double vm,res;
|
||||
process_mem_usage(vm,res);
|
||||
return vm;
|
||||
}));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user