Skip to content

Commit

Permalink
Merge pull request #935 from green-coding-solutions/1.01-patch
Browse files Browse the repository at this point in the history
Fix: metric providers for IO where accumulating instead of echoing
  • Loading branch information
ArneTR authored Oct 5, 2024
2 parents 2a814d8 + 8c07d5e commit 2ceb2cb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
10 changes: 3 additions & 7 deletions metric_providers/disk/io/cgroup/container/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ static unsigned int msleep_time=1000;

static disk_io_t get_disk_cgroup(char* filename) {
long long int rbytes = -1;
unsigned long long int rbytes_sum = 0;
long long int wbytes = -1;
unsigned long long int wbytes_sum = 0;
disk_io_t disk_io = {0};

FILE * fd = fopen(filename, "r");
if ( fd == NULL) {
Expand All @@ -41,8 +40,8 @@ static disk_io_t get_disk_cgroup(char* filename) {
}

while (fscanf(fd, "%*u:%*u rbytes=%lld wbytes=%lld rios=%*u wios=%*u dbytes=%*u dios=%*u", &rbytes, &wbytes) == 2) {
rbytes_sum += rbytes;
wbytes_sum += wbytes;
disk_io.rbytes += rbytes;
disk_io.wbytes += wbytes;
}

fclose(fd);
Expand All @@ -52,9 +51,6 @@ static disk_io_t get_disk_cgroup(char* filename) {
exit(1);
}

disk_io_t disk_io;
disk_io.rbytes = rbytes_sum;
disk_io.wbytes = wbytes_sum;
return disk_io;
}

Expand Down
7 changes: 4 additions & 3 deletions metric_providers/disk/io/procfs/system/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ static void output_get_disk_procfs() {
exit(1);
}

gettimeofday(&now, NULL); // one call for get time of day for all interfaces is fine. The overhead would be more than the gain in granularity

while (fgets(buf, 1024, fd)) {
// We are not counting dropped packets, as we believe they will at least show up in the
// sender side as not dropped.
Expand All @@ -47,12 +49,11 @@ static void output_get_disk_procfs() {
continue; // we skip loop devices
}

gettimeofday(&now, NULL);
printf("%ld%06ld %llu %llu %s\n", now.tv_sec, now.tv_usec, sectors_read, sectors_written, device_name);
usleep(msleep_time*1000);

}

usleep(msleep_time*1000); // after we have looked at all interfaces

fclose(fd);
}

Expand Down
2 changes: 1 addition & 1 deletion metric_providers/network/io/cgroup/container/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static char *trimwhitespace(char *str) {
static net_io_t get_network_cgroup(unsigned int pid) {
char buf[200], ifname[20];
unsigned long long int r_bytes, t_bytes, r_packets, t_packets;
net_io_t net_io;
net_io_t net_io = {0};

char ns_path[PATH_MAX];
snprintf(ns_path, PATH_MAX, "/proc/%u/ns/net", pid);
Expand Down

0 comments on commit 2ceb2cb

Please sign in to comment.