summaryrefslogtreecommitdiffstats
path: root/binding/task-manager-binding.c
diff options
context:
space:
mode:
Diffstat (limited to 'binding/task-manager-binding.c')
-rw-r--r--binding/task-manager-binding.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/binding/task-manager-binding.c b/binding/task-manager-binding.c
index c9946c2..2780f84 100644
--- a/binding/task-manager-binding.c
+++ b/binding/task-manager-binding.c
@@ -175,6 +175,32 @@ void get_extra_info(struct afb_req request)
afb_req_success(request, ret_json, NULL);
}
+void get_load_avg(struct afb_req request)
+{
+ struct json_object *ret_json, *json_obj;
+ float value = 1.;
+
+ ret_json = json_object_new_object();
+ json_obj = json_object_new_object();
+
+ FILE *floadAvg = fopen("/proc/loadavg", "r");
+
+ if (floadAvg == NULL) {
+ afb_req_fail(request, "Failed", "Error processing arguments.");
+ }
+ else {
+ fscanf(floadAvg, "%4f%4*f%4*f", &value);
+
+ json_object_object_add(json_obj, "value", json_object_new_double(value));
+ json_object_object_add(json_obj, "str", json_object_new_string("Load"));
+
+ json_object_object_add(ret_json, "msgType", json_object_new_string("loadAvgInfo"));
+ json_object_object_add(ret_json, "loadInfo", json_obj);
+ }
+ fclose(floadAvg);
+
+ afb_req_success(request, ret_json, NULL);
+}
int fill_pstat(proc_t *proc_info, struct pstat *pstat_values)
{
@@ -250,6 +276,13 @@ static const struct afb_verb_v2 _afb_verbs_v2_taskmanager[] = {
.info = "Get exta info about current process",
.session = AFB_SESSION_NONE_V2
},
+ {
+ .verb = "get_load_avg",
+ .callback = get_load_avg,
+ .auth = NULL,
+ .info = "Get exta info about system load average",
+ .session = AFB_SESSION_NONE_V2
+ },
};