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的更多相关文章

  1. nginx performance monitor

    nginx performance monitor Nginx中的stub_status模块主要用于查看Nginx的一些状态信息 示例 Active connections: 2 server acc ...

  2. JavaFx 中常见的包和类(javafx笔记 )

    JavaFx 中常见的包和类(javafx笔记 ) 更多详细内容请参考<Pro JavaFX 8>. javafx.stage 包包含以下类: Stage 类 ​ Stage 类是任何 J ...

  3. JavaFx 监听剪切板实现(Kotlin)

    原文地址: JavaFx 监听剪切板实现(Kotlin) | Stars-One的杂货小窝 软件有个需求,想要实现监听剪切板的内容,若内容符合预期,则进行相关的操作,就可以免去用户手动粘贴的操作,提供 ...

  4. C#各种同步方法 lock, Monitor,Mutex, Semaphore, Interlocked, ReaderWriterLock,AutoResetEvent, ManualResetEvent

    看下组织结构: System.Object System.MarshalByRefObject System.Threading.WaitHandle System.Threading.Mutex S ...

  5. API Monitor简介(API监控工具)

    API Monitor是一个免费软件,可以让你监视和控制应用程序和服务,取得了API调用. 它是一个强大的工具,看到的应用程序和服务是如何工作的,或跟踪,你在自己的应用程序的问题. 64位支持 API ...

  6. 创建 Monitor 并测试 - 每天5分钟玩转 OpenStack(124)

    前面我们创建了 Pool,VIP 并添加了 Member.今天将创建 Monitor,然后测试 LBaaS 是否能够正常工作. 创建 Monitor LBaaS 可以创建 monitor,用于监控 P ...

  7. MPAndroidChart 3.0——LineChart(折线图)

    显示效果 MPAndroidChart每一种图表的基本使用方式都基本相同 了解一种图表的实现 参考项目源码其他的图表也就差不多哩 在布局文件中定义 <com.github.mikephil.ch ...

  8. 11g新特性:Health Monitor Checks

    一.什么是Health Monitor ChecksHealth Monitor Checks能够发现文件损坏,物理.逻辑块损坏,undo.redo损坏,数据字典损坏等等.Health Monitor ...

  9. 问题记录:JavaFx 鼠标滑轮滚动事件监听!

    问题描述: 在listview的item里面添加鼠标拖拽排序功能.代码如下: setOnMouseDragged(event -> { //设定鼠标长按0.3秒后才可拖拽 防止误操作 isCan ...

随机推荐

  1. 使用Opencv2遇到error C2061: 语法错误: 标识符dest

    在写代码是遇到了这样一个问题,error C2061: 语法错误: 标识符"dest": 1>d:\opencv\opencv\build\include\opencv2\f ...

  2. 设计模式之九:建造者模式(Builder)

    建造者模式: 将一个复杂对象的建造过程和它的表示分离开来,这样同样的建造过程能够创建不同的表示. Separate the construction of a complex object from ...

  3. 使用spring-loaded开源项目,实现java程序和web应用的热部署

    JDK1.5之后提供了java.lang.instrument.Instrumentation,即java agent机制可以实现类的redefinition和retransform. redefin ...

  4. SharePoint创建Alternate Access Mapping (AAM)备用訪问映射

    SharePoint创建Alternate Access Mapping (AAM)备用訪问映射         SharePoint的仓库是SQL Server中的内容数据库.这些数据库储存着组织全 ...

  5. VS中,打开文件时自动定位到目录树中

    工具--选项--项目和解决方案--常规--在解决方案资源管理器中跟踪活动项 这样就能快速跟踪了.

  6. linux关于用户密码家目录总结

    创建用户及其家目录useradd -d /home/tomcat -m tomcat接着修改密码passwd tomcat usermod -s /sbin/nologin + 用户名 禁止登录ssh ...

  7. C#泛型链表Demo

    /// <summary> /// 节点 /// </summary> /// <typeparam name="T"></typepar ...

  8. MVC5发展历程,从MVC2谈起

    目前,MVC已经发布了5个版本,不包括一些临时的版本,为了更好的了解MVC5,知道MVC的发展历程是非常重要的.本篇随笔主要讲解3个版本的内容及其新特性. 1.MVC 2,发布日期:2010年3月 部 ...

  9. tomcat7 bootstrap

    tomcat7 bootstrap http://t5crambing.iteye.com/blog/1923636

  10. cf 865 B. Ordering Pizza

    B. Ordering Pizza It's another Start[c]up finals, and that means there is pizza to order for the ons ...