aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVitaly Wool <vitaly.wool@konsulko.com>2019-04-08 12:36:09 +0200
committerVitaly Wool <vitaly.wool@konsulko.com>2019-04-08 12:43:36 +0200
commit76902e81dcdae6c7a936821133d519b875d30950 (patch)
treec9d77d32e9caade07d9a4ddbfb5046b24f93b421
parentf457ab6fcf8bd3df530636bfa795a0c0fd18bdba (diff)
Implement average load request processing
Per request from the front-end, provide system average load values as found in /proc/loadavg. Change-Id: Ia7a63684de16bd0dbadcd2eacedb9b2d56b138d8 Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.com>
-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
+ },
};