]> arthur.barton.de Git - netdata.git/commitdiff
Separate vm.stats.sys.v_swtch module
authorVladimir Kobal <vlad@prokk.net>
Thu, 9 Mar 2017 00:08:51 +0000 (02:08 +0200)
committerVladimir Kobal <vlad@prokk.net>
Thu, 9 Mar 2017 00:08:51 +0000 (02:08 +0200)
src/freebsd_sysctl.c
src/plugin_freebsd.c
src/plugin_freebsd.h

index ed84cb777a3d8baa68ee82b18e7e1a74769717f8..4f1e35fa4b8401697031bf6aa2d840dc7d52f6aa 100644 (file)
@@ -561,6 +561,46 @@ int do_vm_stats_sys_v_soft(int update_every, usec_t dt) {
     return 0;
 }
 
+// --------------------------------------------------------------------------------------------------------------------
+// vm.stats.sys.v_swtch
+
+int do_vm_stats_sys_v_swtch(int update_every, usec_t dt) {
+    static int mib[4] = {0, 0, 0, 0};
+    u_int ctxt_number;
+
+    if (unlikely(GETSYSCTL_SIMPLE("vm.stats.sys.v_swtch", mib, ctxt_number))) {
+        error("DISABLED: system.ctxt chart");
+        error("DISABLED: vm.stats.sys.v_swtch module");
+        return 1;
+    } else {
+        static RRDSET *st = NULL;
+        static RRDDIM *rd = NULL;
+
+        st = rrdset_find_bytype_localhost("system", "ctxt");
+        if (unlikely(!st)) {
+            st = rrdset_create_localhost("system",
+                                         "ctxt",
+                                         NULL,
+                                         "processes",
+                                         NULL,
+                                         "CPU Context Switches",
+                                         "context switches/s",
+                                         800,
+                                         update_every,
+                                         RRDSET_TYPE_LINE
+            );
+
+            rd = rrddim_add(st, "switches", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
+        }
+        else rrdset_next(st);
+
+        rrddim_set_by_pointer(st, rd, ctxt_number);
+        rrdset_done(st);
+    }
+
+    return 0;
+}
+
 // --------------------------------------------------------------------------------------------------------------------
 // old sources
 
@@ -571,7 +611,7 @@ int do_vm_stats_sys_v_soft(int update_every, usec_t dt) {
 #define IFA_DATA(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
 
 int do_freebsd_sysctl_old(int update_every, usec_t dt) {
-    static int do_context = -1, do_forks = -1, do_disk_io = -1, do_swap = -1, do_ram = -1, do_swapio = -1,
+    static int do_forks = -1, do_disk_io = -1, do_swap = -1, do_ram = -1, do_swapio = -1,
         do_pgfaults = -1, do_ipc_semaphores = -1, do_ipc_shared_mem = -1, do_ipc_msg_queues = -1,
         do_netisr = -1, do_netisr_per_core = -1, do_bandwidth = -1,
         do_tcp_sockets = -1, do_tcp_packets = -1, do_tcp_errors = -1, do_tcp_handshake = -1,
@@ -583,7 +623,6 @@ int do_freebsd_sysctl_old(int update_every, usec_t dt) {
         do_icmp6_neighbor = -1, do_icmp6_types = -1, do_space = -1, do_inodes = -1, do_uptime = -1;
 
     if (unlikely(do_uptime == -1)) {
-        do_context              = config_get_boolean("plugin:freebsd:sysctl", "context switches", 1);
         do_forks                = config_get_boolean("plugin:freebsd:sysctl", "processes started", 1);
         do_disk_io              = config_get_boolean("plugin:freebsd:sysctl", "stats for all disks", 1);
         do_swap                 = config_get_boolean("plugin:freebsd:sysctl", "system swap", 1);
@@ -761,27 +800,6 @@ int do_freebsd_sysctl_old(int update_every, usec_t dt) {
 
     // --------------------------------------------------------------------
 
-    if (likely(do_context)) {
-        if (unlikely(GETSYSCTL_BY_NAME("vm.stats.sys.v_swtch", u_int_data))) {
-            do_context = 0;
-            error("DISABLED: system.ctxt");
-        } else {
-
-            st = rrdset_find_bytype_localhost("system", "ctxt");
-            if (unlikely(!st)) {
-                st = rrdset_create_localhost("system", "ctxt", NULL, "processes", NULL, "CPU Context Switches", "context switches/s", 800, update_every, RRDSET_TYPE_LINE);
-
-                rrddim_add(st, "switches", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
-            }
-            else rrdset_next(st);
-
-            rrddim_set(st, "switches", u_int_data);
-            rrdset_done(st);
-        }
-    }
-
-    // --------------------------------------------------------------------
-
     if (likely(do_forks)) {
         if (unlikely(GETSYSCTL_BY_NAME("vm.stats.vm.v_forks", u_int_data))) {
             do_forks = 0;
index c180aa8f6fd7be9a114196226591b0ccd4f7d779..3b1110a62ed98e7eda276aa4bcd4c0f14ce40ae1 100644 (file)
@@ -23,6 +23,7 @@ static struct freebsd_module {
         { .name = "hw.intrcnt", .dim = "hw_intrcnt", .enabled = 1, .func = do_hw_intcnt },
         { .name = "vm.stats.sys.v_intr", .dim = "dev_intrcnt", .enabled = 1, .func = do_vm_stats_sys_v_intr },
         { .name = "vm.stats.sys.v_soft", .dim = "dev_intrcnt", .enabled = 1, .func = do_vm_stats_sys_v_soft },
+        { .name = "vm.stats.sys.v_swtch", .dim = "dev_intrcnt", .enabled = 1, .func = do_vm_stats_sys_v_swtch },
 
         // the terminator of this array
         { .name = NULL, .dim = NULL, .enabled = 0, .func = NULL }
index 3d8b09a4d6d5f6d175297cc8ad73545a84902411..6ad083fb859651d74e2e947b9bfc402fedd81e1a 100644 (file)
@@ -14,6 +14,7 @@ extern int do_kern_cp_times(int update_every, usec_t dt);
 extern int do_hw_intcnt(int update_every, usec_t dt);
 extern int do_vm_stats_sys_v_intr(int update_every, usec_t dt);
 extern int do_vm_stats_sys_v_soft(int update_every, usec_t dt);
+extern int do_vm_stats_sys_v_swtch(int update_every, usec_t dt);
 extern int do_freebsd_sysctl_old(int update_every, usec_t dt);
 
 #define GETSYSCTL_MIB(name, mib) getsysctl_mib(name, mib, sizeof(mib)/sizeof(int))