Coder Social home page Coder Social logo

sysmonitor's Introduction

Sysmonitor

An APP which can monitor the system and inquire hardware information.

System monitor

(1) RAM usage

public static float getUsedPercentValue(Context context) {
	String dir = "/proc/meminfo";
	try {
		FileReader fr = new FileReader(dir);
		BufferedReader br = new BufferedReader(fr, 2048);
		String memoryLine = br.readLine();
		String subMemoryLine = memoryLine.substring(memoryLine.indexOf("MemTotal:"));
		br.close();
		long totalMemorySize = Integer.parseInt(subMemoryLine.replaceAll("\\D+", ""));
		long availableSize = getAvailableMemory(context) / 1024;
		float percent = (float) ((totalMemorySize - availableSize) / (float) totalMemorySize);
		return percent;
	} catch (IOException e) {
		e.printStackTrace();
	}
	return 0;
}

(2) ROM usage

stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
totalBlocks = stat.getBlockCount();
availableBlocks = stat.getAvailableBlocks();
degree4 = (int) ((totalBlocks - availableBlocks) * 100 / totalBlocks);

(3) Battery level

private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
		batteryLevel=intent.getIntExtra(BatteryManager.EXTRA_LEVEL,0);
            	batteryScale=intent.getIntExtra(BatteryManager.EXTRA_SCALE,100);
            	degree3 = (float) (2.7 * (batteryLevel * 100 / batteryScale));
		RotateAnimation animation3 = new RotateAnimation(degree3, 
				degree3, Animation.RELATIVE_TO_SELF, 0.5f,
				Animation.RELATIVE_TO_SELF, 0.5f);
		animation3.setDuration(1000);
		animation3.setFillAfter(true);
		needleView3.startAnimation(animation3);
        }
};

(4) CPU usage

public void readUsage( ){
	try{
		BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream( "/proc/stat" ) ), 1000 );
		String load = reader.readLine();
		reader.close();     
		String[] toks = load.split(" ");
		long currTotal = Long.parseLong(toks[2]) + Long.parseLong(toks[3]) + Long.parseLong(toks[4]);
		long currIdle = Long.parseLong(toks[5]);
		this.usage =(currTotal - total) * 100.0f / (currTotal - total + currIdle - idle);
		this.total = currTotal;
		this.idle = currIdle;
	}
	catch( IOException ex ){
		ex.printStackTrace();           
	}  
}

Hardware information

Please read my blog.

sysmonitor's People

Contributors

hirojisawatari avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.