Upload files to "uno-stats-monitor/unomond"
This commit is contained in:
@@ -22,9 +22,9 @@ void send_stats();
|
|||||||
void get_stats();
|
void get_stats();
|
||||||
char *trim(char *str);
|
char *trim(char *str);
|
||||||
static void get_cpu_load();
|
static void get_cpu_load();
|
||||||
static void get_cpu_temp();
|
void get_cpu_temp();
|
||||||
static void get_free_mem();
|
void get_free_mem();
|
||||||
static void get_free_space();
|
void get_free_space();
|
||||||
|
|
||||||
// external vars (monitor_daemon.c)
|
// external vars (monitor_daemon.c)
|
||||||
extern const char *cpu_temp_file;
|
extern const char *cpu_temp_file;
|
||||||
@@ -142,7 +142,7 @@ static void get_cpu_load()
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
// if result cannot be read, set to 0
|
// if result cannot be read, set to 0
|
||||||
if(read_result < 0) {
|
if(read_result != 4) {
|
||||||
snprintf(&*cpuload, sizeof(0), "%d", 0);
|
snprintf(&*cpuload, sizeof(0), "%d", 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -151,8 +151,8 @@ static void get_cpu_load()
|
|||||||
if(totalUser < lastTotalUser || totalUserLow < lastTotalUserLow ||
|
if(totalUser < lastTotalUser || totalUserLow < lastTotalUserLow ||
|
||||||
totalSys < lastTotalSys || totalIdle < lastTotalIdle)
|
totalSys < lastTotalSys || totalIdle < lastTotalIdle)
|
||||||
{
|
{
|
||||||
//percent = -1.0;
|
percent = -1.0;
|
||||||
percent = lastPercent;
|
//percent = lastPercent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// we have a good value, save it and process it
|
// we have a good value, save it and process it
|
||||||
@@ -165,10 +165,21 @@ static void get_cpu_load()
|
|||||||
lastPercent = percent;
|
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;
|
lastTotalUser = totalUser;
|
||||||
lastTotalUserLow = totalUserLow;
|
lastTotalUserLow = totalUserLow;
|
||||||
lastTotalSys = totalSys;
|
lastTotalSys = totalSys;
|
||||||
lastTotalIdle = totalIdle;
|
lastTotalIdle = totalIdle;
|
||||||
|
|
||||||
|
// force percent (float) to int
|
||||||
intPercent = percent;
|
intPercent = percent;
|
||||||
|
|
||||||
snprintf(&*cpuload, sizeof(intPercent), "%d", intPercent);
|
snprintf(&*cpuload, sizeof(intPercent), "%d", intPercent);
|
||||||
@@ -176,7 +187,7 @@ static void get_cpu_load()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_cpu_temp()
|
void get_cpu_temp()
|
||||||
{
|
{
|
||||||
FILE* ptr;
|
FILE* ptr;
|
||||||
char str[10];
|
char str[10];
|
||||||
@@ -200,7 +211,8 @@ static void get_cpu_temp()
|
|||||||
char a = str[0];
|
char a = str[0];
|
||||||
char b = str[1];
|
char b = str[1];
|
||||||
char c = str[2];
|
char c = str[2];
|
||||||
snprintf(&*cputemp,6,"%c%c.%c",a,b,c);*/
|
snprintf(&*cputemp,6,"%c%c.%c",a,b,c);
|
||||||
|
*/
|
||||||
|
|
||||||
// no decimals
|
// no decimals
|
||||||
char a = str[0];
|
char a = str[0];
|
||||||
@@ -212,7 +224,7 @@ static void get_cpu_temp()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_free_mem()
|
void get_free_mem()
|
||||||
{
|
{
|
||||||
struct sysinfo info;
|
struct sysinfo info;
|
||||||
int myfreemem;
|
int myfreemem;
|
||||||
@@ -231,7 +243,7 @@ static void get_free_mem()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_free_space()
|
void get_free_space()
|
||||||
{
|
{
|
||||||
struct statfs info;
|
struct statfs info;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
@@ -239,11 +251,14 @@ static void get_free_space()
|
|||||||
char myfree_string[line_length];
|
char myfree_string[line_length];
|
||||||
long unsigned int mytmpfree;
|
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++) {
|
for(n = 0; n < drive_free_space_count; n++) {
|
||||||
mydrive = drive_free_space[n];
|
mydrive = drive_free_space[n];
|
||||||
statfs(mydrive, &info);
|
statfs(mydrive, &info);
|
||||||
mytmpfree = ((info.f_bavail*4) / 1024 / 1024) + 1;
|
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);
|
strcat(freespace,myfree_string);
|
||||||
|
|
||||||
if(debug) {
|
if(debug) {
|
||||||
|
|||||||
@@ -163,10 +163,6 @@ int read_conf_file(int reload) {
|
|||||||
return(EXIT_FAILURE);
|
return(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(debug) {
|
|
||||||
fprintf(log_stream, "in load/reload config file\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// load the base config
|
// load the base config
|
||||||
// delay
|
// delay
|
||||||
if(config_lookup_int(&cfg, "delay", &delay)) {
|
if(config_lookup_int(&cfg, "delay", &delay)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user