Upload files to "uno-stats-monitor/unomond"

This commit is contained in:
RLF
2024-01-10 15:34:12 -05:00
parent 1267fe320c
commit f0f8a9c596
2 changed files with 26 additions and 15 deletions

View File

@@ -22,9 +22,9 @@ void send_stats();
void get_stats();
char *trim(char *str);
static void get_cpu_load();
static void get_cpu_temp();
static void get_free_mem();
static void get_free_space();
void get_cpu_temp();
void get_free_mem();
void get_free_space();
// external vars (monitor_daemon.c)
extern const char *cpu_temp_file;
@@ -142,7 +142,7 @@ static void get_cpu_load()
fclose(file);
// if result cannot be read, set to 0
if(read_result < 0) {
if(read_result != 4) {
snprintf(&*cpuload, sizeof(0), "%d", 0);
return;
}
@@ -151,8 +151,8 @@ static void get_cpu_load()
if(totalUser < lastTotalUser || totalUserLow < lastTotalUserLow ||
totalSys < lastTotalSys || totalIdle < lastTotalIdle)
{
//percent = -1.0;
percent = lastPercent;
percent = -1.0;
//percent = lastPercent;
}
// we have a good value, save it and process it
@@ -165,10 +165,21 @@ static void get_cpu_load()
lastPercent = percent;
}
if(debug) {
fprintf(log_stream,"lasttotalUser: %llu - lasttotalUserLow: %llu - lasttotalSys: %llu - lasttotalIdle: %llu - lastpercent: %f\n",
lastTotalUser, lastTotalUserLow, lastTotalSys, lastTotalIdle, lastPercent);
fprintf(log_stream,"totalUser: %llu - totalUserLow: %llu - totalSys: %llu - totalIdle: %llu - percent: %f\n\n",
totalUser,totalUserLow, totalSys, totalIdle, percent);
}
// save curent values for later comparison
lastTotalUser = totalUser;
lastTotalUserLow = totalUserLow;
lastTotalSys = totalSys;
lastTotalIdle = totalIdle;
// force percent (float) to int
intPercent = percent;
snprintf(&*cpuload, sizeof(intPercent), "%d", intPercent);
@@ -176,7 +187,7 @@ static void get_cpu_load()
return;
}
static void get_cpu_temp()
void get_cpu_temp()
{
FILE* ptr;
char str[10];
@@ -200,7 +211,8 @@ static void get_cpu_temp()
char a = str[0];
char b = str[1];
char c = str[2];
snprintf(&*cputemp,6,"%c%c.%c",a,b,c);*/
snprintf(&*cputemp,6,"%c%c.%c",a,b,c);
*/
// no decimals
char a = str[0];
@@ -212,7 +224,7 @@ static void get_cpu_temp()
return;
}
static void get_free_mem()
void get_free_mem()
{
struct sysinfo info;
int myfreemem;
@@ -231,7 +243,7 @@ static void get_free_mem()
return;
}
static void get_free_space()
void get_free_space()
{
struct statfs info;
int n = 0;
@@ -239,11 +251,14 @@ static void get_free_space()
char myfree_string[line_length];
long unsigned int mytmpfree;
// clear freespace array b4 loop or strcat will keep adding to it causing a buffer overflow
memset(freespace, '\0', sizeof(freespace));
for(n = 0; n < drive_free_space_count; n++) {
mydrive = drive_free_space[n];
statfs(mydrive, &info);
mytmpfree = ((info.f_bavail*4) / 1024 / 1024) + 1;
snprintf(myfree_string,line_length,"%ldG ",mytmpfree);
snprintf(myfree_string,10,"%ldG ",mytmpfree);
strcat(freespace,myfree_string);
if(debug) {

View File

@@ -163,10 +163,6 @@ int read_conf_file(int reload) {
return(EXIT_FAILURE);
}
if(debug) {
fprintf(log_stream, "in load/reload config file\n");
}
// load the base config
// delay
if(config_lookup_int(&cfg, "delay", &delay)) {