Pages

Friday, January 1, 2016

JavaScript Human Readable File Size Display

JavaScript Human Readable File Size Display

Currently, I am involved in building an Agentless Monitoring System.
Where the Data are collected by Standalone Components, fed into Database.
A Web Application to load those data's and display graph ( BAR, LINE Charts etc). I am building this system from scratch.

Server Side: JSP & Servlets,

Client Side: JQuery & Java Script

Data Collection: 
  1. BASH Script - snmpwalk.BASH Script gathers SNMP data and convert into JSON.
  2. This Script is invoked from the Server.
  3. The Collected data is fed into Data Parser Engine.

Data Parser:
Parse the data from JSON and feed into the Database.

How I handled the Parameters ?

I am not sure, What ever I have followed is correct or not.

  1. Date - java.lang.Date & stored as long data type ( date.getTime())
  2. Utilization ( DISK , RAM etc )  - in long data type ( bytes )

Every time, a User select a Start time, end time, metric and view the data in
graphs & tables. With respect to date, We shall convert it as
YYYY-MM-DD,HH:MM:SS

 But how to show the metrics in Human readable format ?

I planned to display the files size in human readable format at the Client Side.
While googling, I got an excellent Javascript library.

Just Include the following Javascript in your HTML file

<script type="text/javascript" src="http://cdn.filesizejs.com/filesize.min.js"></script>

Where ever you want to show the file size in human readable format, invoke the method

var ingb=filesize(10000000);

You can see the demo at this link,
http://filesizejs.com/

No comments:

Post a Comment