diff --git a/Makefile.am b/Makefile.am index de38e4b..715d2d8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,7 +7,8 @@ SUBDIRS = \ . \ src/evcollect \ plugins/eventql \ - plugins/hostname + plugins/hostname \ + plugins/unix_stats EXTRA_DIST = \ doc \ diff --git a/configure.ac b/configure.ac index 5691562..ad37b5a 100644 --- a/configure.ac +++ b/configure.ac @@ -64,5 +64,5 @@ AM_CONDITIONAL([HAVE_ZLIB], [test $HAVE_ZLIB = 1]) ACX_PTHREAD AM_CONDITIONAL([HAVE_PTHREAD], [test "x$acx_pthread_ok" = "xyes"]) -AC_CONFIG_FILES([Makefile src/evcollect/Makefile plugins/hostname/Makefile plugins/eventql/Makefile]) +AC_CONFIG_FILES([Makefile src/evcollect/Makefile plugins/hostname/Makefile plugins/eventql/Makefile plugins/unix_stats/Makefile]) AC_OUTPUT diff --git a/plugins/unix_stats/Makefile.am b/plugins/unix_stats/Makefile.am new file mode 100644 index 0000000..e7f5945 --- /dev/null +++ b/plugins/unix_stats/Makefile.am @@ -0,0 +1,32 @@ +MAINTAINERCLEANFILES = Makefile.in + +AM_CXXFLAGS = -std=c++0x -Wall -Wextra -Wdelete-non-virtual-dtor -g -fvisibility=hidden -I$(top_srcdir)/src +AM_CFLAGS = -std=c11 -Wall -pedantic -g +AM_LDFLAGS = -fvisibility=hidden -module -avoid-version -shared -export-dynamic -static-libstdc++ -static-libgcc -rpath $(libdir) + +noinst_LTLIBRARIES = plugin_unix_stats.la + +plugin_unix_stats_la_SOURCES = \ + util/stringutil.cc \ + util/stringutil.h \ + util/stringutil_impl.h \ + util/time.cc \ + util/time.h \ + util/time_impl.h \ + disk_stats.h \ + disk_stats.cc \ + kernel_stats.h \ + kernel_stats.cc \ + process_stats.h \ + process_stats.cc \ + unix_stats_plugin.cc + +PLUGINDIR=$(DESTDIR)$(libdir)/evcollect/plugins + +install-data-hook: $(noinst_LTLIBRARIES) + @for soname in `echo | $(EGREP) "^dlname=" $^ | $(SED) -e "s|^dlname='\(.*\)'|\1|"`; do \ + mkdir -p ${PLUGINDIR}; \ + echo Installing $$soname to ${PLUGINDIR}; \ + cp $(abs_builddir)/.libs/$$soname ${PLUGINDIR}; \ + done + diff --git a/plugins/unix_stats/disk_stats.cc b/plugins/unix_stats/disk_stats.cc new file mode 100644 index 0000000..32282c2 --- /dev/null +++ b/plugins/unix_stats/disk_stats.cc @@ -0,0 +1,135 @@ +/** + * Copyright (c) 2016 DeepCortex GmbH + * Authors: + * - Paul Asmuth + * - Laura Schlimmer + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License ("the license") as + * published by the Free Software Foundation, either version 3 of the License, + * or any later version. + * + * In accordance with Section 7(e) of the license, the licensing of the Program + * under the license does not imply a trademark license. Therefore any rights, + * title and interest in our trademarks remain entirely with us. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the license for more details. + * + * You can be released from the requirements of the license by purchasing a + * commercial license. Buying such a license is mandatory as soon as you develop + * commercial activities involving this program without disclosing the source + * code of your own applications + */ + +#include +#include +#include +#include "util/stringutil.h" +#include "disk_stats.h" + +#if __linux__ +#include +#endif + +#if __APPLE__ +#include +#endif + +namespace evcollect { +namespace plugin_unix_stats { + +std::vector getMountInfo() { + std::vector mount_info; + +#if __linux__ + + auto file = setmntent(MOUNTED, "r"); + while (auto mntent = getmntent(file)) { + MountInfo mn_info = { + .device = mntent->mnt_fsname, + .mount_point = mntent->mnt_dir + }; + + mount_info.emplace_back(mn_info); + } + fclose(file); + +#elif __APPLE__ + struct statfs* mntbuf; + auto mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); + for (auto i = 0; i < mntsize; ++i) { + MountInfo mn_info = { + .device = mntbuf[i].f_mntfromname, + .mount_point = mntbuf[i].f_mntonname + }; + + mount_info.emplace_back(mn_info); + } + +#endif + + return mount_info; +} + + +bool getDiskInfo(std::vector disk_info) { + auto mount_info = getMountInfo(); + + for (size_t i = 0; i < mount_info.size(); ++i) { + struct statvfs buf; + if (statvfs(mount_info[i].mount_point.c_str(), &buf) == -1) { + continue; + } + + DiskInfo di; + di.total = buf.f_blocks * buf.f_frsize; + di.available = buf.f_bavail * buf.f_frsize; + di.used = di.total - di.available; + di.capacity = di.total > 0 ? (di.used / di.total) * 100 : 100; + di.ifree = buf.f_favail; + di.iused = buf.f_files - di.ifree; + + disk_info.emplace_back(di); + } + + return true; +} + +std::string toJSON(std::vector disk_info) { + std::string json; + json.append(R"({disk: )"); + + for (size_t i = 0; i < disk_info.size(); ++i) { + if (i > 0) { + json.append(","); + } + + json.append(StringUtil::format(R"([ + "filesystem": $0, + "mount_point": $1, + "total": $2, + "available": $3, + "used": $4, + "capacity": $5, + "ifree": $6, + "iused": $7 + ])", + disk_info[i].filesystem, + disk_info[i].mount_point, + disk_info[i].total, + disk_info[i].available, + disk_info[i].used, + disk_info[i].capacity, + disk_info[i].ifree, + disk_info[i].used + )); + } + + json.append("}"); + return json; +} + +} //namespace plugin_unix_stats +} //namespace evcollect diff --git a/plugins/unix_stats/disk_stats.h b/plugins/unix_stats/disk_stats.h new file mode 100644 index 0000000..76e072d --- /dev/null +++ b/plugins/unix_stats/disk_stats.h @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2016 DeepCortex GmbH + * Authors: + * - Paul Asmuth + * - Laura Schlimmer + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License ("the license") as + * published by the Free Software Foundation, either version 3 of the License, + * or any later version. + * + * In accordance with Section 7(e) of the license, the licensing of the Program + * under the license does not imply a trademark license. Therefore any rights, + * title and interest in our trademarks remain entirely with us. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the license for more details. + * + * You can be released from the requirements of the license by purchasing a + * commercial license. Buying such a license is mandatory as soon as you develop + * commercial activities involving this program without disclosing the source + * code of your own applications + */ + +#include + +namespace evcollect { +namespace plugin_unix_stats { + +struct MountInfo { + std::string device; + std::string mount_point; +}; + +struct DiskInfo { + std::string filesystem; + std::string mount_point; + uint64_t total; + uint64_t used; + uint64_t available; + uint8_t capacity; + uint64_t iused; + uint64_t ifree; +}; + + +bool getDiskInfo(std::vector disk_info); + +std::string toJSON(std::vector disk_info); + +} //namespace plugin_unix_stats +} //namespace evcollect diff --git a/plugins/unix_stats/kernel_stats.cc b/plugins/unix_stats/kernel_stats.cc new file mode 100644 index 0000000..86b092a --- /dev/null +++ b/plugins/unix_stats/kernel_stats.cc @@ -0,0 +1,185 @@ +/** + * Copyright (c) 2016 DeepCortex GmbH + * Authors: + * - Paul Asmuth + * - Laura Schlimmer + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License ("the license") as + * published by the Free Software Foundation, either version 3 of the License, + * or any later version. + * + * In accordance with Section 7(e) of the license, the licensing of the Program + * under the license does not imply a trademark license. Therefore any rights, + * title and interest in our trademarks remain entirely with us. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the license for more details. + * + * You can be released from the requirements of the license by purchasing a + * commercial license. Buying such a license is mandatory as soon as you develop + * commercial activities involving this program without disclosing the source + * code of your own applications + */ +#include "kernel_stats.h" +#include "util/stringutil.h" + +#if __linux__ +#include +#include +#endif + +#if __APPLE__ +#include "util/time.h" +#include +#endif + + +namespace evcollect { +namespace plugin_unix_stats { + +bool getKernelInfo(KernelInfo kernel_info) { +#if __linux__ + /* load averages and uptime */ + { + struct sysinfo info; + if (sysinfo(&info) == -1) { + //evcollect_seterror(ctx, "sysinfo failed"); + return false; + } + + /* load average for the last 1, 5 and 15 minutes */ + switch (sizeof(info.loads) / sizeof(info.loads[0])) { + case 3: + kernel_info.load_avg.min15 = info.loads[2]; + + case 2: + kernel_info.load_avg.min15 = info.loads[1]; + + case 1: + kernel_info.load_avg.min5 = info.loads[0]; + } + + kernel_info.uptime = info.uptime; + } + + /* kernel version */ + { + struct utsname info; + if (uname(&info) == -1) { + return false; + } + + kernel_info.version = info.version; + } + + /* kernel arguments */ + { + auto file = fopen("/proc/cmdline", "r"); + if (!file) { + return false; + } + + char buf[256]; //FIXME size + while (fgets(buf, sizeof(buf), file)) { + kernel_info.arguments.append(buf); + } + + fclose(file); + } +#elif __APPLE__ + + /* load averages */ + { + struct loadavg loadinfo; + size_t size = sizeof(loadinfo); + + if (sysctlbyname("vm.loadavg", &loadinfo, &size, NULL, 0) == -1) { + //evcollect_seterror( + // ctx, + // StringUtil::format("sysctlbyname failed: $0", strerror(errno)).c_str()); + return false; + } + + /* load average for the last 1, 5 and 15 minutes */ + switch (sizeof(loadinfo.ldavg) / sizeof(fixpt_t)) { + case 3: + kernel_info.load_avg.min15 = (double) loadinfo.ldavg[2] / loadinfo.fscale; + + case 2: + kernel_info.load_avg.min15 = (double) loadinfo.ldavg[1] / loadinfo.fscale; + + case 1: + kernel_info.load_avg.min5 = (double) loadinfo.ldavg[0] / loadinfo.fscale; + } + } + + /* uptime */ + { + struct timeval t; + size_t size = sizeof(t); + if (sysctlbyname("kern.boottime", &t, &size, NULL, 0) == -1) { + //evcollect_seterror( + // ctx, + // StringUtil::format("sysctlbyname failed: $0", strerror(errno)).c_str()); + return false; + } + + UnixTime now; + kernel_info.uptime = (now.unixMicros() / kMicrosPerSecond) - t.tv_sec; + } + + /* kernel version */ + { + int mib[2] = {CTL_KERN, KERN_VERSION}; + size_t len = 256; + char version[len]; + if (sysctl(mib, 2, version, &len, NULL, 0) == -1) { + return false; + } + + kernel_info.version = version; + } + + /* kernel version */ + { + int mib[2] = {CTL_KERN, KERN_VERSION}; + size_t len = 256; + char version[len]; + if (sysctl(mib, 2, version, &len, NULL, 0) == -1) { + return false; + } + + kernel_info.version = version; + } +#endif + + return true; +} + +std::string toJSON(KernelInfo kernel_info) { + std::string json = StringUtil::format(R"({ + "uptime": $0, + "load_avg": { + "min1": $1, + "min5": $2, + "min15": $3 + }, + "version": "$4", + "arguments": "$5" + })", + kernel_info.uptime, + kernel_info.load_avg.min1, + kernel_info.load_avg.min5, + kernel_info.load_avg.min15, + kernel_info.version, + kernel_info.arguments); + + return json; +} + +} //namespace plugin_unix_stats +} //namespace evcollect + + diff --git a/plugins/unix_stats/kernel_stats.h b/plugins/unix_stats/kernel_stats.h new file mode 100644 index 0000000..e8e77ec --- /dev/null +++ b/plugins/unix_stats/kernel_stats.h @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2016 DeepCortex GmbH + * Authors: + * - Paul Asmuth + * - Laura Schlimmer + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License ("the license") as + * published by the Free Software Foundation, either version 3 of the License, + * or any later version. + * + * In accordance with Section 7(e) of the license, the licensing of the Program + * under the license does not imply a trademark license. Therefore any rights, + * title and interest in our trademarks remain entirely with us. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the license for more details. + * + * You can be released from the requirements of the license by purchasing a + * commercial license. Buying such a license is mandatory as soon as you develop + * commercial activities involving this program without disclosing the source + * code of your own applications + */ + +#include +#include + +namespace evcollect { +namespace plugin_unix_stats { + +struct LoadAvg { + double min1; + double min5; + double min15; +}; + +struct KernelInfo { + uint64_t uptime; + plugin_unix_stats::LoadAvg load_avg; + + std::string version; + std::string arguments; /* linux only */ +}; + + +bool getKernelInfo(KernelInfo kernel_info); + +std::string toJSON(KernelInfo kernel_info); + +} //namespace plugin_unix_stats +} //namespace evcollect + diff --git a/plugins/unix_stats/process_stats.cc b/plugins/unix_stats/process_stats.cc new file mode 100644 index 0000000..24f8c98 --- /dev/null +++ b/plugins/unix_stats/process_stats.cc @@ -0,0 +1,217 @@ +/** + * Copyright (c) 2016 DeepCortex GmbH + * Authors: + * - Paul Asmuth + * - Laura Schlimmer + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License ("the license") as + * published by the Free Software Foundation, either version 3 of the License, + * or any later version. + * + * In accordance with Section 7(e) of the license, the licensing of the Program + * under the license does not imply a trademark license. Therefore any rights, + * title and interest in our trademarks remain entirely with us. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the license for more details. + * + * You can be released from the requirements of the license by purchasing a + * commercial license. Buying such a license is mandatory as soon as you develop + * commercial activities involving this program without disclosing the source + * code of your own applications + */ + +#include "util/stringutil.h" +#include "process_stats.h" +#include "util/stringutil.h" +#if __linux__ +#include +//#include +#include +//#include +#endif + +#if __APPLE__ +#include +#endif + +namespace evcollect { +namespace plugin_unix_stats { + + +bool getProcessInfo(std::vector process_info) { +#if __linux__ + auto dir = opendir("/proc/"); + if (!dir) { + // //StringUtil::format("opendir failed: $0", strerror(errno)).c_str()); + return false; + } + + for (;;) { + auto entry = readdir(dir); + /* end of directory */ + if (!entry) { + break; + } + + /* skip if not one of the /proc/{pid} directories */ + if (entry->d_type != DT_DIR || (!StringUtil::isNumber(entry->d_name))) { + continue; + } + + auto file_name = StringUtil::format("/proc/$0/stat", entry->d_name); + std::ifstream file( + file_name.c_str(), + std::ifstream::in); + + if (!file.is_open()) { + return false; + } + + size_t i = 0; + std::string buf; + ProcessInfo info; + while (!file.eof()) { + char c; + file.get(c); + if (isspace(c)) { + switch (i++) { + case 0: /* process id */ + info.pid = std::stoull(buf); + break; + + case 1: /* filename of the executable */ + info.name = buf; + break; + + case 2: /* process state */ + info.state = buf; + break; + + case 3: /* parent PID */ + info.ppid = std::stoull(buf); + break; + + case 4: /* group ID */ + info.pgrp = std::stoull(buf); + break; + + case 13: /* time in user mode */ + info.utime = std::stoull(buf); + break; + + case 14: /* time in kernel mode */ + info.stime = std::stoull(buf); + break; + + case 18: /* nice value */ + info.nice = std::stoul(buf); + break; + + case 21: /* starttime */ + info.starttime = std::stoull(buf); + break; + + case 22: /* virtual memory size */ + info.vsize = std::stoull(buf); + break; + + default: + break; + } + + buf.clear(); + } else { + buf.push_back(c); + } + } + + process_info.emplace_back(info); + } + + closedir(dir); + +#elif __APPLE__ + size_t len = 0; + int name[3] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL}; + /* size of kinfo_proc */ + if (sysctl(name, 3, NULL, &len, NULL, 0) == -1) { + // StringUtil::format("sysctl failed: $0", strerror(errno)).c_str()); + return false; + } + + struct kinfo_proc* info; + info = static_cast(malloc(len)); + if (sysctl(name, 3, info, &len, NULL, 0) == -1) { + free(info); + // StringUtil::format("sysctl failed: $0", strerror(errno)).c_str()); + return false; + } + + int count = len / sizeof(kinfo_proc); + for (int i = 0; i < count; ++i) { + pid_t pid = info[i].kp_proc.p_pid; + if (pid == 0) { + continue; + } + + struct ProcessInfo pinfo; + pinfo.pid = pid; + pinfo.ppid = info[i].kp_eproc.e_ppid; + pinfo.pgrp = info[i].kp_eproc.e_pgid; + pinfo.nice = (uint64_t) info[i].kp_proc.p_nice; + pinfo.starttime = (uint64_t) info[i].kp_proc.p_un.__p_starttime.tv_sec; + pinfo.state = info[i].kp_proc.p_stat; + + process_info.emplace_back(pinfo); + } + + free(info); +#endif + return true; +} + +std::string toJSON(std::vector process_list) { + std::string json = "{process: "; + + for (size_t i = 0; i < process_list.size(); ++i) { + if (i > 0) { + json.append(","); + } + + + json.append(StringUtil::format(R"([ + "pid": $0, + "name": "$1", + "state": "$2", + "ppid": $3, + "pgrp": $4, + "utime": $5, + "stime": $6, + "nice": $7, + "starttime": $8, + "vsize": $9, + ])", + process_list[i].pid, + process_list[i].name, + process_list[i].state, + process_list[i].ppid, + process_list[i].pgrp, + process_list[i].utime, + process_list[i].stime, + process_list[i].nice, + process_list[i].starttime, + process_list[i].vsize)); + } + + json.append("}"); + + return json; +} + +} //namespace plugin_unix_stats +} //namespace evcollect + + diff --git a/plugins/unix_stats/process_stats.h b/plugins/unix_stats/process_stats.h new file mode 100644 index 0000000..1cd9d58 --- /dev/null +++ b/plugins/unix_stats/process_stats.h @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2016 DeepCortex GmbH + * Authors: + * - Paul Asmuth + * - Laura Schlimmer + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License ("the license") as + * published by the Free Software Foundation, either version 3 of the License, + * or any later version. + * + * In accordance with Section 7(e) of the license, the licensing of the Program + * under the license does not imply a trademark license. Therefore any rights, + * title and interest in our trademarks remain entirely with us. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the license for more details. + * + * You can be released from the requirements of the license by purchasing a + * commercial license. Buying such a license is mandatory as soon as you develop + * commercial activities involving this program without disclosing the source + * code of your own applications + */ + +#include + +namespace evcollect { +namespace plugin_unix_stats { + +struct ProcessInfo { + uint64_t pid; + std::string name; + std::string state; + uint64_t ppid; + uint64_t pgrp; + uint64_t utime; + uint64_t stime; + int8_t nice; + uint64_t starttime; + uint64_t vsize; +}; + +bool getProcessInfo(std::vector process_info); + +std::string toJSON(std::vector process_info); + +} //namespace plugin_unix_stats +} //namespace evcollect + diff --git a/plugins/unix_stats/unix_stats_plugin.cc b/plugins/unix_stats/unix_stats_plugin.cc new file mode 100644 index 0000000..61f3014 --- /dev/null +++ b/plugins/unix_stats/unix_stats_plugin.cc @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2016 DeepCortex GmbH + * Authors: + * - Paul Asmuth + * - Laura Schlimmer + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License ("the license") as + * published by the Free Software Foundation, either version 3 of the License, + * or any later version. + * + * In accordance with Section 7(e) of the license, the licensing of the Program + * under the license does not imply a trademark license. Therefore any rights, + * title and interest in our trademarks remain entirely with us. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the license for more details. + * + * You can be released from the requirements of the license by purchasing a + * commercial license. Buying such a license is mandatory as soon as you develop + * commercial activities involving this program without disclosing the source + * code of your own applications + */ +#include +#include +#include "disk_stats.h" +#include "kernel_stats.h" +#include "process_stats.h" + +namespace evcollect { +namespace plugin_unix_stats { + +int getEvent( + evcollect_ctx_t* ctx, + void* userdata, + evcollect_event_t* ev) { + + std::vector disk_info; + if (!getDiskInfo(disk_info)) { + return 0; + } + + KernelInfo kernel_info; + if (!getKernelInfo(kernel_info)) { + return 0; + } + + std::vector process_list; + if (!getProcessInfo(process_list)) { + return 0; + } + + std::string json; + json.append(toJSON(disk_info)); + json.append(toJSON(kernel_info)); + json.append(toJSON(process_list)); + + return 1; +} + +} // namespace plugin_unix_stats +} // namespace evcollect + +EVCOLLECT_PLUGIN_INIT(unix_stats) { + evcollect_source_plugin_register( + ctx, + "unix.stats", + &evcollect::plugin_unix_stats::getEvent, + NULL, + NULL, + NULL, + NULL, + NULL); + + return true; +} diff --git a/plugins/unix_stats/unix_stats_plugin.md b/plugins/unix_stats/unix_stats_plugin.md new file mode 100644 index 0000000..0f447a2 --- /dev/null +++ b/plugins/unix_stats/unix_stats_plugin.md @@ -0,0 +1,182 @@ +# evcollect unix.stats + +different plugins that can each used by itself or combined + +## Tables + +###unix.kernel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
uptimeIntegerSeconds of uptime
load_avg.min1DoubleLoad average during the last minute
load_avg.min5DoubleLoad average during the last five minutes
load_avg.min15DoubleLoad average during the last 15 minutes
argumentsStringKernel arguments
versionIntegerKernel version
+ + + CREATE TABLE unix.kernel ( + uptime UINT64, + load_avg RECORD (min1, min5, min15), + arguments STRING, + version STRING + ) + +###unix.disk_usage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
disk.filesystemStringThe name of the file system
disk.mount_pointStringThe mount point
disk.totalIntegerThe total size of the file system in bytes
disk.availableIntegerThe total free space in bytes
disk.usedIntegerThe total space used in the file system in bytes
disk.capacityIntegerThe percentage of space that is used between 0 and 100
disk.iusedIntegerThe number of used inodes
disk.ifreeIntegerThe number of free inodes
+ + + CREATE TABLE unix.disk ( + disk RECORD ( + filesystem STRING, + mount_point STRING, + total UINT64, + available UINT64, + used UINT64, + capacity UINT32, + iused UINT64, + ifree UINT64 + ) + ) + +###unix.processes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
process.pidIntegerThe process ID +
process.nameStringThe filename of the executable +
process.stateStringThe process state +
process.ppidIntegerThe parent PID of the process +
process.pgrpIntegerThe group ID of the process +
process.utimeIntegerThe time, measured in clock ticks, the process spent in user mode +
process.stimeIntegerThe time, measured in clock ticks, the process spent in kernel mode +
process.niceDoubleThe process nice level (-20 - 19) +
process.starttimeIntegerThe time the process started after system boot +
process.vsizeIntegerThe virtual memory size in bytes +
+ + + CREATE TABLE unix.process ( + process RECORD ( + pid UINT64, + name STRING, + state STRING, + ppid UINT64, + pgrp UINT64, + utime UINT64, + stime UINT64, + nice DOUBLE, + starttime UINT64, + vsize UINT64 + ) + ) + diff --git a/plugins/unix_stats/util/stringutil.cc b/plugins/unix_stats/util/stringutil.cc new file mode 120000 index 0000000..29b84bc --- /dev/null +++ b/plugins/unix_stats/util/stringutil.cc @@ -0,0 +1 @@ +../../../src/evcollect/util/stringutil.cc \ No newline at end of file diff --git a/plugins/unix_stats/util/stringutil.h b/plugins/unix_stats/util/stringutil.h new file mode 120000 index 0000000..11bea2f --- /dev/null +++ b/plugins/unix_stats/util/stringutil.h @@ -0,0 +1 @@ +../../../src/evcollect/util/stringutil.h \ No newline at end of file diff --git a/plugins/unix_stats/util/stringutil_impl.h b/plugins/unix_stats/util/stringutil_impl.h new file mode 120000 index 0000000..fb0d47e --- /dev/null +++ b/plugins/unix_stats/util/stringutil_impl.h @@ -0,0 +1 @@ +../../../src/evcollect/util/stringutil_impl.h \ No newline at end of file diff --git a/plugins/unix_stats/util/time.cc b/plugins/unix_stats/util/time.cc new file mode 120000 index 0000000..b18e128 --- /dev/null +++ b/plugins/unix_stats/util/time.cc @@ -0,0 +1 @@ +../../../src/evcollect/util/time.cc \ No newline at end of file diff --git a/plugins/unix_stats/util/time.h b/plugins/unix_stats/util/time.h new file mode 120000 index 0000000..70ac7c2 --- /dev/null +++ b/plugins/unix_stats/util/time.h @@ -0,0 +1 @@ +../../../src/evcollect/util/time.h \ No newline at end of file diff --git a/plugins/unix_stats/util/time_impl.h b/plugins/unix_stats/util/time_impl.h new file mode 120000 index 0000000..785f206 --- /dev/null +++ b/plugins/unix_stats/util/time_impl.h @@ -0,0 +1 @@ +../../../src/evcollect/util/time_impl.h \ No newline at end of file diff --git a/src/evcollect/config.cc b/src/evcollect/config.cc index 2646516..02c45ff 100644 --- a/src/evcollect/config.cc +++ b/src/evcollect/config.cc @@ -53,6 +53,7 @@ ReturnCode loadConfig( const std::string& config_file_path, ProcessConfig* conf) { conf->load_plugins.push_back("./plugins/hostname/.libs/plugin_hostname.so"); + conf->load_plugins.push_back("./plugins/unix_stats/.libs/plugin_unix_stats.so"); conf->load_plugins.push_back("./plugins/eventql/.libs/plugin_eventql.so"); { @@ -62,10 +63,19 @@ ReturnCode loadConfig( b.event_name = "sys.alive"; b.interval_micros = 1000000; - // XXX: source plugin hostname - b.sources.emplace_back(); - auto& s = b.sources.back(); - s.plugin_name = "hostname"; + { + // XXX: source plugin hostname + b.sources.emplace_back(); + auto& s = b.sources.back(); + s.plugin_name = "hostname"; + } + + { + // XXX: source plugin unix_stats + b.sources.emplace_back(); + auto& s = b.sources.back(); + s.plugin_name = "unix.stats"; + } } { @@ -114,6 +124,15 @@ ReturnCode loadConfig( std::vector { "sys.alive", "test/sys.alive.rollup" })); } + { + conf->event_bindings.emplace_back(); + auto& b = conf->event_bindings.back(); + b.event_name = "sys.unix"; + b.interval_micros = 1000000; + b.sources.emplace_back(); + auto& s = b.sources.back(); + s.plugin_name = "unix.stats"; + } return ReturnCode::success(); } diff --git a/src/evcollect/util/logging.cc b/src/evcollect/util/logging.cc index a5e377a..070d1e3 100644 --- a/src/evcollect/util/logging.cc +++ b/src/evcollect/util/logging.cc @@ -26,6 +26,7 @@ #include #include #include +#include #ifdef HAVE_SYSLOG_H #include #endif diff --git a/src/evcollect/util/time.cc b/src/evcollect/util/time.cc index c2e54fd..109eee2 100644 --- a/src/evcollect/util/time.cc +++ b/src/evcollect/util/time.cc @@ -78,7 +78,7 @@ uint64_t MonotonicClock::now() { #else timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { - logFatal("clock_gettime(CLOCK_MONOTONIC) failed"); + //logFatal("clock_gettime(CLOCK_MONOTONIC) failed"); abort(); } else { return std::uint64_t(ts.tv_sec) * 1000000 + ts.tv_nsec / 1000;