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 ...
随机推荐
- Android Studio更改项目SDK的版本
Elipse 中的安卓项目,在Android Studio中可以通过File -->new -- > Import Project的方法建立起来.但是有时候需要用到更改项目的API Lev ...
- DF标志和串移动指令(movsb/movsw)
1.标志寄存器的第10位DF,方向标志位.在串处理指令中,控制每次操作后si,di的增减 DF=0,每次操作后,si.di添加 DF=1,每次操作后,si.di减小 我们能够用汇编语法描写叙述movs ...
- 关于nios 中printf 的问题
在nios中,有printf的程序,在线调试没有什么问题,但是下到flash里面,程序跑了一段时间就死掉了!JTAG_UART是阻塞式输出,他只是将数据输出到buffer中,等待你上位机读取,当你的b ...
- JNI 实战全面解析
项目决定移植一款C++开源项目到Android平台,开始对JNI深入研究. JNI是什么? JNI(JavaNative Interface)意为Java本地调用,它允许Java代码和其他语言写的代码 ...
- 定时器函数SetTimer
原文链接:http://www.cnblogs.com/zhangpengshou/archive/2009/04/05/1429770.html 一.SetTimer表示的是定义个定时器.根据定义指 ...
- 我的头上碧空晴朗——数据库存datetime问题
今天遇到一个问题,数据库mysql存的datetime类型数据.取出来数据居然耍流氓,好好的日期在秒后多了个小数点0 当我用正常的方法, SimpleDateFormat myFmt=new Simp ...
- 如何更新 CentOS 镜像源
话不多说, 直接上教程. 首先备份/etc/yum.repos.d/CentOS-Base.repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.rep ...
- 【转】Flash AS3.0 中的自定义事件
原文 http://www.cnblogs.com/acpp/archive/2010/10/19/1855670.html package { import flash.events.Event; ...
- HDU——T 1166 敌兵布阵
http://acm.hdu.edu.cn/showproblem.php?pid=1166 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- C++虚表的原理,很好
下面这篇文章讲的很好. http://www.cnblogs.com/lihaosky/articles/1606502.html 假设我们有这样的一个类: class Base { public: ...