Collecting Application Metrics in Java (optionally .Net) - java

I want to be able to expose various time and count based metrics dynamically from my applications. Perf4j works out pretty well for the time ones but does not allow for count in a straightforward way that I'm aware of.
for instance I can do
StopWatch dbWriteTime = new Log4JStopWatch("ServiceName:DBWrite");
dbWriteTime.start();
... execute DB stuff here
dbWriteTime.stop();
and you can set these metrics to get logged at whatever interval and it does a great job of that. But sometimes I want to do something like
Metric metric = new Metric("ServiceName:OrdersPerRequest");
metric.put(50);
I could call the perf4j timer lib 50 times but that is a horrible and inefficient hack to get my metrics in the log. Does anyone know a good open source library that can do both types of metrics? Also if it could monitor the output metric logs and dump them to a centralized DB that would be great. Additionally if you know of a good open source web front end to graph and display this sort of data I'd be very interested in that. It seems this must be something a lot of people have needed before.

I like Coda Hale's metrics library the best but you might also want to look at Java Simon. Other options include stajistics, JAMon, and parfait.

I would suggest taking a look at Coda Hale's presentation, and his metrics library. That should cover you from a Java perspective.

Related

Application Performance Monitoring Tool Spring Boot

Please suggest an Application performance tool for Spring boot, I am using Jamon API right now but I need the logs at very granular level like graph and all instead of AVG, Min, MAX time only. I don't want to deploy it as additional service, I am looking something integrated within Micro service (Via Maven or Jar). Thanks in advance.
<Monitor> monitorName = <MonitorFactory>.start("Function Name");
//Some code here
monitorName.stop();
What I need is EveryDetails for this function name : Every Time Stamp it invoked, how much time this function took at that timestamp.
Sounds like you want to monitor just java methods. If that is the case then Automon should work.
JAMon has lots of modules that monitor web hits, jdbc, garbage collector, and more. Automon doesn't do all that, but can monitor any java code (even 3rd party libraries) with a simple configuration file. Automon doesn't actually do the monitoring, but instead calls any monitoring code that either you provide and out of the box it works with well-known monitoring libraries (i.e. JAMon, JavaSimon, Yammer Metrics, new relic, StatsD, Micrometer). It is also easy to implement your own callback code that would log (using sl4j, log4j etc). In fact, a similar example referenced below does just that with calls to System.out.println. You could even have it both log messages and call jamon.
automon - https://github.com/stevensouza/automon
automon System.out.println implementation - https://github.com/stevensouza/automon/blob/master/automon/src/main/java/org/automon/implementations/SysOut.java
Here is sample output using SysOut, however if you implement it you could add anything else you want.
SysOut.start(..): execution(String com.stevesouza.helloworld.HelloWorld.getLastName())
SysOut.stop(..) ms.: 0
Full disclosure. I wrote both JAMon and Automon.

Make a log file in Java mySQL

I want to make a log in mySQL using Java but I want to do the following:
- Make a record with the CURRENT_TIMESTAMP
- Update the record with an end time (so begin time and end time)
I can't post my code because I get an error when I try...
Thank you in advance,
Remco
You could use log4j and use an appropriate apppender, like detailed in this question
The problem is that JDBCAppender is deprecated. Here is another solution if you really need this functionality : log4j-databaseappender, however it is very sparse on documentation (exactly, almost none), is a bit old, and has only one owner, but might serve as a good starting point if you want to roll your own. At least the code is small.
As for log4j, I'd certainly not try to reinvent the wheel and create another logging framework, when there is a readymade solution for a generic problem. If however you use another framework (which you didn't specify), I'm sure it would make the lives of your fellow colleagues easier not having to cope with different methods of logging... At least I'd be happy to see uniform logging instructions in the code I have to work on...

Set up testing of our questionnaire with jmeter

