Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add memory component

  • Loading branch information...
commit 9af8d25d9f6e305ad89041122776e501828b4086 1 parent a0da7cd
Adam Lindberg authored
View
1  memory/component.config
@@ -0,0 +1 @@
+[{enabled, "true"}, {displayname, "Memory"}].
View
0  memory/memory.css
No changes.
View
30 memory/memory.erl
@@ -0,0 +1,30 @@
+-module(memory).
+
+-export([get_json/0]).
+-export([get_json/1]).
+
+get_json() ->
+ Mem = erlang:memory(),
+ {ok, jsfw_json:encode([[format(Type), format(M)] || {Type, M} <- Mem])}.
+
+get_json(Arg) ->
+ {ok, jsfw_json:encode(Arg)}.
+
+format(Bytes) when is_integer(Bytes) ->
+ {Value, Unit} = human_readable(Bytes),
+ iolist_to_binary(io_lib:format("~s ~s", [Value, Unit]));
+format(Type) when is_atom(Type) ->
+ LC = re:split(atom_to_list(Type), "_", [{return, list}]),
+ UC = [string:to_upper([C]) ++ Rest || [C|Rest] <- LC],
+ string:join(UC, " ").
+
+human_readable(Bytes) when Bytes > 1000000000 ->
+ {format_float(Bytes / 1000000000), "GB"};
+human_readable(Bytes) when Bytes > 1000000 ->
+ {format_float(Bytes / 1000000), "MB"};
+human_readable(Bytes) when Bytes > 1000 ->
+ {format_float(Bytes / 1000), "KB"};
+human_readable(Bytes) when Bytes ->
+ {integer_to_list(Bytes), "B"}.
+
+format_float(Float) -> io_lib:format("~.2f", [Float]).
View
20 memory/memory.js
@@ -0,0 +1,20 @@
+var memory = new function() {
+ var body;
+ var table;
+
+ this.init = function() {
+ body = new Body();
+ table = body.table(["Type", "Memory"]);
+ body.fill_json("/json/memory", table);
+ body.add(table);
+ body.print();
+ }
+
+ this.handle = function(arg) {
+ body.print();
+ }
+
+ this.refresh = function() {
+
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.