Registry level counters in Linux accessible from Java

自作多情 提交于 2019-12-24 14:56:55

问题


I am looking for counters in Linux systems similar to custom counters in Windows, which could be accessed through C#. (http://msdn.microsoft.com/en-us/library/aa326924%28v=vs.71%29.aspx). My use case is this: I have a process that imports a file from location A to B. This file has some XML records that need to be parsed and loaded into a database. I want to have counters which I can keep incrementing, for example, whenever a new file is received at B, and whenever a record is imported into the database. I want to log these counter values at regular intervals to detect any inconsistencies. I used to do this with custom counters (refer to the link above) when I was using Windows+C#, but how can I do this in Linux+Java ? Thanks for any help..


回答1:


Linux doesn't have a registry (thank goodness) I wouldn't suggest you mix application data with your OS. Java has User preferences, but I don't recommended you use it for this type of information.

If you want to record some information, write it to a file, or database e.g. http://java-sources.net/open-source/database-engines A file might be the simplest.




回答2:


The real win with creating a custom counter in a Windows application is that you can monitor your application at runtime using the Windows Performance Monitor. So in your example you could watch how the number of files received over time changes.

The "Java way" (i.e. platform independent) of doing something simillar is JMX.

By all means write the values to a file or database as Peter suggests. That will give you a historic view of the stats. But I strongly recommend you investigate JMX as a way of monitoring your application at runtime analogous to Windows counters.



来源:https://stackoverflow.com/questions/4601453/registry-level-counters-in-linux-accessible-from-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!