I've worked with jmeter a little before and have just downloaded jmeter 2.7.
Our web application has a questionnaire that each person fills out. Like most questionnaires, the questions that show up vary depending on answers to previous questions, so there are multiple paths and very rarely does one person see all of the questions.
What I'd like to do is create a control file that will specify a group of questionnaires which it will load and log those people into the system and fill out a questionnaire checking the path and results at the end to make sure the answers were stored properly.
I would like to have 25 simultaneous users of this. Eventually I'd like to have a few hundred.
How do I get starting setting all of this up through jmeter? I don't mean a walkthrough, but I'm a little familiar with a number of the jmeter components. Which components would I use to solve this problem and in what order?
Thanks.
First of all I recommend upgrading to the latest version of jMeter.
To start every test you should add a thread group(right click on the test plan):
Then you would specify number of users/threads to 25 by clicking on your thread group and filling in the number of threads field.
Since you're dealing with web you would add a http request to your thread group (I have many more samplers in my screenshot don't get confused, this is because it's possible to extend jmeter with anything you need really) :
Then after doing some web request you would validate those web requests by using i.e. response assertion :
I could go on for a long time really. Jmeter documentation is somewhat poor in my opinion but it's a great tool.
Without any specific questions this should be enough to get you started.

Good alternative to crontab for java batch programs?

I've been looking for replacements for my companies current batch processing system(java SE + crontab), since there is a lot of java code/shell script duplication, most jobs are ETL and do very similar steps and also i want to provide platform independence instead of relying on crontab, to be more specific with our job role, the current job creation steps are this:
Develop a java program that meets a business requirement.
Test it in a production like enviroment until it meets the business requirement needs.
Pass it to a production server with a shell script that provides file maintenance, java prgram execution and error handling routines(avoid 2 processes of the same name running, mail log to support and developers in case of program error, check output file existence after java program ends if it's relevant for the interface), and specify recurrence data(how often will this program run).
Much of the same logic is being designed and developed into a system that contains generic routines that these programs or "interfaces"(thats how they call it there) do independently(using copy-pasted code usually since most routines are similar), but i am still missing a very important part which i need help with, this concerns the scheduler implementation that i use, and i need it to meet one of these two needs:
-I want to guarantee that whenever i stop the scheduling server for a system update(due to new jobs being added, etc) or whatever other reason, those jobs that could not run due to the system being down(example is 3 jobs that could not run at 3:00 P.M. because the system was down), get to run when the server gets back up, even though their respective scheduling time is gone.
OR in case that the first thing is not possible then:
-I need a way to update the scheduler with new jobs and also update the jars that provide these jobs without restarting the scheduler(sort of like OSGi).
Either of these conditions would satisfy my requirements, and would end my search for the replacement, i've looked into Quartz, Oddjob(theres a scheduler in production with this scheduler, but it needs restarting each time you add new jobs/libraries, does not satisfy my needs) and OSGi using an application server, but i am looking for better suggestions, in case you also know better options, they are also much appreciated.
You might also want to take a look at http://jcrontab.sourceforge.net/
Jcrontab is a scheduler written in Java. The project objective is to provide a fully functional schedules for Java projects.
Alright, found just what i wanted, Quartz does the trick, but i have to develop my own UI Management, FORTUNATELY, there's this project http://code.google.com/p/myschedule/ which contains all that i need(add, remove, resuming jobs), and it is cheap to run the webapp, since you can use tomcat. Now i can focus on designing reusable jobs :), thank god for Quartz!

Use of AspectJ for debugging Enterprise Java applications

The idea is to utilize AOP for designing applications/tools to debug/view execution flow of an application at runtime. To begin with, a simple data(state) dump at the start and end of method invocation will do the necessary data collection.
The target is not application developers but high level business analyst or high level support people for whom a execution flow could prove helpful. The runtime application flow can also be useful in reducing the learning curve of an application for new developers especially in configuration loaded systems.
I wanted to know if there already exists such tools/applications which could be used. Or better, if this makes sense, then is there a better way to achieve this.
You could start with Spring Insight (http://www.springsource.org/insight) and add your own plugins to collect data appropriate for business analysts/support staff. If that doesn't meet needs, you can write your own custom aspects. It is not that hard.
You could write your own aspects, as suggested by ramnivas, but to prepare for the requests from the users, you may want to just have the aspects compiled into the application, so that you don't have to take a hit at run-time, and then they could just select which execution flows or method groups they are interested in, and you just call the server and set some variable to give them the information desired.
Writing the aspects is easy, but to limit recompiling, you may want to get an idea what the users will want, for example, if they want to have a log of every call made from the time a webservice is called until it gets to the database, then you can build that in, but it would be easier to know this up-front.
Otherwise the aspect does nothing, if the variable is not set, and perhaps unset the variable when finished.
You could also have where they can pick which type of logging and for which user, which may lead to more useful information.

Categories

Resources