@cryptotaxi247 / netdata-1 / commits / 67ce94519

apps.plugin code cleanup

Costa Tsaousis (ktsaou) committed Jan 22, 2017 at 14:09 UTC 67ce94519fe4cf35144460b8110b3e7676b716b0
1 file changed +131 -148
src/apps_plugin.c
+131 -148
@@ -1722,7 +1722,7 @@ static int collect_data_for_all_processes_from_proc(void) {
1722 }
1723
1724 if(include_exited_childs) {
1725 - qsort((void *)all_pids_sortlist, all_pids_count, sizeof(pid_t), compar_pid);
1725 + qsort((void *)all_pids_sortlist, (size_t)all_pids_count, sizeof(pid_t), compar_pid);
1726 for(slc = 0; slc < all_pids_count; slc++)
1727 collect_data_for_pid(all_pids_sortlist[slc]);
1728 }
@@ -1974,13 +1974,32 @@ static long zero_all_targets(struct target *root) {
1974 }
1975
1976 static inline void reallocate_target_fds(struct target *w) {
1977 - w->target_fds = reallocz(w->target_fds, sizeof(int) * all_files_size);
1978 - memset(&w->target_fds[w->target_fds_size], 0, sizeof(int) * (all_files_size - w->target_fds_size));
1979 - w->target_fds_size = all_files_size;
1977 + if(unlikely(!w))
1978 + return;
1979 +
1980 + if(unlikely(!w->target_fds || w->target_fds_size < all_files_size)) {
1981 + w->target_fds = reallocz(w->target_fds, sizeof(int) * all_files_size);
1982 + memset(&w->target_fds[w->target_fds_size], 0, sizeof(int) * (all_files_size - w->target_fds_size));
1983 + w->target_fds_size = all_files_size;
1984 + }
1985 }
1986
1982 -static inline void add_fd_on_target(int type, struct target *w) {
1983 - switch(type) {
1987 +static inline void aggregate_fd_on_target(int fd, struct target *w) {
1988 + if(unlikely(!w))
1989 + return;
1990 +
1991 + if(unlikely(w->target_fds[fd])) {
1992 + // it is already aggregated
1993 + // just increase its usage counter
1994 + w->target_fds[fd]++;
1995 + return;
1996 + }
1997 +
1998 + // increase its usage counter
1999 + // so that we will not add it again
2000 + w->target_fds[fd]++;
2001 +
2002 + switch(all_files[fd].type) {
2003 case FILETYPE_FILE:
2004 w->openfiles++;
2005 break;
@@ -2020,16 +2039,17 @@ static inline void add_fd_on_target(int type, struct target *w) {
2039 }
2040
2041 static inline void aggregate_pid_fds_on_targets(struct pid_stat *p) {
2023 - struct target *w = p->target, *u = p->user_target, *g = p->group_target;
2042
2025 - if(unlikely(w && (!w->target_fds || w->target_fds_size < all_files_size)))
2026 - reallocate_target_fds(w);
2043 + if(unlikely(!p->updated)) {
2044 + // the process is not running
2045 + return;
2046 + }
2047
2028 - if(unlikely(u && (!u->target_fds || u->target_fds_size < all_files_size)))
2029 - reallocate_target_fds(u);
2048 + struct target *w = p->target, *u = p->user_target, *g = p->group_target;
2049
2031 - if(unlikely(g && (!g->target_fds || g->target_fds_size < all_files_size)))
2032 - reallocate_target_fds(g);
2050 + reallocate_target_fds(w);
2051 + reallocate_target_fds(u);
2052 + reallocate_target_fds(g);
2053
2054 int c, size = p->fds_size, *fds = p->fds;
2055 for(c = 0; c < size ;c++) {
@@ -2038,72 +2058,64 @@ static inline void aggregate_pid_fds_on_targets(struct pid_stat *p) {
2058 if(likely(fd <= 0 || fd >= all_files_size))
2059 continue;
2060
2041 - if(likely(w)) {
2042 - if(unlikely(!w->target_fds[fd]))
2043 - add_fd_on_target(all_files[fd].type, w);
2044 -
2045 - w->target_fds[fd]++;
2046 - }
2047 -
2048 - if(likely(u)) {
2049 - if(unlikely(!u->target_fds[fd]))
2050 - add_fd_on_target(all_files[fd].type, u);
2051 -
2052 - u->target_fds[fd]++;
2053 - }
2054 -
2055 - if(likely(g)) {
2056 - if(unlikely(!g->target_fds[fd]))
2057 - add_fd_on_target(all_files[fd].type, g);
2058 -
2059 - g->target_fds[fd]++;
2060 - }
2061 + aggregate_fd_on_target(all_files[fd].type, w);
2062 + aggregate_fd_on_target(all_files[fd].type, u);
2063 + aggregate_fd_on_target(all_files[fd].type, g);
2064 }
2065 }
2066
2067 static inline void aggregate_pid_on_target(struct target *w, struct pid_stat *p, struct target *o) {
2068 (void)o;
2069
2067 - if(likely(p->updated)) {
2068 - w->cutime += p->cutime;
2069 - w->cstime += p->cstime;
2070 - w->cgtime += p->cgtime;
2071 - w->cminflt += p->cminflt;
2072 - w->cmajflt += p->cmajflt;
2073 -
2074 - w->utime += p->utime;
2075 - w->stime += p->stime;
2076 - w->gtime += p->gtime;
2077 - w->minflt += p->minflt;
2078 - w->majflt += p->majflt;
2079 -
2080 - // w->rss += p->rss;
2081 -
2082 - w->statm_size += p->statm_size;
2083 - w->statm_resident += p->statm_resident;
2084 - w->statm_share += p->statm_share;
2085 - // w->statm_text += p->statm_text;
2086 - // w->statm_lib += p->statm_lib;
2087 - // w->statm_data += p->statm_data;
2088 - // w->statm_dirty += p->statm_dirty;
2089 -
2090 - w->io_logical_bytes_read += p->io_logical_bytes_read;
2091 - w->io_logical_bytes_written += p->io_logical_bytes_written;
2092 - // w->io_read_calls += p->io_read_calls;
2093 - // w->io_write_calls += p->io_write_calls;
2094 - w->io_storage_bytes_read += p->io_storage_bytes_read;
2095 - w->io_storage_bytes_written += p->io_storage_bytes_written;
2096 - // w->io_cancelled_write_bytes += p->io_cancelled_write_bytes;
2097 -
2098 - w->processes++;
2099 - w->num_threads += p->num_threads;
2100 -
2101 - if(unlikely(debug || w->debug))
2102 - fprintf(stderr, "apps.plugin: \taggregating '%s' pid %d on target '%s' utime=%llu, stime=%llu, gtime=%llu, cutime=%llu, cstime=%llu, cgtime=%llu, minflt=%llu, majflt=%llu, cminflt=%llu, cmajflt=%llu\n", p->comm, p->pid, w->name, p->utime, p->stime, p->gtime, p->cutime, p->cstime, p->cgtime, p->minflt, p->majflt, p->cminflt, p->cmajflt);
2070 + if(unlikely(!p->updated)) {
2071 + // the process is not running
2072 + return;
2073 + }
2074 +
2075 + if(unlikely(!w)) {
2076 + error("pid %d %s was left without a target!", p->pid, p->comm);
2077 + return;
2078 }
2079 +
2080 + w->cutime += p->cutime;
2081 + w->cstime += p->cstime;
2082 + w->cgtime += p->cgtime;
2083 + w->cminflt += p->cminflt;
2084 + w->cmajflt += p->cmajflt;
2085 +
2086 + w->utime += p->utime;
2087 + w->stime += p->stime;
2088 + w->gtime += p->gtime;
2089 + w->minflt += p->minflt;
2090 + w->majflt += p->majflt;
2091 +
2092 + // w->rss += p->rss;
2093 +
2094 + w->statm_size += p->statm_size;
2095 + w->statm_resident += p->statm_resident;
2096 + w->statm_share += p->statm_share;
2097 + // w->statm_text += p->statm_text;
2098 + // w->statm_lib += p->statm_lib;
2099 + // w->statm_data += p->statm_data;
2100 + // w->statm_dirty += p->statm_dirty;
2101 +
2102 + w->io_logical_bytes_read += p->io_logical_bytes_read;
2103 + w->io_logical_bytes_written += p->io_logical_bytes_written;
2104 + // w->io_read_calls += p->io_read_calls;
2105 + // w->io_write_calls += p->io_write_calls;
2106 + w->io_storage_bytes_read += p->io_storage_bytes_read;
2107 + w->io_storage_bytes_written += p->io_storage_bytes_written;
2108 + // w->io_cancelled_write_bytes += p->io_cancelled_write_bytes;
2109 +
2110 + w->processes++;
2111 + w->num_threads += p->num_threads;
2112 +
2113 + if(unlikely(debug || w->debug))
2114 + fprintf(stderr, "apps.plugin: \taggregating '%s' pid %d on target '%s' utime=%llu, stime=%llu, gtime=%llu, cutime=%llu, cstime=%llu, cgtime=%llu, minflt=%llu, majflt=%llu, cminflt=%llu, cmajflt=%llu\n", p->comm, p->pid, w->name, p->utime, p->stime, p->gtime, p->cutime, p->cstime, p->cgtime, p->minflt, p->majflt, p->cminflt, p->cmajflt);
2115 }
2116
2117 static void calculate_netdata_statistics(void) {
2118 +
2119 apply_apps_groups_targets_inheritance();
2120
2121 zero_all_targets(users_root_target);
@@ -2114,21 +2126,17 @@ static void calculate_netdata_statistics(void) {
2126 struct pid_stat *p = NULL;
2127 struct target *w = NULL, *o = NULL;
2128
2117 - // concentrate everything on the apps_groups_targets
2129 + // concentrate everything on the targets
2130 for(p = root_of_pids; p ; p = p->next) {
2119 - if(!p->updated) continue;
2131
2132 // --------------------------------------------------------------------
2122 - // assign apps_groups target
2133 + // apps_groups target
2134
2124 - if(likely(p->target))
2125 - aggregate_pid_on_target(p->target, p, NULL);
2126 - else
2127 - error("pid %d %s was left without a target!", p->pid, p->comm);
2135 + aggregate_pid_on_target(p->target, p, NULL);
2136
2137
2138 // --------------------------------------------------------------------
2131 - // assign user target
2139 + // user target
2140
2141 o = p->user_target;
2142 if(likely(p->user_target && p->user_target->uid == p->uid))
@@ -2140,14 +2148,11 @@ static void calculate_netdata_statistics(void) {
2148 w = p->user_target = get_users_target(p->uid);
2149 }
2150
2143 - if(likely(w))
2144 - aggregate_pid_on_target(w, p, o);
2145 - else
2146 - error("pid %d %s was left without a user target!", p->pid, p->comm);
2151 + aggregate_pid_on_target(w, p, o);
2152
2153
2154 // --------------------------------------------------------------------
2150 - // assign group target
2155 + // user group target
2156
2157 o = p->group_target;
2158 if(likely(p->group_target && p->group_target->gid == p->gid))
@@ -2159,10 +2164,7 @@ static void calculate_netdata_statistics(void) {
2164 w = p->group_target = get_groups_target(p->gid);
2165 }
2166
2162 - if(likely(w))
2163 - aggregate_pid_on_target(w, p, o);
2164 - else
2165 - error("pid %d %s was left without a group target!", p->pid, p->comm);
2167 + aggregate_pid_on_target(w, p, o);
2168
2169
2170 // --------------------------------------------------------------------
@@ -2178,32 +2180,18 @@ static void calculate_netdata_statistics(void) {
2180 // ----------------------------------------------------------------------------
2181 // update chart dimensions
2182
2181 -BUFFER *output = NULL;
2183 int print_calculated_number(char *str, calculated_number value) { (void)str; (void)value; return 0; }
2184
2185 static inline void send_BEGIN(const char *type, const char *id, unsigned long long usec) {
2185 - // fprintf(stdout, "BEGIN %s.%s %llu\n", type, id, usec);
2186 - buffer_strcat(output, "BEGIN ");
2187 - buffer_strcat(output, type);
2188 - buffer_strcat(output, ".");
2189 - buffer_strcat(output, id);
2190 - buffer_strcat(output, " ");
2191 - buffer_print_llu(output, usec);
2192 - buffer_strcat(output, "\n");
2186 + fprintf(stdout, "BEGIN %s.%s %llu\n", type, id, usec);
2187 }
2188
2189 static inline void send_SET(const char *name, unsigned long long value) {
2196 - // fprintf(stdout, "SET %s = %llu\n", name, value);
2197 - buffer_strcat(output, "SET ");
2198 - buffer_strcat(output, name);
2199 - buffer_strcat(output, " = ");
2200 - buffer_print_llu(output, value);
2201 - buffer_strcat(output, "\n");
2190 + fprintf(stdout, "SET %s = %llu\n", name, value);
2191 }
2192
2193 static inline void send_END(void) {
2205 - // fprintf(stdout, "END\n");
2206 - buffer_strcat(output, "END\n");
2194 + fprintf(stdout, "END\n");
2195 }
2196
2197 double utime_fix_ratio = 1.0, stime_fix_ratio = 1.0, gtime_fix_ratio = 1.0, cutime_fix_ratio = 1.0, cstime_fix_ratio = 1.0, cgtime_fix_ratio = 1.0;
@@ -2243,7 +2231,7 @@ static usec_t send_resource_usage_to_netdata() {
2231 memmove(&me_last, &me, sizeof(struct rusage));
2232 }
2233
2246 - buffer_sprintf(output,
2234 + fprintf(stdout,
2235 "BEGIN netdata.apps_cpu %llu\n"
2236 "SET user = %llu\n"
2237 "SET system = %llu\n"
@@ -2278,7 +2266,7 @@ static usec_t send_resource_usage_to_netdata() {
2266 );
2267
2268 if(include_exited_childs)
2281 - buffer_sprintf(output,
2269 + fprintf(stdout,
2270 "BEGIN netdata.apps_children_fix %llu\n"
2271 "SET cutime = %llu\n"
2272 "SET cstime = %llu\n"
@@ -2594,112 +2582,112 @@ static void send_charts_updates_to_netdata(struct target *root, const char *type
2582
2583 // we have something new to show
2584 // update the charts
2597 - buffer_sprintf(output, "CHART %s.cpu '' '%s CPU Time (%d%% = %d core%s)' 'cpu time %%' cpu %s.cpu stacked 20001 %d\n", type, title, (processors * 100), processors, (processors>1)?"s":"", type, update_every);
2585 + fprintf(stdout, "CHART %s.cpu '' '%s CPU Time (%d%% = %d core%s)' 'cpu time %%' cpu %s.cpu stacked 20001 %d\n", type, title, (processors * 100), processors, (processors>1)?"s":"", type, update_every);
2586 for (w = root; w ; w = w->next) {
2587 if(unlikely(w->exposed))
2600 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 %llu %s\n", w->name, hz * RATES_DETAIL / 100, w->hidden ? "hidden" : "");
2588 + fprintf(stdout, "DIMENSION %s '' absolute 1 %llu %s\n", w->name, hz * RATES_DETAIL / 100, w->hidden ? "hidden" : "");
2589 }
2590
2603 - buffer_sprintf(output, "CHART %s.mem '' '%s Real Memory (w/o shared)' 'MB' mem %s.mem stacked 20003 %d\n", type, title, type, update_every);
2591 + fprintf(stdout, "CHART %s.mem '' '%s Real Memory (w/o shared)' 'MB' mem %s.mem stacked 20003 %d\n", type, title, type, update_every);
2592 for (w = root; w ; w = w->next) {
2593 if(unlikely(w->exposed))
2606 - buffer_sprintf(output, "DIMENSION %s '' absolute %ld %ld\n", w->name, sysconf(_SC_PAGESIZE), 1024L*1024L);
2594 + fprintf(stdout, "DIMENSION %s '' absolute %ld %ld\n", w->name, sysconf(_SC_PAGESIZE), 1024L*1024L);
2595 }
2596
2609 - buffer_sprintf(output, "CHART %s.vmem '' '%s Virtual Memory Size' 'MB' mem %s.vmem stacked 20004 %d\n", type, title, type, update_every);
2597 + fprintf(stdout, "CHART %s.vmem '' '%s Virtual Memory Size' 'MB' mem %s.vmem stacked 20004 %d\n", type, title, type, update_every);
2598 for (w = root; w ; w = w->next) {
2599 if(unlikely(w->exposed))
2612 - buffer_sprintf(output, "DIMENSION %s '' absolute %ld %ld\n", w->name, sysconf(_SC_PAGESIZE), 1024L*1024L);
2600 + fprintf(stdout, "DIMENSION %s '' absolute %ld %ld\n", w->name, sysconf(_SC_PAGESIZE), 1024L*1024L);
2601 }
2602
2615 - buffer_sprintf(output, "CHART %s.threads '' '%s Threads' 'threads' processes %s.threads stacked 20005 %d\n", type, title, type, update_every);
2603 + fprintf(stdout, "CHART %s.threads '' '%s Threads' 'threads' processes %s.threads stacked 20005 %d\n", type, title, type, update_every);
2604 for (w = root; w ; w = w->next) {
2605 if(unlikely(w->exposed))
2618 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 1\n", w->name);
2606 + fprintf(stdout, "DIMENSION %s '' absolute 1 1\n", w->name);
2607 }
2608
2621 - buffer_sprintf(output, "CHART %s.processes '' '%s Processes' 'processes' processes %s.processes stacked 20004 %d\n", type, title, type, update_every);
2609 + fprintf(stdout, "CHART %s.processes '' '%s Processes' 'processes' processes %s.processes stacked 20004 %d\n", type, title, type, update_every);
2610 for (w = root; w ; w = w->next) {
2611 if(unlikely(w->exposed))
2624 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 1\n", w->name);
2612 + fprintf(stdout, "DIMENSION %s '' absolute 1 1\n", w->name);
2613 }
2614
2627 - buffer_sprintf(output, "CHART %s.cpu_user '' '%s CPU User Time (%d%% = %d core%s)' 'cpu time %%' cpu %s.cpu_user stacked 20020 %d\n", type, title, (processors * 100), processors, (processors>1)?"s":"", type, update_every);
2615 + fprintf(stdout, "CHART %s.cpu_user '' '%s CPU User Time (%d%% = %d core%s)' 'cpu time %%' cpu %s.cpu_user stacked 20020 %d\n", type, title, (processors * 100), processors, (processors>1)?"s":"", type, update_every);
2616 for (w = root; w ; w = w->next) {
2617 if(unlikely(w->exposed))
2630 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 %llu\n", w->name, hz * RATES_DETAIL / 100LLU);
2618 + fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, hz * RATES_DETAIL / 100LLU);
2619 }
2620
2633 - buffer_sprintf(output, "CHART %s.cpu_system '' '%s CPU System Time (%d%% = %d core%s)' 'cpu time %%' cpu %s.cpu_system stacked 20021 %d\n", type, title, (processors * 100), processors, (processors>1)?"s":"", type, update_every);
2621 + fprintf(stdout, "CHART %s.cpu_system '' '%s CPU System Time (%d%% = %d core%s)' 'cpu time %%' cpu %s.cpu_system stacked 20021 %d\n", type, title, (processors * 100), processors, (processors>1)?"s":"", type, update_every);
2622 for (w = root; w ; w = w->next) {
2623 if(unlikely(w->exposed))
2636 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 %llu\n", w->name, hz * RATES_DETAIL / 100LLU);
2624 + fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, hz * RATES_DETAIL / 100LLU);
2625 }
2626
2627 if(show_guest_time) {
2640 - buffer_sprintf(output, "CHART %s.cpu_guest '' '%s CPU Guest Time (%d%% = %d core%s)' 'cpu time %%' cpu %s.cpu_system stacked 20022 %d\n", type, title, (processors * 100), processors, (processors > 1) ? "s" : "", type, update_every);
2628 + fprintf(stdout, "CHART %s.cpu_guest '' '%s CPU Guest Time (%d%% = %d core%s)' 'cpu time %%' cpu %s.cpu_system stacked 20022 %d\n", type, title, (processors * 100), processors, (processors > 1) ? "s" : "", type, update_every);
2629 for (w = root; w; w = w->next) {
2630 if(unlikely(w->exposed))
2643 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 %llu\n", w->name, hz * RATES_DETAIL / 100LLU);
2631 + fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, hz * RATES_DETAIL / 100LLU);
2632 }
2633 }
2634
2647 - buffer_sprintf(output, "CHART %s.major_faults '' '%s Major Page Faults (swap read)' 'page faults/s' swap %s.major_faults stacked 20010 %d\n", type, title, type, update_every);
2635 + fprintf(stdout, "CHART %s.major_faults '' '%s Major Page Faults (swap read)' 'page faults/s' swap %s.major_faults stacked 20010 %d\n", type, title, type, update_every);
2636 for (w = root; w ; w = w->next) {
2637 if(unlikely(w->exposed))
2650 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 %llu\n", w->name, RATES_DETAIL);
2638 + fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, RATES_DETAIL);
2639 }
2640
2653 - buffer_sprintf(output, "CHART %s.minor_faults '' '%s Minor Page Faults' 'page faults/s' mem %s.minor_faults stacked 20011 %d\n", type, title, type, update_every);
2641 + fprintf(stdout, "CHART %s.minor_faults '' '%s Minor Page Faults' 'page faults/s' mem %s.minor_faults stacked 20011 %d\n", type, title, type, update_every);
2642 for (w = root; w ; w = w->next) {
2643 if(unlikely(w->exposed))
2656 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 %llu\n", w->name, RATES_DETAIL);
2644 + fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, RATES_DETAIL);
2645 }
2646
2659 - buffer_sprintf(output, "CHART %s.lreads '' '%s Disk Logical Reads' 'kilobytes/s' disk %s.lreads stacked 20042 %d\n", type, title, type, update_every);
2647 + fprintf(stdout, "CHART %s.lreads '' '%s Disk Logical Reads' 'kilobytes/s' disk %s.lreads stacked 20042 %d\n", type, title, type, update_every);
2648 for (w = root; w ; w = w->next) {
2649 if(unlikely(w->exposed))
2662 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL);
2650 + fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL);
2651 }
2652
2665 - buffer_sprintf(output, "CHART %s.lwrites '' '%s I/O Logical Writes' 'kilobytes/s' disk %s.lwrites stacked 20042 %d\n", type, title, type, update_every);
2653 + fprintf(stdout, "CHART %s.lwrites '' '%s I/O Logical Writes' 'kilobytes/s' disk %s.lwrites stacked 20042 %d\n", type, title, type, update_every);
2654 for (w = root; w ; w = w->next) {
2655 if(unlikely(w->exposed))
2668 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL);
2656 + fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL);
2657 }
2658
2671 - buffer_sprintf(output, "CHART %s.preads '' '%s Disk Reads' 'kilobytes/s' disk %s.preads stacked 20002 %d\n", type, title, type, update_every);
2659 + fprintf(stdout, "CHART %s.preads '' '%s Disk Reads' 'kilobytes/s' disk %s.preads stacked 20002 %d\n", type, title, type, update_every);
2660 for (w = root; w ; w = w->next) {
2661 if(unlikely(w->exposed))
2674 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL);
2662 + fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL);
2663 }
2664
2677 - buffer_sprintf(output, "CHART %s.pwrites '' '%s Disk Writes' 'kilobytes/s' disk %s.pwrites stacked 20002 %d\n", type, title, type, update_every);
2665 + fprintf(stdout, "CHART %s.pwrites '' '%s Disk Writes' 'kilobytes/s' disk %s.pwrites stacked 20002 %d\n", type, title, type, update_every);
2666 for (w = root; w ; w = w->next) {
2667 if(unlikely(w->exposed))
2680 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL);
2668 + fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL);
2669 }
2670
2671 if(enable_file_charts) {
2684 - buffer_sprintf(output, "CHART %s.files '' '%s Open Files' 'open files' disk %s.files stacked 20050 %d\n", type,
2672 + fprintf(stdout, "CHART %s.files '' '%s Open Files' 'open files' disk %s.files stacked 20050 %d\n", type,
2673 title, type, update_every);
2674 for (w = root; w; w = w->next) {
2675 if (unlikely(w->exposed))
2688 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 1\n", w->name);
2676 + fprintf(stdout, "DIMENSION %s '' absolute 1 1\n", w->name);
2677 }
2678
2691 - buffer_sprintf(output, "CHART %s.sockets '' '%s Open Sockets' 'open sockets' net %s.sockets stacked 20051 %d\n",
2679 + fprintf(stdout, "CHART %s.sockets '' '%s Open Sockets' 'open sockets' net %s.sockets stacked 20051 %d\n",
2680 type, title, type, update_every);
2681 for (w = root; w; w = w->next) {
2682 if (unlikely(w->exposed))
2695 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 1\n", w->name);
2683 + fprintf(stdout, "DIMENSION %s '' absolute 1 1\n", w->name);
2684 }
2685
2698 - buffer_sprintf(output, "CHART %s.pipes '' '%s Pipes' 'open pipes' processes %s.pipes stacked 20053 %d\n", type,
2686 + fprintf(stdout, "CHART %s.pipes '' '%s Pipes' 'open pipes' processes %s.pipes stacked 20053 %d\n", type,
2687 title, type, update_every);
2688 for (w = root; w; w = w->next) {
2689 if (unlikely(w->exposed))
2702 - buffer_sprintf(output, "DIMENSION %s '' absolute 1 1\n", w->name);
2690 + fprintf(stdout, "DIMENSION %s '' absolute 1 1\n", w->name);
2691 }
2692 }
2693 }
@@ -2882,8 +2870,7 @@ int main(int argc, char **argv)
2870 all_pids_sortlist = callocz(sizeof(pid_t), (size_t)pid_max);
2871 all_pids = callocz(sizeof(struct pid_stat *), (size_t) pid_max);
2872
2885 - output = buffer_create(1024);
2886 - buffer_sprintf(output,
2873 + fprintf(stdout,
2874 "CHART netdata.apps_cpu '' 'Apps Plugin CPU' 'milliseconds/s' apps.plugin netdata.apps_cpu stacked 140000 %1$d\n"
2875 "DIMENSION user '' incremental 1 1000\n"
2876 "DIMENSION system '' incremental 1 1000\n"
@@ -2903,7 +2890,7 @@ int main(int argc, char **argv)
2890 );
2891
2892 if(include_exited_childs)
2906 - buffer_sprintf(output,
2893 + fprintf(stdout,
2894 "CHART netdata.apps_children_fix '' 'Apps Plugin Exited Children Normalization Ratios' 'percentage' apps.plugin netdata.apps_children_fix line 140003 %1$d\n"
2895 "DIMENSION cutime '' absolute 1 %2$llu\n"
2896 "DIMENSION cstime '' absolute 1 %2$llu\n"
@@ -2960,13 +2947,9 @@ int main(int argc, char **argv)
2947 if(likely(enable_groups_charts))
2948 send_collected_data_to_netdata(groups_root_target, "groups", dt);
2949
2963 - show_guest_time_old = show_guest_time;
2964 -
2965 - if(write(STDOUT_FILENO, buffer_tostring(output), buffer_strlen(output)) == -1)
2966 - fatal("Cannot send chart values to netdata.");
2950 + fflush(stdout);
2951
2968 - // fflush(stdout);
2969 - buffer_flush(output);
2952 + show_guest_time_old = show_guest_time;
2953
2954 if(unlikely(debug))
2955 fprintf(stderr, "apps.plugin: done Loop No %llu\n", global_iterations_counter);