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.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
+ },
};