summaryrefslogtreecommitdiffstats
path: root/src/collectors/common-contexts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/collectors/common-contexts/common-contexts.h29
-rw-r--r--src/collectors/common-contexts/disk.io.h44
-rw-r--r--src/collectors/common-contexts/mem.available.h35
-rw-r--r--src/collectors/common-contexts/mem.pgfaults.h40
-rw-r--r--src/collectors/common-contexts/mem.swap.h35
-rw-r--r--src/collectors/common-contexts/system.io.h38
-rw-r--r--src/collectors/common-contexts/system.processes.h115
-rw-r--r--src/collectors/common-contexts/system.ram.h68
8 files changed, 404 insertions, 0 deletions
diff --git a/src/collectors/common-contexts/common-contexts.h b/src/collectors/common-contexts/common-contexts.h
new file mode 100644
index 000000000..9d2d77147
--- /dev/null
+++ b/src/collectors/common-contexts/common-contexts.h
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef NETDATA_COMMON_CONTEXTS_H
+#define NETDATA_COMMON_CONTEXTS_H
+
+#include "../../libnetdata/libnetdata.h"
+#include "../../database/rrd.h"
+
+#ifndef _COMMON_PLUGIN_NAME
+#error You need to set _COMMON_PLUGIN_NAME before including common-contexts.h
+#endif
+
+#ifndef _COMMON_PLUGIN_MODULE_NAME
+#error You need to set _COMMON_PLUGIN_MODULE_NAME before including common-contexts.h
+#endif
+
+#define _COMMON_CONFIG_SECTION "plugin:" _COMMON_PLUGIN_NAME ":" _COMMON_PLUGIN_MODULE_NAME
+
+typedef void (*instance_labels_cb_t)(RRDSET *st, void *data);
+
+#include "system.io.h"
+#include "system.ram.h"
+#include "system.processes.h"
+#include "mem.swap.h"
+#include "mem.pgfaults.h"
+#include "mem.available.h"
+#include "disk.io.h"
+
+#endif //NETDATA_COMMON_CONTEXTS_H
diff --git a/src/collectors/common-contexts/disk.io.h b/src/collectors/common-contexts/disk.io.h
new file mode 100644
index 000000000..26f98b9be
--- /dev/null
+++ b/src/collectors/common-contexts/disk.io.h
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef NETDATA_DISK_IO_H
+#define NETDATA_DISK_IO_H
+
+#include "common-contexts.h"
+
+typedef struct {
+ RRDSET *st_io;
+ RRDDIM *rd_io_reads;
+ RRDDIM *rd_io_writes;
+} ND_DISK_IO;
+
+static inline void common_disk_io(ND_DISK_IO *d, const char *id, const char *name, uint64_t bytes_read, uint64_t bytes_write, int update_every, instance_labels_cb_t cb, void *data) {
+ if(unlikely(!d->st_io)) {
+ d->st_io = rrdset_create_localhost(
+ "disk"
+ , id
+ , name
+ , "io"
+ , "disk.io"
+ , "Disk I/O Bandwidth"
+ , "KiB/s"
+ , _COMMON_PLUGIN_NAME
+ , _COMMON_PLUGIN_MODULE_NAME
+ , NETDATA_CHART_PRIO_DISK_IO
+ , update_every
+ , RRDSET_TYPE_AREA
+ );
+
+ d->rd_io_reads = rrddim_add(d->st_io, "reads", NULL, 1, 1024, RRD_ALGORITHM_INCREMENTAL);
+ d->rd_io_writes = rrddim_add(d->st_io, "writes", NULL, -1, 1024, RRD_ALGORITHM_INCREMENTAL);
+
+ if(cb)
+ cb(d->st_io, data);
+ }
+
+ // this always have to be in base units, so that exporting sends base units to other time-series db
+ rrddim_set_by_pointer(d->st_io, d->rd_io_reads, (collected_number)bytes_read);
+ rrddim_set_by_pointer(d->st_io, d->rd_io_writes, (collected_number)bytes_write);
+ rrdset_done(d->st_io);
+}
+
+#endif //NETDATA_DISK_IO_H
diff --git a/src/collectors/common-contexts/mem.available.h b/src/collectors/common-contexts/mem.available.h
new file mode 100644
index 000000000..3f763fe18
--- /dev/null
+++ b/src/collectors/common-contexts/mem.available.h
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef NETDATA_MEM_AVAILABLE_H
+#define NETDATA_MEM_AVAILABLE_H
+#include "common-contexts.h"
+
+static inline void common_mem_available(uint64_t available_bytes, int update_every) {
+ static RRDSET *st_mem_available = NULL;
+ static RRDDIM *rd_avail = NULL;
+
+ if(unlikely(!st_mem_available)) {
+ st_mem_available = rrdset_create_localhost(
+ "mem"
+ , "available"
+ , NULL
+ , "overview"
+ , NULL
+ , "Available RAM for applications"
+ , "MiB"
+ , _COMMON_PLUGIN_NAME
+ , _COMMON_PLUGIN_MODULE_NAME
+ , NETDATA_CHART_PRIO_MEM_SYSTEM_AVAILABLE
+ , update_every
+ , RRDSET_TYPE_AREA
+ );
+
+ rd_avail = rrddim_add(st_mem_available, "avail", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
+ }
+
+ // this always have to be in base units, so that exporting sends base units to other time-series db
+ rrddim_set_by_pointer(st_mem_available, rd_avail, (collected_number)available_bytes);
+ rrdset_done(st_mem_available);
+}
+
+#endif //NETDATA_MEM_AVAILABLE_H
diff --git a/src/collectors/common-contexts/mem.pgfaults.h b/src/collectors/common-contexts/mem.pgfaults.h
new file mode 100644
index 000000000..503b9f7e8
--- /dev/null
+++ b/src/collectors/common-contexts/mem.pgfaults.h
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef NETDATA_MEM_PGFAULTS_H
+#define NETDATA_MEM_PGFAULTS_H
+
+#include "common-contexts.h"
+
+static inline void common_mem_pgfaults(uint64_t minor, uint64_t major, int update_every) {
+ static RRDSET *st_pgfaults = NULL;
+ static RRDDIM *rd_minor = NULL, *rd_major = NULL;
+
+ if(unlikely(!st_pgfaults)) {
+ st_pgfaults = rrdset_create_localhost(
+ "mem"
+ , "pgfaults"
+ , NULL
+ , "page faults"
+ , NULL
+ , "Memory Page Faults"
+ , "faults/s"
+ , _COMMON_PLUGIN_NAME
+ , _COMMON_PLUGIN_MODULE_NAME
+ , NETDATA_CHART_PRIO_MEM_SYSTEM_PGFAULTS
+ , update_every
+ , RRDSET_TYPE_LINE
+ );
+
+ rrdset_flag_set(st_pgfaults, RRDSET_FLAG_DETAIL);
+
+ rd_minor = rrddim_add(st_pgfaults, "minor", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
+ rd_major = rrddim_add(st_pgfaults, "major", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
+ }
+
+ // this always have to be in base units, so that exporting sends base units to other time-series db
+ rrddim_set_by_pointer(st_pgfaults, rd_minor, minor);
+ rrddim_set_by_pointer(st_pgfaults, rd_major, major);
+ rrdset_done(st_pgfaults);
+}
+
+#endif //NETDATA_MEM_PGFAULTS_H
diff --git a/src/collectors/common-contexts/mem.swap.h b/src/collectors/common-contexts/mem.swap.h
new file mode 100644
index 000000000..6d692ef3b
--- /dev/null
+++ b/src/collectors/common-contexts/mem.swap.h
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "common-contexts.h"
+
+static inline void common_mem_swap(uint64_t free_bytes, uint64_t used_bytes, int update_every) {
+ static RRDSET *st_system_swap = NULL;
+ static RRDDIM *rd_free = NULL, *rd_used = NULL;
+
+ if(unlikely(!st_system_swap)) {
+ st_system_swap = rrdset_create_localhost(
+ "mem"
+ , "swap"
+ , NULL
+ , "swap"
+ , NULL
+ , "System Swap"
+ , "MiB"
+ , _COMMON_PLUGIN_NAME
+ , _COMMON_PLUGIN_MODULE_NAME
+ , NETDATA_CHART_PRIO_MEM_SWAP
+ , update_every
+ , RRDSET_TYPE_STACKED
+ );
+
+ rrdset_flag_set(st_system_swap, RRDSET_FLAG_DETAIL);
+
+ rd_free = rrddim_add(st_system_swap, "free", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
+ rd_used = rrddim_add(st_system_swap, "used", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
+ }
+
+ // this always have to be in base units, so that exporting sends base units to other time-series db
+ rrddim_set_by_pointer(st_system_swap, rd_used, (collected_number)used_bytes);
+ rrddim_set_by_pointer(st_system_swap, rd_free, (collected_number)free_bytes);
+ rrdset_done(st_system_swap);
+}
diff --git a/src/collectors/common-contexts/system.io.h b/src/collectors/common-contexts/system.io.h
new file mode 100644
index 000000000..84440c9b8
--- /dev/null
+++ b/src/collectors/common-contexts/system.io.h
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef NETDATA_SYSTEM_IO_H
+#define NETDATA_SYSTEM_IO_H
+
+#include "common-contexts.h"
+
+static inline void common_system_io(uint64_t read_bytes, uint64_t write_bytes, int update_every) {
+ static RRDSET *st_io = NULL;
+ static RRDDIM *rd_in = NULL, *rd_out = NULL;
+
+ if(unlikely(!st_io)) {
+ st_io = rrdset_create_localhost(
+ "system"
+ , "io"
+ , NULL
+ , "disk"
+ , NULL
+ , "Disk I/O"
+ , "KiB/s"
+ , _COMMON_PLUGIN_NAME
+ , _COMMON_PLUGIN_MODULE_NAME
+ , NETDATA_CHART_PRIO_SYSTEM_IO
+ , update_every
+ , RRDSET_TYPE_AREA
+ );
+
+ rd_in = rrddim_add(st_io, "in", "reads", 1, 1024, RRD_ALGORITHM_INCREMENTAL);
+ rd_out = rrddim_add(st_io, "out", "writes", -1, 1024, RRD_ALGORITHM_INCREMENTAL);
+ }
+
+ // this always have to be in base units, so that exporting sends base units to other time-series db
+ rrddim_set_by_pointer(st_io, rd_in, (collected_number)read_bytes);
+ rrddim_set_by_pointer(st_io, rd_out, (collected_number)write_bytes);
+ rrdset_done(st_io);
+}
+
+#endif //NETDATA_SYSTEM_IO_H
diff --git a/src/collectors/common-contexts/system.processes.h b/src/collectors/common-contexts/system.processes.h
new file mode 100644
index 000000000..1b886d65f
--- /dev/null
+++ b/src/collectors/common-contexts/system.processes.h
@@ -0,0 +1,115 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef NETDATA_SYSTEM_PROCESSES_H
+#define NETDATA_SYSTEM_PROCESSES_H
+
+#include "common-contexts.h"
+
+#define _system_process_chart() \
+ rrdset_create_localhost( \
+ "system" \
+ , "processes" \
+ , NULL \
+ , "processes" \
+ , NULL \
+ , "System Processes" \
+ , "processes" \
+ , _COMMON_PLUGIN_NAME \
+ , _COMMON_PLUGIN_MODULE_NAME \
+ , NETDATA_CHART_PRIO_SYSTEM_PROCESSES \
+ , update_every \
+ , RRDSET_TYPE_LINE \
+ )
+
+#if defined(OS_WINDOWS)
+static inline void common_system_processes(uint64_t running, int update_every) {
+ static RRDSET *st_processes = NULL;
+ static RRDDIM *rd_running = NULL;
+
+ if(unlikely(!st_processes)) {
+ st_processes = _system_process_chart();
+
+ rd_running = rrddim_add(st_processes, "running", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
+ }
+
+ rrddim_set_by_pointer(st_processes, rd_running, running);
+ rrdset_done(st_processes);
+}
+
+// EBPF COUNTER PART
+static inline void common_system_threads(uint64_t threads, int update_every) {
+ static RRDSET *st_threads = NULL;
+ static RRDDIM *rd_threads = NULL;
+
+ if(unlikely(!st_threads)) {
+ st_threads = rrdset_create_localhost(
+ "system"
+ , "threads"
+ , NULL
+ , "processes"
+ , NULL
+ , "Threads"
+ , "threads"
+ , _COMMON_PLUGIN_NAME
+ , _COMMON_PLUGIN_MODULE_NAME
+ , NETDATA_CHART_PRIO_WINDOWS_THREADS
+ , update_every
+ , RRDSET_TYPE_LINE
+ );
+
+ rd_threads = rrddim_add(st_threads, "threads", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
+ }
+
+ rrddim_set_by_pointer(st_threads, rd_threads, threads);
+ rrdset_done(st_threads);
+}
+#endif
+
+#if defined(OS_LINUX)
+static inline void common_system_processes(uint64_t running, uint64_t blocked, int update_every) {
+ static RRDSET *st_processes = NULL;
+ static RRDDIM *rd_running = NULL;
+ static RRDDIM *rd_blocked = NULL;
+
+ if(unlikely(!st_processes)) {
+ st_processes = _system_process_chart();
+
+ rd_running = rrddim_add(st_processes, "running", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
+ rd_blocked = rrddim_add(st_processes, "blocked", NULL, -1, 1, RRD_ALGORITHM_ABSOLUTE);
+ }
+
+ rrddim_set_by_pointer(st_processes, rd_running, (collected_number)running);
+ rrddim_set_by_pointer(st_processes, rd_blocked, (collected_number)blocked);
+ rrdset_done(st_processes);
+}
+#endif
+
+static inline void common_system_context_switch(uint64_t value, int update_every) {
+ static RRDSET *st_ctxt = NULL;
+ static RRDDIM *rd_switches = NULL;
+
+ if(unlikely(!st_ctxt)) {
+ st_ctxt = rrdset_create_localhost(
+ "system"
+ , "ctxt"
+ , NULL
+ , "processes"
+ , NULL
+ , "CPU Context Switches"
+ , "context switches/s"
+ , _COMMON_PLUGIN_NAME
+ , _COMMON_PLUGIN_MODULE_NAME
+ , NETDATA_CHART_PRIO_SYSTEM_CTXT
+ , update_every
+ , RRDSET_TYPE_LINE
+ );
+
+ rd_switches = rrddim_add(st_ctxt, "switches", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
+ }
+
+ rrddim_set_by_pointer(st_ctxt, rd_switches, (collected_number)value);
+ rrdset_done(st_ctxt);
+}
+
+
+#endif //NETDATA_SYSTEM_PROCESSES_H
diff --git a/src/collectors/common-contexts/system.ram.h b/src/collectors/common-contexts/system.ram.h
new file mode 100644
index 000000000..6b108405c
--- /dev/null
+++ b/src/collectors/common-contexts/system.ram.h
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef NETDATA_SYSTEM_RAM_H
+#define NETDATA_SYSTEM_RAM_H
+
+#include "common-contexts.h"
+
+#define _system_ram_chart() \
+ rrdset_create_localhost( \
+ "system" \
+ , "ram" \
+ , NULL \
+ , "ram" \
+ , NULL \
+ , "System RAM" \
+ , "MiB" \
+ , _COMMON_PLUGIN_NAME \
+ , _COMMON_PLUGIN_MODULE_NAME \
+ , NETDATA_CHART_PRIO_SYSTEM_RAM \
+ , update_every \
+ , RRDSET_TYPE_STACKED \
+ )
+
+#ifdef OS_WINDOWS
+static inline void common_system_ram(uint64_t free_bytes, uint64_t used_bytes, int update_every) {
+ static RRDSET *st_system_ram = NULL;
+ static RRDDIM *rd_free = NULL;
+ static RRDDIM *rd_used = NULL;
+
+ if(unlikely(!st_system_ram)) {
+ st_system_ram = _system_ram_chart();
+ rd_free = rrddim_add(st_system_ram, "free", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
+ rd_used = rrddim_add(st_system_ram, "used", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
+ }
+
+ // this always have to be in base units, so that exporting sends base units to other time-series db
+ rrddim_set_by_pointer(st_system_ram, rd_free, (collected_number)free_bytes);
+ rrddim_set_by_pointer(st_system_ram, rd_used, (collected_number)used_bytes);
+ rrdset_done(st_system_ram);
+}
+#endif
+
+#ifdef OS_LINUX
+static inline void common_system_ram(uint64_t free_bytes, uint64_t used_bytes, uint64_t cached_bytes, uint64_t buffers_bytes, int update_every) {
+ static RRDSET *st_system_ram = NULL;
+ static RRDDIM *rd_free = NULL;
+ static RRDDIM *rd_used = NULL;
+ static RRDDIM *rd_cached = NULL;
+ static RRDDIM *rd_buffers = NULL;
+
+ if(unlikely(!st_system_ram)) {
+ st_system_ram = _system_ram_chart();
+ rd_free = rrddim_add(st_system_ram, "free", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
+ rd_used = rrddim_add(st_system_ram, "used", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
+ rd_cached = rrddim_add(st_system_ram, "cached", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
+ rd_buffers = rrddim_add(st_system_ram, "buffers", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
+ }
+
+ // this always have to be in base units, so that exporting sends base units to other time-series db
+ rrddim_set_by_pointer(st_system_ram, rd_free, (collected_number)free_bytes);
+ rrddim_set_by_pointer(st_system_ram, rd_used, (collected_number)used_bytes);
+ rrddim_set_by_pointer(st_system_ram, rd_cached, (collected_number)cached_bytes);
+ rrddim_set_by_pointer(st_system_ram, rd_buffers, (collected_number)buffers_bytes);
+ rrdset_done(st_system_ram);
+}
+#endif
+
+#endif //NETDATA_SYSTEM_RAM_H