JavaFx lineChart real-time Monitor
JavaFx lineChart real-time Monitor about memory
public class EffectTest extends Application { StackPane root;
private static int MAX_DATA_POINTS = ;
private static int Y_DATA_RANGE = ;
private static int TICK_UNIT = ; private static int UPDATE_INTERVAL_MS = ;
private LineChart.Series<Number, Number> series1;
private LineChart<Number, Number> lineChart;
private NumberAxis xAxis = new NumberAxis();
private NumberAxis yAxis = new NumberAxis(); private SequentialTransition animation;
private Paint paintXticklabel;
private double nextX = ; Random rnd = new Random();
double currentMemBAK=;
public EffectTest() { Timeline timeline = new Timeline();
timeline.getKeyFrames().add(new KeyFrame(Duration.millis(UPDATE_INTERVAL_MS*), new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) { // update chart data
// note that we add one data point and remove one data point in this simple example.
// in a production environment you'd have to add multiple and remove multiple data points double currentMem= Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory();
double drawy =(currentMem-currentMemBAK)/;
currentMemBAK=currentMem;
System.out.println("currentMem:"+currentMem);
// add new points
//series1.getData().add(new XYChart.Data<Number, Number>(nextX, Math.cos(Math.toRadians(nextX)) * Y_DATA_RANGE)); //mem
series1.getData().add(new XYChart.Data<Number, Number>(nextX, drawy+)); //cpu
//series1.getData().add(new XYChart.Data<Number, Number>(nextX, getCpuRatioForWindows())); // remove points that shouldn't be visible anymore
if (series1.getData().size() > MAX_DATA_POINTS) {
series1.getData().remove(); }
System.out.println("node size:"+series1.getData().size()); nextX += ; // update using series 1 as reference
// series 2 contains same amount of data; if it doesn't for your case,
// you need to adapt this here and calculate the proper range
List<Data<Number, Number>> data = series1.getData();
xAxis.setLowerBound(data.get().getXValue().doubleValue());
xAxis.setUpperBound(data.get(data.size() - ).getXValue().doubleValue()); ////////
lineChart.getXAxis().setTickLabelFill(paintXticklabel); // xAxis.setTickUnit(1);
root.setTranslateX(-); }
}));
timeline.setCycleCount(Animation.INDEFINITE); animation = new SequentialTransition();
animation.getChildren().addAll(timeline);
} public Parent createContent() { xAxis = new NumberAxis();
xAxis.setForceZeroInRange(false);
xAxis.setAutoRanging(false);
xAxis.setTickLabelsVisible(false);
xAxis.setTickMarkVisible(false);
xAxis.setMinorTickVisible(false);
xAxis=new NumberAxis(, Y_DATA_RANGE+, TICK_UNIT/); // set Axis property
// final NumberAxis yAxis = new NumberAxis(1, 21, 0.1);
// xAxis.setTickUnit(1);
// xAxis.setPrefWidth(35);
// xAxis.setMinorTickCount(10);
// xAxis.setSide(Side.RIGHT);
// xAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(xAxis) {
// @Override
// public String toString(Number object) {
// String label;
// label = String.format("%7.2f", object.floatValue());
// return label;
// }
// }); //yAxis = new NumberAxis(-Y_DATA_RANGE, Y_DATA_RANGE, TICK_UNIT);
yAxis = new NumberAxis(, Y_DATA_RANGE+, TICK_UNIT/);
yAxis.setAutoRanging(false); lineChart = new LineChart<>(xAxis, yAxis);
lineChart.setAnimated(false);
lineChart.setLegendVisible(false); //set if dont want symbols on the point
lineChart.setCreateSymbols(false);
series1 = new LineChart.Series<>();
// series1.getData().add(new LineChart.Data<Number, Number>(0d, 0d));
lineChart.getData().add(series1); //save ticklabe
paintXticklabel=xAxis.getTickLabelFill();
return lineChart;
} public void play() {
animation.play();
} @Override
public void stop() {
animation.pause();
} @Override
public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Drawing Operations Test"); root = new StackPane();
root.getChildren().add(createContent()); Scene s= new Scene(root);
primaryStage.setScene(s);
primaryStage.show(); play();
} public static void main(String[] args) {
launch(args);
// getCpuRatioForWindows() ;
System.out.println(getCpuRatioForWindows()); } private static final int CPUTIME = ;
private static final int PERCENT = ; public static double getCpuRatioForWindows()
{
try
{
String procCmd =
System.getenv("windir")
+ "\\system32\\wbem\\wmic.exe process get Caption,CommandLine,KernelModeTime,ReadOperationCount,ThreadCount,UserModeTime,WriteOperationCount"; long[] c0 = readCpu(Runtime.getRuntime().exec(procCmd));
Thread.sleep(CPUTIME);
long[] c1 = readCpu(Runtime.getRuntime().exec(procCmd));
if (c0 != null && c1 != null)
{
long idletime = c1[] - c0[];
long busytime = c1[] - c0[];
return Double.valueOf(PERCENT * (busytime) * 1.0 / (busytime + idletime)).intValue() ;
}
else
{
return ;
}
}
catch (Exception ex)
{
ex.printStackTrace();
return ;
}
}
private static final int FAULTLENGTH = ;
private static long[] readCpu(final Process proc)
{
long[] retn = new long[];
try
{
proc.getOutputStream().close();
InputStreamReader ir = new InputStreamReader(proc.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String line = input.readLine();
if (line == null || line.length() < FAULTLENGTH)
{
return null;
}
int capidx = line.indexOf("Caption");
int cmdidx = line.indexOf("CommandLine");
int rocidx = line.indexOf("ReadOperationCount");
int umtidx = line.indexOf("UserModeTime");
int kmtidx = line.indexOf("KernelModeTime");
int wocidx = line.indexOf("WriteOperationCount");
long idletime = ;
long kneltime = ;
long usertime = ;
while ((line = input.readLine()) != null)
{
if (line.length() < wocidx)
{
continue;
}
//Caption,CommandLine,KernelModeTime,ReadOperationCount,
// ThreadCount,UserModeTime,WriteOperation
String caption = substring(line, capidx, cmdidx - ).trim();
String cmd = substring(line, cmdidx, kmtidx - ).trim();
if (cmd.indexOf("wmic.exe") >= )
{
continue;
}
String s1 = substring(line, kmtidx, rocidx - ).trim();
String s2 = substring(line, umtidx, wocidx - ).trim();
if (caption.equals("System Idle Process") || caption.equals("System"))
{
if (s1.length() > )
idletime += Long.valueOf(s1).longValue();
if (s2.length() > )
idletime += Long.valueOf(s2).longValue();
continue;
}
if (s1.length() > )
kneltime += Long.valueOf(s1).longValue();
if (s2.length() > )
usertime += Long.valueOf(s2).longValue();
}
retn[] = idletime;
retn[] = kneltime + usertime;
return retn;
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
try
{
proc.getInputStream().close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
return null;
}
private static String substring(String src, int start_idx, int end_idx)
{
byte[] b = src.getBytes();
String tgt = "";
for (int i = start_idx; i <= end_idx; i++)
{
tgt += (char)b[i];
}
return tgt;
}
}
JavaFx lineChart real-time Monitor的更多相关文章
- nginx performance monitor
nginx performance monitor Nginx中的stub_status模块主要用于查看Nginx的一些状态信息 示例 Active connections: 2 server acc ...
- JavaFx 中常见的包和类(javafx笔记 )
JavaFx 中常见的包和类(javafx笔记 ) 更多详细内容请参考<Pro JavaFX 8>. javafx.stage 包包含以下类: Stage 类 Stage 类是任何 J ...
- JavaFx 监听剪切板实现(Kotlin)
原文地址: JavaFx 监听剪切板实现(Kotlin) | Stars-One的杂货小窝 软件有个需求,想要实现监听剪切板的内容,若内容符合预期,则进行相关的操作,就可以免去用户手动粘贴的操作,提供 ...
- C#各种同步方法 lock, Monitor,Mutex, Semaphore, Interlocked, ReaderWriterLock,AutoResetEvent, ManualResetEvent
看下组织结构: System.Object System.MarshalByRefObject System.Threading.WaitHandle System.Threading.Mutex S ...
- API Monitor简介(API监控工具)
API Monitor是一个免费软件,可以让你监视和控制应用程序和服务,取得了API调用. 它是一个强大的工具,看到的应用程序和服务是如何工作的,或跟踪,你在自己的应用程序的问题. 64位支持 API ...
- 创建 Monitor 并测试 - 每天5分钟玩转 OpenStack(124)
前面我们创建了 Pool,VIP 并添加了 Member.今天将创建 Monitor,然后测试 LBaaS 是否能够正常工作. 创建 Monitor LBaaS 可以创建 monitor,用于监控 P ...
- MPAndroidChart 3.0——LineChart(折线图)
显示效果 MPAndroidChart每一种图表的基本使用方式都基本相同 了解一种图表的实现 参考项目源码其他的图表也就差不多哩 在布局文件中定义 <com.github.mikephil.ch ...
- 11g新特性:Health Monitor Checks
一.什么是Health Monitor ChecksHealth Monitor Checks能够发现文件损坏,物理.逻辑块损坏,undo.redo损坏,数据字典损坏等等.Health Monitor ...
- 问题记录:JavaFx 鼠标滑轮滚动事件监听!
问题描述: 在listview的item里面添加鼠标拖拽排序功能.代码如下: setOnMouseDragged(event -> { //设定鼠标长按0.3秒后才可拖拽 防止误操作 isCan ...
随机推荐
- C++模板中重要的术语
- ruby redis的集群管理器
#========================================================================================== # => ...
- berkeley db储存URL队列的简单实现增、删、查
Berkeley DB(BDB)是一个高效的嵌入式数据库编程库,C语言.C++.Java.Perl.Python.Tcl以及其它非常多语言都有其相应的API. Berkeley DB能够保存随意 ...
- CSS3 实现RSS图标
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>CSS3 实现RSS图标&l ...
- IComparable接口实现自定义类型的排序
IComparable接口实现自定义类型的排序 CompareTo(Object) 方法的实现必须返回有三个值之一 如下表中所示. 返回值 参数比较 大于0 x>y 等于0 x=y 小于0 ...
- 123.static静态函数和函数模板
#include <iostream> using namespace std; //static成员,每个类型都会实例化,创建一个变量,类型一致则共享,否则不共享 template &l ...
- BZOJ 3631 链剖+差分
思路: 1.树链剖分+用带标记的线段树维护操作(复杂度O(nlog2n)) 2.树链剖分LCA(TarjanLCA等各种LCA)+差分 复杂度(O(n)->O(nlogn)之间) 下面就说说怎么 ...
- 实时监控Cat之旅~分布式消息树的实现原理与测试
大众点评的老吴在InfoQ上讲了Cat之后,有不少同仁开始关注这个实时监控系统,但学习的文章甚少,在GitHub上也是一言代过,给我们这些开发人员留下了N多个疑问,一时间不知道去哪里问,向谁去问了,通 ...
- easyUI表单验证
1.重写easyui中的 $.extend($.fn.validatebox.defaults.rules, { }) 2.长度重写的方式 1 $.extend($.fn.validatebox.de ...
- 分享一段官date函数用法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...