13 #ifndef __PROCESS_SYSTEM_HPP__
14 #define __PROCESS_SYSTEM_HPP__
39 self().id +
"/load_1min",
42 self().id +
"/load_5min",
45 self().id +
"/load_15min",
48 self().id +
"/cpus_total",
51 self().id +
"/mem_total_bytes",
54 self().id +
"/mem_free_bytes",
70 route(
"/stats.json", statsHelp(), &System::stats);
84 static std::string statsHelp()
88 "Shows local system metrics."),
90 "> cpus_total Total number of available CPUs",
91 "> load_1min Average system load for last"
92 " minute in uptime(1) style",
93 "> load_5min Average system load for last"
94 " 5 minutes in uptime(1) style",
95 "> load_15min Average system load for last"
96 " 15 minutes in uptime(1) style",
97 "> memory_total_bytes Total system memory in bytes",
98 "> memory_free_bytes Free system memory in bytes"));
102 Future<double> _load_1min()
108 return Failure(
"Failed to get loadavg: " + load.
error());
112 Future<double> _load_5min()
118 return Failure(
"Failed to get loadavg: " + load.
error());
122 Future<double> _load_15min()
128 return Failure(
"Failed to get loadavg: " + load.
error());
132 Future<double> _cpus_total()
138 return Failure(
"Failed to get cpus: " + cpus.
error());
142 Future<double> _mem_total_bytes()
148 return Failure(
"Failed to get memory: " + memory.
error());
152 Future<double> _mem_free_bytes()
158 return Failure(
"Failed to get memory: " + memory.
error());
162 Future<http::Response> stats(
const http::Request&
request)
167 object.values[
"avg_load_1min"] = load.
get().
one;
168 object.values[
"avg_load_5min"] = load.
get().
five;
169 object.values[
"avg_load_15min"] = load.
get().
fifteen;
174 object.values[
"cpus_total"] = cpus.
get();
179 object.values[
"mem_total_bytes"] = memory.
get().
total.
bytes();
180 object.values[
"mem_free_bytes"] = memory.
get().
free.
bytes();
183 return http::OK(
object, request.url.query.get(
"jsonp"));
186 metrics::Gauge load_1min;
187 metrics::Gauge load_5min;
188 metrics::Gauge load_15min;
190 metrics::Gauge cpus_total;
192 metrics::Gauge mem_total_bytes;
193 metrics::Gauge mem_free_bytes;
198 #endif // __PROCESS_SYSTEM_HPP__
Definition: system.hpp:33
Future< Response > request(const Request &request, bool streamedResponse=false)
Asynchronously sends an HTTP request to the process and returns the HTTP response once the entire res...
Future< Nothing > remove(const Metric &metric)
Definition: metrics.hpp:109
virtual void finalize()
Invoked when a process is terminated.
Definition: system.hpp:73
Definition: process.hpp:72
void route(const std::string &name, const Option< std::string > &help, const HttpRequestHandler &handler, const RouteOptions &options=RouteOptions())
Sets up a handler for HTTP requests with the specified name.
Future< Nothing > add(const T &metric)
Definition: metrics.hpp:95
Try< Load > loadavg()
Definition: os.hpp:295
std::string TLDR(const std::string &tldr)
Definition: help.hpp:69
Try< long > cpus()
Definition: os.hpp:280
bool isSome() const
Definition: try.hpp:70
virtual ~System()
Definition: system.hpp:57
static Try error(const E &e)
Definition: try.hpp:42
virtual void initialize()
Invoked when a process gets spawned.
Definition: system.hpp:60
std::string HELP(const std::string &tldr, const Option< std::string > &description=None(), const Option< std::string > &authentication=None(), const Option< std::string > &authorization=None(), const Option< std::string > &references=None())
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
Bytes total
Definition: os.hpp:36
System()
Definition: system.hpp:36
uint64_t bytes() const
Definition: bytes.hpp:79
PID< System > self() const
Returns the PID of the process.
Definition: process.hpp:502
double fifteen
Definition: os.hpp:28
Try< Memory > memory()
Definition: freebsd.hpp:78
Definition: process.hpp:493
Deferred< void()> defer(const PID< T > &pid, void(T::*method)())
Definition: defer.hpp:35
Bytes free
Definition: os.hpp:37
const T & get() const
Definition: try.hpp:73
double five
Definition: os.hpp:27
double one
Definition: os.hpp:26
std::string DESCRIPTION(T &&...args)
Definition: help.hpp:76