Compare commits
3 Commits
252e146576
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 59bb33ff7f | |||
| a92122b41d | |||
| 1469485f3d |
@@ -15,7 +15,7 @@ void cpu_detect(struct cpu_sensors_t *t, const char *pci_dev) {
|
||||
t->module = unknown;
|
||||
t->num_cores = (uint8_t)sysconf(_SC_NPROCESSORS_ONLN);
|
||||
|
||||
snprintf(t->hwmon, sizeof(t->hwmon), "/sys/bus/pci/devices/%s/hwmon", pci_dev);
|
||||
snprintf(t->hwmon, sizeof(t->hwmon), "%s/hwmon", pci_dev);
|
||||
const int ret = get_hwmon_dir(t->hwmon, sizeof(t->hwmon));
|
||||
if (ret != 0) {
|
||||
t->hwmon[0] = '\0';
|
||||
|
||||
@@ -18,7 +18,7 @@ static sensor_file_t* sensors;
|
||||
static int gpu_metrics_fd;
|
||||
|
||||
void gpu_detect(struct gpu_sensors_t *t, const char *pci) {
|
||||
snprintf(t->hwmon, sizeof(t->hwmon), "/sys/bus/pci/devices/%s/hwmon", pci);
|
||||
snprintf(t->hwmon, sizeof(t->hwmon), "%s/hwmon", pci);
|
||||
const int ret = get_hwmon_dir(t->hwmon, sizeof(t->hwmon));
|
||||
if (ret != 0) {
|
||||
t->hwmon[0] = '\0';
|
||||
@@ -36,7 +36,7 @@ void gpu_detect(struct gpu_sensors_t *t, const char *pci) {
|
||||
char raw_metrics[max_metrics_length];
|
||||
read(gpu_metrics_fd, raw_metrics, sizeof(raw_metrics));
|
||||
const struct metrics_table_header *header = (struct metrics_table_header *)raw_metrics;
|
||||
applog(LOG_INF, "Found gpu_metrics_v%d_%d", header->format_revision, header->content_revision);
|
||||
applog(LOG_INF, "Found gpu_metrics_v%d_%d at %s", header->format_revision, header->content_revision, p);
|
||||
}
|
||||
|
||||
sensors = malloc(sizeof(sensor_file_t) * (t->has_gpu_metrics ? 10 : 5));
|
||||
|
||||
@@ -19,9 +19,8 @@
|
||||
|
||||
static constexpr uint8_t lcd_contrast = 250;
|
||||
static constexpr uint16_t refresh_interval_ms = 1000;
|
||||
static constexpr char netif[] = "enp7s0";
|
||||
static constexpr char cpu_pcidev[] = "0000:00:18.3";
|
||||
static constexpr char gpu_pcidev[] = "0000:0a:00.0";
|
||||
static constexpr char cpu_pcidev[] = "/sys/bus/pci/devices/0000:00:18.3";
|
||||
static constexpr char gpu_pcidev[] = "/sys/class/drm/renderD128/device";
|
||||
|
||||
static struct {
|
||||
pthread_mutex_t sensors_mtx;
|
||||
@@ -52,7 +51,7 @@ static void *sensors_thread(void *arg) {
|
||||
/* set up paths for the sensors */
|
||||
strcpy(sensors->home.mountpoint, "/home/drath");
|
||||
strcpy(sensors->gry.mountpoint, "/var/mnt/gry");
|
||||
strcpy(sensors->net.device, netif);
|
||||
// strcpy(sensors->net.device, netif);
|
||||
cpu_detect(&sensors->cpu, cpu_pcidev);
|
||||
gpu_detect(&sensors->gpu, gpu_pcidev);
|
||||
sys_detect(&sensors->sys, "nct6775.656");
|
||||
|
||||
26
src/sys.c
26
src/sys.c
@@ -2,6 +2,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <net/if.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "log.h"
|
||||
@@ -91,7 +94,28 @@ void sys_get_network(struct network_t *network) {
|
||||
}
|
||||
|
||||
void sys_netdev_detect(struct network_t *network) {
|
||||
applog(LOG_INF, "Opening netdev %s", network->device);
|
||||
struct ifaddrs *ifaddr;
|
||||
getifaddrs(&ifaddr);
|
||||
char addr[INET_ADDRSTRLEN];
|
||||
for (const struct ifaddrs *ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) {
|
||||
// ugliest fucking if
|
||||
if (!ifa->ifa_addr ||
|
||||
ifa->ifa_addr->sa_family != AF_INET ||
|
||||
!(ifa->ifa_flags & IFF_UP) ||
|
||||
!(ifa->ifa_flags & IFF_RUNNING) ||
|
||||
ifa->ifa_flags & IFF_LOOPBACK)
|
||||
continue;
|
||||
|
||||
const struct sockaddr_in *sin = (struct sockaddr_in *)ifa->ifa_addr;
|
||||
inet_ntop(AF_INET, &sin->sin_addr, addr, sizeof(addr));
|
||||
if (strncmp("10.0.1.", addr, 7) == 0) {
|
||||
strcpy(network->device, ifa->ifa_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
freeifaddrs(ifaddr);
|
||||
|
||||
applog(LOG_INF, "Detected %s with addr %s", network->device, addr);
|
||||
static char path[128];
|
||||
snprintf(path, sizeof(path), "/sys/class/net/%s/statistics/", network->device);
|
||||
open_sensor(&network->f_rx, path, "rx_bytes", nullptr, 1, SENSOR_U64);
|
||||
|
||||
Reference in New Issue
Block a user