#include <json.h>
+#include <pakfire/arch.h>
#include <pakfire/buildservice.h>
#include <pakfire/config.h>
#include <pakfire/ctx.h>
#include <pakfire/digest.h>
#include <pakfire/httpclient.h>
#include <pakfire/logging.h>
+#include <pakfire/os.h>
#include <pakfire/path.h>
#include <pakfire/private.h>
#include <pakfire/string.h>
return r;
}
+
+PAKFIRE_EXPORT int pakfire_buildservice_submit_stats(struct pakfire_buildservice* service) {
+ struct pakfire_cpuinfo cpuinfo = {};
+ struct pakfire_cpustat cpustat = {};
+ struct pakfire_loadavg loadavg = {};
+ struct pakfire_meminfo meminfo = {};
+ const char* arch = NULL;
+ int r;
+
+ struct pakfire_xfer* xfer = NULL;
+ json_object* response = NULL;
+ char* buffer = NULL;
+ size_t length = 0;
+
+ // Fetch CPU info
+ r = pakfire_cpuinfo(&cpuinfo);
+ if (r) {
+ CTX_ERROR(service->ctx, "Failed to fetch CPU info: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
+ // Fetch CPU stats
+ r = pakfire_cpustat(&cpustat);
+ if (r) {
+ CTX_ERROR(service->ctx, "Failed to fetch CPU stats: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
+ // Fetch load average
+ r = pakfire_loadavg(&loadavg);
+ if (r) {
+ CTX_ERROR(service->ctx, "Failed to fetch load average: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
+ // Fetch meminfo
+ r = pakfire_meminfo(&meminfo);
+ if (r) {
+ CTX_ERROR(service->ctx, "Failed to fetch meminfo: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
+ // Fetch native arch
+ arch = pakfire_arch_native();
+ if (!arch) {
+ CTX_ERROR(service->ctx, "Failed to fetch native arch: %s\n", strerror(errno));
+ r = -errno;
+ goto ERROR;
+ }
+
+ // Create a new xfer
+ r = pakfire_buildservice_create_xfer(&xfer, service, "/api/v1/builders/stats");
+ if (r)
+ goto ERROR;
+
+ // Enable authentication
+ r = pakfire_xfer_auth(xfer);
+ if (r)
+ goto ERROR;
+
+ // CPU Model
+ r = pakfire_xfer_add_param(xfer, "cpu_model", "%s", cpuinfo.model);
+ if (r)
+ goto ERROR;
+
+ // CPU Count
+ r = pakfire_xfer_add_param(xfer, "cpu_count", "%u", cpuinfo.count);
+ if (r)
+ goto ERROR;
+
+ // CPU Arch
+ r = pakfire_xfer_add_param(xfer, "cpu_arch", "%s", arch);
+ if (r)
+ goto ERROR;
+
+ // Pakfire Version
+ r = pakfire_xfer_add_param(xfer, "pakfire_version", "%s", PACKAGE_VERSION);
+ if (r)
+ goto ERROR;
+
+ // OS
+ r = pakfire_xfer_add_param(xfer, "os_name", "%s", "???");
+ if (r)
+ goto ERROR;
+
+ // CPU Stats: User
+ r = pakfire_xfer_add_param(xfer, "cpu_user", "%.6f", cpustat.user);
+ if (r)
+ goto ERROR;
+
+ // CPU Stats: Nice
+ r = pakfire_xfer_add_param(xfer, "cpu_nice", "%.6f", cpustat.nice);
+ if (r)
+ goto ERROR;
+
+ // CPU Stats: System
+ r = pakfire_xfer_add_param(xfer, "cpu_system", "%.6f", cpustat.system);
+ if (r)
+ goto ERROR;
+
+ // CPU Stats: Idle
+ r = pakfire_xfer_add_param(xfer, "cpu_idle", "%.6f", cpustat.idle);
+ if (r)
+ goto ERROR;
+
+ // CPU Stats: IO Wait
+ r = pakfire_xfer_add_param(xfer, "cpu_iowait", "%.6f", cpustat.iowait);
+ if (r)
+ goto ERROR;
+
+ // CPU Stats: IRQ
+ r = pakfire_xfer_add_param(xfer, "cpu_irq", "%.6f", cpustat.irq);
+ if (r)
+ goto ERROR;
+
+ // CPU Stats: Soft IRQ
+ r = pakfire_xfer_add_param(xfer, "cpu_softirq", "%.6f", cpustat.softirq);
+ if (r)
+ goto ERROR;
+
+ // CPU Stats: Steal
+ r = pakfire_xfer_add_param(xfer, "cpu_steal", "%.6f", cpustat.steal);
+ if (r)
+ goto ERROR;
+
+ // CPU Stats: Guest
+ r = pakfire_xfer_add_param(xfer, "cpu_guest", "%.6f", cpustat.guest);
+ if (r)
+ goto ERROR;
+
+ // CPU Stats: Guest Nice
+ r = pakfire_xfer_add_param(xfer, "cpu_guest_nice", "%.6f", cpustat.guest_nice);
+ if (r)
+ goto ERROR;
+
+ // Load Average: 1
+ r = pakfire_xfer_add_param(xfer, "loadavg1", "%.2f", loadavg.load1);
+ if (r)
+ goto ERROR;
+
+ // Load Average: 5
+ r = pakfire_xfer_add_param(xfer, "loadavg5", "%.2f", loadavg.load5);
+ if (r)
+ goto ERROR;
+
+ // Load Average: 15
+ r = pakfire_xfer_add_param(xfer, "loadavg15", "%.2f", loadavg.load15);
+ if (r)
+ goto ERROR;
+
+ // Memory: Total
+ r = pakfire_xfer_add_param(xfer, "mem_total", "%lu", meminfo.total);
+ if (r)
+ goto ERROR;
+
+ // Memory: Available
+ r = pakfire_xfer_add_param(xfer, "mem_available", "%lu", meminfo.available);
+ if (r)
+ goto ERROR;
+
+ // Memory: Used
+ r = pakfire_xfer_add_param(xfer, "mem_used", "%lu", meminfo.used);
+ if (r)
+ goto ERROR;
+
+ // Memory: Free
+ r = pakfire_xfer_add_param(xfer, "mem_free", "%lu", meminfo.free);
+ if (r)
+ goto ERROR;
+
+ // Memory: Active
+ r = pakfire_xfer_add_param(xfer, "mem_active", "%lu", meminfo.active);
+ if (r)
+ goto ERROR;
+
+ // Memory: Inactive
+ r = pakfire_xfer_add_param(xfer, "mem_inactive", "%lu", meminfo.inactive);
+ if (r)
+ goto ERROR;
+
+ // Memory: Buffers
+ r = pakfire_xfer_add_param(xfer, "mem_buffers", "%lu", meminfo.buffers);
+ if (r)
+ goto ERROR;
+
+ // Memory: Cached
+ r = pakfire_xfer_add_param(xfer, "mem_cached", "%lu", meminfo.cached);
+ if (r)
+ goto ERROR;
+
+ // Memory: Shared
+ r = pakfire_xfer_add_param(xfer, "mem_shared", "%lu", meminfo.shared);
+ if (r)
+ goto ERROR;
+
+ // Swap: Total
+ r = pakfire_xfer_add_param(xfer, "swap_total", "%lu", meminfo.swap_total);
+ if (r)
+ goto ERROR;
+
+ // Swap: Used
+ r = pakfire_xfer_add_param(xfer, "swap_used", "%lu", meminfo.swap_used);
+ if (r)
+ goto ERROR;
+
+ // Swap: Free
+ r = pakfire_xfer_add_param(xfer, "swap_free", "%lu", meminfo.swap_free);
+ if (r)
+ goto ERROR;
+
+ // Write the response to the buffer
+ r = pakfire_xfer_set_output_buffer(xfer, &buffer, &length);
+ if (r)
+ goto ERROR;
+
+ // Run the xfer
+ r = pakfire_xfer_run(xfer, PAKFIRE_XFER_NO_PROGRESS);
+ if (r)
+ goto ERROR;
+
+ // Parse the response
+ r = pakfire_buildservice_parse_response(service, xfer, buffer, length, &response);
+ if (r) {
+ CTX_ERROR(service->ctx, "Could not parse the response: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
+ERROR:
+ if (xfer)
+ pakfire_xfer_unref(xfer);
+ if (response)
+ json_object_put(response);
+ if (buffer)
+ free(buffer);
+
+ return r;
+}
###############################################################################
import asyncio
-import cpuinfo
import json
import kerberos
import logging
import os
-import psutil
import subprocess
import tempfile
import tornado.httpclient
"job" : self.daemon.job_received,
}
- # Fetch processor information
- self.cpu = cpuinfo.get_cpu_info()
-
- # Fetch the native architecture
- self.native_arch = _pakfire.native_arch()
-
- async def submit_stats(self):
- """
- Sends stats about this builder
- """
- log.debug("Sending stats...")
-
- # Fetch processor information
- cpu_times = psutil.cpu_times_percent()
-
- # Fetch memory/swap information
- mem = psutil.virtual_memory()
- swap = psutil.swap_memory()
-
- # Fetch load average
- loadavg = psutil.getloadavg()
-
- await self.write_message({
- "type" : "stats",
- "data" : {
- # CPU info
- "cpu_model" : self.cpu.get("brand"),
- "cpu_count" : self.cpu.get("count"),
- "cpu_arch" : self.native_arch,
-
- # Pakfire + OS
- "pakfire_version" : PAKFIRE_VERSION,
- "os_name" : util.get_distro_name(),
-
- # CPU Times
- "cpu_user" : cpu_times.user,
- "cpu_nice" : cpu_times.nice,
- "cpu_system" : cpu_times.system,
- "cpu_idle" : cpu_times.idle,
- "cpu_iowait" : cpu_times.iowait,
- "cpu_irq" : cpu_times.irq,
- "cpu_softirq" : cpu_times.softirq,
- "cpu_steal" : cpu_times.steal,
- "cpu_guest" : cpu_times.guest,
- "cpu_guest_nice" : cpu_times.guest_nice,
-
- # Load average
- "loadavg1" : loadavg[0],
- "loadavg5" : loadavg[1],
- "loadavg15" : loadavg[2],
-
- # Memory
- "mem_total" : mem.total,
- "mem_available" : mem.available,
- "mem_used" : mem.used,
- "mem_free" : mem.free,
- "mem_active" : mem.active,
- "mem_inactive" : mem.inactive,
- "mem_buffers" : mem.buffers,
- "mem_cached" : mem.cached,
- "mem_shared" : mem.shared,
-
- # Swap
- "swap_total" : swap.total,
- "swap_used" : swap.used,
- "swap_free" : swap.free,
- },
- })
-
class JobControlConnection(Connection):
"""