Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ INSTALLER_SRCS := $(wildcard $(INSTALLER_SRC)/*.c)
TOML_SRCS := $(TOML)/toml.c

ifeq ($(OS), Windows_NT)
LINKED_LIBS := -lWs2_32 -ldxgi -ldxguid -lole32
LINKED_LIBS := -lWs2_32 -ldxgi -ldxguid -lole32 -lpsapi
else ifeq ($(shell uname), Linux)
LINKED_LIBS :=
endif
Expand Down
18 changes: 14 additions & 4 deletions src/config_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,28 @@ result_t* open_config() {
config_details_t get_details_from_config(toml_table_t* config) {
// set initial defaults
config_details_t config_details = (config_details_t) {
.server_config.hostname = BENJI_DEFAULT_SERVER_HOSTNAME,
.server_config.port = BENJI_DEFAULT_SERVER_PORT
.server_config_details.hostname = BENJI_DEFAULT_SERVER_HOSTNAME,
.server_config_details.port = BENJI_DEFAULT_SERVER_PORT,
};

toml_table_t* server_table = toml_table_table(config, "server");
toml_table_t* telemetry_table = toml_table_table(config, "telemetry");

if (server_table) {
toml_value_t hostname = toml_table_string(server_table, "hostname");
toml_value_t port = toml_table_int(server_table, "port");

config_details.server_config.hostname = hostname.ok ? hostname.u.s : BENJI_DEFAULT_SERVER_HOSTNAME;
config_details.server_config.port = port.ok ? port.u.i : BENJI_DEFAULT_SERVER_PORT;
if (hostname.ok) {
config_details.server_config_details.hostname = hostname.u.s;
}

if (port.ok) {
config_details.server_config_details.port = port.u.i;
}
}

if (telemetry_table) {
// TODO: add values here
}

return config_details;
Expand Down
12 changes: 10 additions & 2 deletions src/include/config_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@
#define BENJI_DEFAULT_SERVER_PORT (8000)
#endif

#ifndef BENJI_DEFAULT_MAX_PROCESSES
#define BENJI_DEFAULT_MAX_PROCESSES (10)
#endif

typedef struct _BENJI_CONFIG_DETAILS {
struct _BENJI_SERVER_CONFIG {
struct _BENJI_SERVER_CONFIG_DETAILS {
const char* hostname;
uint16_t port; // 1-65535
} server_config;
} server_config_details;

struct _TELEMETRY_CONFIG_DETAILS {
// TODO: add values here
} telemetry_config_details;
} config_details_t;

result_t* open_config();
Expand Down
9 changes: 5 additions & 4 deletions src/include/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
#endif
#endif

static struct _BENJI_SERVER_INFO {
static struct _BENJI_SERVER_CONFIG {
const char* hostname;
uint16_t port;
} server_info;
} server_config;

static BENJI_SOCKET server_socket;

Expand All @@ -41,7 +41,8 @@ static BENJI_SOCKET server_socket;
/* TODO: add linux stuff */
#endif

// prolly the closest anything in this project will get to a constructor
void collect_server_details(config_details_t config_details);
// mock constructors
void collect_server_config_details(config_details_t config_details);
void collect_telemetry_config_details(config_details_t config_details);

#endif
11 changes: 5 additions & 6 deletions src/include/telemetry/cpu_telemetry.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#ifndef __BENJI_CPU_TELEMETRY_H
#define __BENJI_CPU_TELEMETRY_H

#if defined(_WIN32)
#include <intrin.h>
#include <unistd.h>
#endif

#ifndef BENJI_USE_SYSTEM_TELEMETRY_UTILS
#define BENJI_USE_SYSTEM_TELEMETRY_UTILS
#endif

#include "../utils.h"
#include "../map.h"
#include "../result.h"

#include "telemetry_base.h"

#if defined(_WIN32)
#include <intrin.h>
#include <unistd.h>
#endif

#ifndef BENJI_CPUID_BUFFER_LENGTH
#define BENJI_CPUID_BUFFER_LENGTH (4)
#endif
Expand Down
44 changes: 44 additions & 0 deletions src/include/telemetry/processes_telemetry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef __BENJI_PROCESSES_TELEMETRY_H
#define __BENJI_PROCESSES_TELEMETRY_H

#include <stdint.h>

#ifndef BENJI_USE_SYSTEM_TELEMETRY_UTILS
#define BENJI_USE_SYSTEM_TELEMETRY_UTILS
#endif

#include "../utils.h"
#include "../result.h"

#include "telemetry_base.h"

#ifndef BENJI_PROCESSES_FIELDS
#define BENJI_PROCESSES_FIELDS(_field_getter_impl) \
_field_getter_impl(processes, names) \
_field_getter_impl(processes, pids) \
_field_getter_impl(processes, parent_pids) \
_field_getter_impl(processes, cpu_usages) \
_field_getter_impl(processes, gpu_usages) \
_field_getter_impl(processes, ram_usages) \
_field_getter_impl(processes, disk_usages) \
_field_getter_impl(processes, network_usages)
#endif

BENJI_CREATE_TELEMETRY_STRUCT(PROCESSES, processes,
size_t processes_count;

char* names;
size_t* pids;
size_t* parent_pids;
double* cpu_usages; // percent between 0.0 and 1.0
double* gpu_usages; // percent between 0.0 and 1.0
double* ram_usages; // percent between 0.0 and 1.0
double* disk_usages; // percent between 0.0 and 1.0
double* network_usages; // percent between 0.0 and 1.0
)

BENJI_CREATE_TELEMETRY_BASE(processes)

BENJI_PROCESSES_FIELDS(BENJI_CREATE_TELEMETRY_GETTER_IMPL)

#endif
6 changes: 6 additions & 0 deletions src/include/telemetry/telemetry_base.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef __BENJI_TELEMETRY_BASE_H
#define __BENJI_TELEMETRY_BASE_H

#include <stdint.h>

#include "../result.h"

#ifndef BENJI_CREATE_TELEMETRY_STRUCT
Expand Down Expand Up @@ -49,4 +51,8 @@
} while (false);
#endif

static struct _BENJI_TELEMETRY_CONFIG {
// TODO: add values here
} telemetry_config;

#endif
7 changes: 3 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ int main(int argc, const char* argv[]) {

config_details_t config_details = get_details_from_config(toml_config);

toml_free(toml_config);
collect_server_config_details(config_details);
collect_telemetry_config_details(config_details);

#ifdef _WIN32
collect_server_details(config_details);
#endif
toml_free(toml_config);

#if defined(_WIN32)
winsock_init();
Expand Down
13 changes: 8 additions & 5 deletions src/service.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include "include/service.h"

#if defined(_WIN32)
Expand Down Expand Up @@ -30,7 +29,7 @@
return;
}

result_t* server_socket_result = server_init(server_info.hostname, server_info.port);
result_t* server_socket_result = server_init(server_config.hostname, server_config.port);

if (server_socket_result->is_error) {
result_error_payload_t server_socket_result_error = result_unwrap_error(server_socket_result);
Expand Down Expand Up @@ -145,7 +144,11 @@
/* TODO: add linux stuff */
#endif

void collect_server_details(config_details_t config_details) {
server_info.hostname = config_details.server_config.hostname;
server_info.port = config_details.server_config.port;
void collect_server_config_details(config_details_t config_details) {
server_config.hostname = config_details.server_config_details.hostname;
server_config.port = config_details.server_config_details.port;
}

void collect_telemetry_config_details(config_details_t config_details) {
// TODO: add values
}