diff --git a/README.md b/README.md index 51053d0..f8519df 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ cg_mon ====== Simple application to extend osmon functionality when using cgroups. -Now it only supports reading memory cgroup metrics and can't automatically detect where cgroups mounted. +Now it only supports reading memory and cpuacct cgroup metrics and can't automatically detect where cgroups mounted. Usage example. -------------- @@ -19,10 +19,12 @@ ok 1941913600 6> cg_mem_sup:usage(). 4880506880 +7> cg_cpu_sup:usage(). +8526844361646 ``` To be done: -1. Add support for another cgroups such as cpuacct, blkio and so on. +1. Add support for another cgroups such as blkio. 2. Add event notifications (for example, about excessing some limit of memory usage). 3. Add documentation. diff --git a/src/cg_cpu_sup.erl b/src/cg_cpu_sup.erl new file mode 100644 index 0000000..3a3a29e --- /dev/null +++ b/src/cg_cpu_sup.erl @@ -0,0 +1,33 @@ + +-module(cg_cpu_sup). +-author("Viacheslav V. Kovalev"). + +%% API +-export([ + provided_resource/0, + key_value_sources/0, + single_value_sources/0 +]). + +-export([ + usage/0 +]). + + +-define(PROVIDED_RESOURCE, cpuacct). +-define(KEY_VALUE_SOURCES, []). +-define(SINGLE_VALUE_SOURCES, [ + {usage, "cpuacct.usage"} +]). + +provided_resource() -> + ?PROVIDED_RESOURCE. + +key_value_sources() -> + ?KEY_VALUE_SOURCES. + +single_value_sources() -> + ?SINGLE_VALUE_SOURCES. + +usage() -> + cg_mon_reader:read_meter(?PROVIDED_RESOURCE, usage). diff --git a/src/cg_mon_app.erl b/src/cg_mon_app.erl index 8c1651a..e05a1a9 100644 --- a/src/cg_mon_app.erl +++ b/src/cg_mon_app.erl @@ -130,7 +130,7 @@ cgroup_discovery_file() -> end. handler_modules() -> - [cg_mem_sup]. + [cg_mem_sup, cg_cpu_sup]. %%%===================================================================