summaryrefslogtreecommitdiffstats
path: root/binding/task-manager-binding.c
diff options
context:
space:
mode:
authorVitaly Wool <vitaly.wool@konsulko.com>2019-05-13 13:02:48 +0000
committerVitaly Wool <vitaly.wool@konsulko.com>2019-05-17 15:13:47 +0200
commit1126965c7ff0bb24d00a900590dd6214054d57e6 (patch)
tree3e253121c609ce3b8910b82dd1cb12d1d047d636 /binding/task-manager-binding.c
parent8e33f71b6177eb656f49e0b11658ab5c84d7e8de (diff)
Fill in basic network statshalibut_7.99.1halibut/7.99.17.99.1
Per request from the front-end, provide IP statistics as found in /proc/net/netstat. Bug-AGL: SPEC-2403 Change-Id: I98214e0c187546f3c2c4a338d09357582d51b87f Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.com>
Diffstat (limited to 'binding/task-manager-binding.c')
-rw-r--r--binding/task-manager-binding.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/binding/task-manager-binding.c b/binding/task-manager-binding.c
index 5a2bc78..6b4c80c 100644
--- a/binding/task-manager-binding.c
+++ b/binding/task-manager-binding.c
@@ -204,6 +204,53 @@ void get_load_avg(struct afb_req request)
afb_req_success(request, ret_json, NULL);
}
+void get_netstat(struct afb_req request)
+{
+ struct json_object *ret_json, *json_obj;
+ char names_str[1024], values_str[1024];
+ char *pnames = names_str, *pvalues = values_str;
+
+ FILE *fnetstat = fopen("/proc/net/netstat", "r");
+
+ if (fnetstat == NULL) {
+ afb_req_fail(request, "Failed", "Error processing arguments.");
+ return;
+ }
+
+ do {
+ pnames = fgets(pnames, 1024, fnetstat);
+ } while (pnames && !feof(fnetstat) && strncmp(pnames, "IpExt: ", 7));
+ if (feof(fnetstat)) {
+ fclose(fnetstat);
+ afb_req_fail(request, "Failed", "Parse error");
+ return;
+ }
+ pvalues = fgets(pvalues, 1024, fnetstat);
+ fclose(fnetstat);
+ if (pvalues == NULL) {
+ afb_req_fail(request, "Failed", "Parse error");
+ return;
+ }
+
+ ret_json = json_object_new_object();
+ json_obj = json_object_new_object();
+
+ pnames += 7; pvalues += 7;
+ while (pnames && pvalues) {
+ char *name = strsep(&pnames, " ");
+ char *value = strsep(&pvalues, " ");
+
+ if (name && value) {
+ AFB_REQ_INFO(request, "adding %s[%s]\n", name, value);
+ json_object_object_add(json_obj, name, json_object_new_int(atoi(value)));
+ }
+ }
+ json_object_object_add(ret_json, "msgType", json_object_new_string("netStatInfo"));
+ json_object_object_add(ret_json, "netstat", json_obj);
+
+ afb_req_success(request, ret_json, NULL);
+}
+
int fill_pstat(proc_t *proc_info, struct pstat *pstat_values)
{
long unsigned int cpu_time[9];
@@ -285,6 +332,13 @@ static const struct afb_verb_v2 _afb_verbs_v2_taskmanager[] = {
.info = "Get exta info about system load average",
.session = AFB_SESSION_NONE_V2
},
+ {
+ .verb = "get_netstat",
+ .callback = get_netstat,
+ .auth = NULL,
+ .info = "Get network (IP) statistics",
+ .session = AFB_SESSION_NONE_V2
+ },
};