]> arthur.barton.de Git - netdata.git/commitdiff
Merge pull request #1912 from vlvkobal/master
authorCosta Tsaousis <costa@tsaousis.gr>
Thu, 16 Mar 2017 23:58:06 +0000 (01:58 +0200)
committerGitHub <noreply@github.com>
Thu, 16 Mar 2017 23:58:06 +0000 (01:58 +0200)
FreeBSD plugin refactoring

1  2 
src/apps_plugin.c
src/global_statistics.c

diff --combined src/apps_plugin.c
index bea06c3c84030d07cf2c2260bb6ca2c4df678d10,d2ac2bd95a5f12ac65d0f6b1ca947ba8e01320e4..83694c9f0fce3f996bc983840ab7b923ce836fc1
@@@ -90,8 -90,7 +90,8 @@@ static in
  static size_t
          global_iterations_counter = 1,
          calls_counter = 0,
 -        file_counter = 0;
 +        file_counter = 0,
 +        targets_assignment_counter = 0;
  
  
  // ----------------------------------------------------------------------------
@@@ -750,8 -749,6 +750,8 @@@ static inline int managed_log(struct pi
  }
  
  static inline void assign_target_to_pid(struct pid_stat *p) {
 +    targets_assignment_counter++;
 +
      uint32_t hash = simple_hash(p->comm);
      size_t pclen  = strlen(p->comm);
  
@@@ -1162,7 -1159,7 +1162,7 @@@ static inline int read_proc_stat() 
          error("FREEBSD: There are %d CPU states (5 was expected)", CPUSTATES);
          goto cleanup;
      }
-     if (unlikely(GETSYSCTL("kern.cp_time", cp_time))) goto cleanup;
+     if (unlikely(GETSYSCTL_BY_NAME("kern.cp_time", cp_time))) goto cleanup;
  #else
      static char filename[FILENAME_MAX + 1] = "";
      static procfile *ff = NULL;
@@@ -2654,13 -2651,12 +2654,13 @@@ static usec_t send_resource_usage_to_ne
                  , "CHART netdata.apps_cpu '' 'Apps Plugin CPU' 'milliseconds/s' apps.plugin netdata.apps_cpu stacked 140000 %1$d\n"
                          "DIMENSION user '' incremental 1 1000\n"
                          "DIMENSION system '' incremental 1 1000\n"
 -                        "CHART netdata.apps_files '' 'Apps Plugin Files' 'files/s' apps.plugin netdata.apps_files line 140001 %1$d\n"
 +                        "CHART netdata.apps_sizes '' 'Apps Plugin Files' 'files/s' apps.plugin netdata.apps_sizes line 140001 %1$d\n"
                          "DIMENSION calls '' incremental 1 1\n"
                          "DIMENSION files '' incremental 1 1\n"
                          "DIMENSION pids '' absolute 1 1\n"
                          "DIMENSION fds '' absolute 1 1\n"
                          "DIMENSION targets '' absolute 1 1\n"
 +                        "DIMENSION new_pids 'new pids' incremental 1 1\n"
                          "CHART netdata.apps_fix '' 'Apps Plugin Normalization Ratios' 'percentage' apps.plugin netdata.apps_fix line 140002 %1$d\n"
                          "DIMENSION utime '' absolute 1 %2$llu\n"
                          "DIMENSION stime '' absolute 1 %2$llu\n"
          "SET user = %llu\n"
          "SET system = %llu\n"
          "END\n"
 -        "BEGIN netdata.apps_files %llu\n"
 +        "BEGIN netdata.apps_sizes %llu\n"
          "SET calls = %zu\n"
          "SET files = %zu\n"
          "SET pids = %zu\n"
          "SET fds = %d\n"
          "SET targets = %zu\n"
 +        "SET new_pids = %zu\n"
          "END\n"
          "BEGIN netdata.apps_fix %llu\n"
          "SET utime = %u\n"
          , all_pids_count
          , all_files_len
          , apps_groups_targets_count
 +        , targets_assignment_counter
          , usec
          , (unsigned int)(utime_fix_ratio   * 100 * RATES_DETAIL)
          , (unsigned int)(stime_fix_ratio   * 100 * RATES_DETAIL)
@@@ -3103,6 -3097,20 +3103,6 @@@ static void send_charts_updates_to_netd
              fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, RATES_DETAIL);
      }
  
 -#ifndef __FreeBSD__
 -    fprintf(stdout, "CHART %s.lreads '' '%s Disk Logical Reads' 'kilobytes/s' disk %s.lreads stacked 20042 %d\n", type, title, type, update_every);
 -    for (w = root; w ; w = w->next) {
 -        if(unlikely(w->exposed))
 -            fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL);
 -    }
 -
 -    fprintf(stdout, "CHART %s.lwrites '' '%s I/O Logical Writes' 'kilobytes/s' disk %s.lwrites stacked 20042 %d\n", type, title, type, update_every);
 -    for (w = root; w ; w = w->next) {
 -        if(unlikely(w->exposed))
 -            fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL);
 -    }
 -#endif
 -
  #ifdef __FreeBSD__
      fprintf(stdout, "CHART %s.preads '' '%s Disk Reads' 'blocks/s' disk %s.preads stacked 20002 %d\n", type, title, type, update_every);
      for (w = root; w ; w = w->next) {
          if(unlikely(w->exposed))
              fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL);
      }
 +
 +    fprintf(stdout, "CHART %s.lreads '' '%s Disk Logical Reads' 'kilobytes/s' disk %s.lreads stacked 20042 %d\n", type, title, type, update_every);
 +    for (w = root; w ; w = w->next) {
 +        if(unlikely(w->exposed))
 +            fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL);
 +    }
 +
 +    fprintf(stdout, "CHART %s.lwrites '' '%s I/O Logical Writes' 'kilobytes/s' disk %s.lwrites stacked 20042 %d\n", type, title, type, update_every);
 +    for (w = root; w ; w = w->next) {
 +        if(unlikely(w->exposed))
 +            fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL);
 +    }
  #endif
  
      if(enable_file_charts) {
@@@ -3199,7 -3195,7 +3199,7 @@@ static void parse_args(int argc, char *
              }
          }
  
 -        if(strcmp("version", argv[i]) == 0 || strcmp("-v", argv[i]) == 0) {
 +        if(strcmp("version", argv[i]) == 0 || strcmp("-v", argv[i]) == 0 || strcmp("-V", argv[i]) == 0) {
              printf("apps.plugin %s\n", VERSION);
              exit(0);
          }
                      "\n"
                      " This program is a data collector plugin for netdata.\n"
                      "\n"
 -                    " Valid command line options:\n"
 +                    " Available command line options:\n"
                      "\n"
                      " SECONDS           set the data collection frequency\n"
                      "\n"
                      "                   apps_groups.conf\n"
                      "                   (default NAME=groups)\n"
                      "\n"
 -                    " version           print program version and exit\n"
 +                    " version or -v or -V print program version and exit\n"
                      "\n"
                      , VERSION
              );
diff --combined src/global_statistics.c
index 2ccdf6801480d2064390513bf0616be47c71a7f7,17faeaa1f3e829b1b89ff88feded9d1f9b3fb907..8575061ac1fd31222a3100bec09bd78294b890b8
@@@ -10,14 -10,14 +10,14 @@@ volatile struct global_statistics globa
          .compressed_content_size = 0
  };
  
 -pthread_mutex_t global_statistics_mutex = PTHREAD_MUTEX_INITIALIZER;
 +netdata_mutex_t global_statistics_mutex = NETDATA_MUTEX_INITIALIZER;
  
  inline void global_statistics_lock(void) {
 -    pthread_mutex_lock(&global_statistics_mutex);
 +    netdata_mutex_lock(&global_statistics_mutex);
  }
  
  inline void global_statistics_unlock(void) {
 -    pthread_mutex_unlock(&global_statistics_mutex);
 +    netdata_mutex_unlock(&global_statistics_mutex);
  }
  
  void finished_web_request_statistics(uint64_t dt,
@@@ -129,11 -129,19 +129,19 @@@ void global_statistics_charts(void) 
      getrusage(RUSAGE_THREAD, &thread);
      getrusage(RUSAGE_SELF, &me);
  
+ #ifdef __FreeBSD__
+     if (!stcpu_thread) stcpu_thread = rrdset_find_localhost("netdata.plugin_freebsd_cpu");
+     if (!stcpu_thread) {
+         stcpu_thread = rrdset_create_localhost("netdata", "plugin_freebsd_cpu", NULL, "freebsd", NULL
+                                                , "NetData FreeBSD Plugin CPU usage", "milliseconds/s", 132000
+                                                , localhost->rrd_update_every, RRDSET_TYPE_STACKED);
+ #else
      if (!stcpu_thread) stcpu_thread = rrdset_find_localhost("netdata.plugin_proc_cpu");
      if (!stcpu_thread) {
          stcpu_thread = rrdset_create_localhost("netdata", "plugin_proc_cpu", NULL, "proc", NULL
                                                 , "NetData Proc Plugin CPU usage", "milliseconds/s", 132000
                                                 , localhost->rrd_update_every, RRDSET_TYPE_STACKED);
+ #endif
  
          rrddim_add(stcpu_thread, "user", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL);
          rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRD_ALGORITHM_INCREMENTAL);