Introducing a Java stats package to an application? - java

I currently have a web application and wish to add certain statistics to the site. These statistics would be in addition to web statistics.
I can easily log certain events to a file via log4j. Is there something I can add that will investigate the data and format it in a human readable way (chart or table)?
The application is running in tomcat.

We log events for our web-shop in our database. Something like this
ID-----USER-----EVENTTYPE-----DATE
Then it's easy to create graphs with Google Chart showing logins, orders created, payments done with visa vs mastercard, files download last 30 days etc..

You might want to try JMX and a console that will let you see values at runtime.

You could create an MBean and view it through jmx console. Or add a class that handles the logging, and format it, and then in Log4J you could output that class only to it's own log file. You could then write a parser on that file, and view it via a webpage if necessary.

Related

Javafx audit logging

I have an assignment in Javafx to take a basic login application and have it produce an audit log that includes the entries the user put in the text boxes and the buttons pressed along with the date and time. I have searched high and low and I cannot find an example that I can make work with my application. Can someone provide me a basic example of how to implement the audit log or point me in the right direction?
For a professional application, many people use java.util.logging, or Apache Log4J. However, since this is an assignment, I assume your instructor wishes you to keep a log using your own File I/O.
I would suggest implementing a method called log(String message) which opens your audit file and appends a line to the end with the current timestamp and given message. Then, everywhere in your application you need to log something, you simply call your own log(message) function.
For more help with File IO, try reading through this tutorial, or searching google for a good one.

How to log application usage to website

I'm looking for a method to see how often people use my application and some small usage stats about that usage, e.g. Time Of Day (derived from the message time), duration of usage (program statistic), etc.
The application is written in Java and already connects to the internet, so I know I can send/request information from websites.
My question, is how best to do this? I know I could use Google Analytics and "ping" a specific web page, but ideally I'd like the extra statistics too, can that be done with GA? How do I separate that traffic out of the other GA stats?
Are there existing code snippets I could utilise?
What do I need the server to do? I have hosting with SSH access, MySQL, etc. So can install packages if needed.
Edited to add
This is not a web application, it's a local program that runs on a client machine and connects to the internet to gather data. So there's no web pages that I can insert java code or other scripts into for true web analytics.
This is why I was thinking that I would have to "ping" or "poke" (No idea what the correct terms are) a specific web address, perhaps a PHP page that would record the statistics.
The statistics that I would like to gather are:
IP Address (ONLY to determine the unique visitor and perhaps country of origin)
Time of execution (from the time the statistic was generated)
Number of items processed (program statistic)
Execution duration (program generated statistic)
As the program is usually run by the user an average of once per day, I don't anticipate massive load on the server (famous last words!)
Edited for clarification
The application is a CLI based (no GUI or web browser, web server, or other web application technologies are used). The application runs locally on a user's machine, collects information on various files, downloads information on those files from the internet (yes, using a URL connection), and compiles that information into a database.
I have no view of or access to, the users of the application. I do have a website that I use Google Analytics to see who visits and where from, all the usually stats.
I want to be able to capture a small bunch of stats (explained above) each time the application is run so I know that the application is being used and by how many users and what for.
I had thought I might be able to call a PHP web page with some arguments that could then be added to a database, e.g. http://omertron.com/stats?IP=192.168.2.0|processed=23|duration=270
Or can Google Analytics be used to log that information some how? I can't find much in the documentation about how I would do that.
Check out this list of web analytics software. Lots of free packages there, and once you find one that suits your needs, you'll be able to frame your question specifically to the challenges in using that particular package.
Your options are:
Tagging Systems (like Google Analytics)
Access Log File Analysis
With tagging you create an account with Google Analytics and add some specific JavaScript code you will get from Google, into the relevant places of your code, this allows the browser of your visitors to connect to GA and get captured there.
The Access log file can hold all information about all sessions. There is a lot of detail data generated, so data has to be Extracted, Transformed and Loaded (ETL) to a database. The evaluation can be then performed in nearly real-time. You can create some dashboard application that does the ETL and displays the status of you application.
A third option would be to combine tagging and log file analysis. This will give you more precise results.
Interesting, my thoughts are you would need a framework to accomplish this.
The java application should be able to asynchronously log every event that is happening in the application.
In google analytics you can define names and push events for those specific names. If you would be able to use the following api, I dont think you need to ping a specific web page to use google analytics.
http://download.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html
I have not used this api, hope this helps!

There is an interface/GUI appender for log4j?

I want to show my logs in the GUI in a textfield, list, etc. (something like ImgBurn), but I not found a ready appender that do this. There are an appender to do this?
Currently I doing log to the console without any problems.
Take a look at Apache Chainsaw: this can use the Receiver concept from the recent Log4j builds to display events: http://logging.apache.org/chainsaw/index.html.
If you are looking to do real-time text field display you may need to write your own Receiver class.
There are some good tools available for Free (paid as well) that can parse your log files and present them in better formats with lots of filtering and reporting options as well.
Here is a good list of such tools
Are you looking for a real time log viewer?
I can recommend you OtrosLogViewr. It can tail logs from running applications even on remote servers (using SFTP, FTP, Samba)
Check out the latest developer snapshot of Chainsaw - tons of new features, and when configured to process log files via VFSLogFilePatternReceiver, can tail log files, even between app restarts.
There are a ton of new features in this version compared with the currently-released one - some of the more helpful include search results that are highlighted and aggregated in a table, and the ability to annotate events (click in the 'marker' field)
http://people.apache.org/~sdeboy
Try Glasswall, which appends the log contents on the page if you are running a servlet.
http://code.google.com/p/glasswall/

How to build a simple application which can capture user input and produce a printable output

We need to build the following application:-
User punches in couple of inputs into a form (e.g. customer name, insurance policy information, bank details and the insurance amount). The application is supposed to take a print copy with 3 perforations which contains the above information (one for the customer, insurance agent and the insurance firm)
The end users in this case (insurance agents) are not tech savvy and would like to have an application with the smallest footprint which can be launched from a CD. Also do note that they might not have an internet connection.
We are looking for ideas on frameworks we should use to build this application. Note: We are proficient in java only. Does this application need to be a web application or a simple html with some pdf generation capability. Looking for suggestions here?
If all you need is to enter the information and print the PDF, you can just create a PDF form with editable fields using OpenOffice, no need to code an application for that.
However if you need to save the data, you then can use PDFBox to parse the filled form and put its data into a database later.
Despite the 'web' part of Java Web Start, it might suffice to supply an applet (yes, I did mean applet not application) on the CD that is launched using JWS.
As of Java 1.6.0_10+, applets can be dragged from the web page (on the CD) where they reside. If a dragged applet is configured by JNLP (installed using JWS), it will then install itself into the user's system.
Further, JNLP offers a way for even sand-boxed apps. to use the printer. See my demo. of the JNLP PrintService for more details on that.

HOW-TO: remote file access from a web server?

We have a web application which which is deployed and used within an intranet. The application reads in text files from a specified location on the web server itself.
Now we have a requirement of reading in text files from other machines as well, so i'm exploring possible options to implement this. Possible options i've been thinking of are:
Maybe start a ftp server on each local machine and then write a servlet to ftp given machines n read-in data.
Maybe run some utility program thats would read in file contents and push it back to the server using xml etc ?)
Ne help about above/or new ideas would be highly appreciated!
Technologies i'm using are :
Tomcat/Struts/JSP/AJAX.
P.S i want to handle non NFS situations as well!
Thanks,
Abhishek.
apart from the fact that I don't know whats the purpose of the application you're building, and knowing it is a Web-app, why not have users upload the specific files you want to process?, or even better, if they are configuration files, you might put them all in one single location, let's say just one machine. That might be better than having your app stuck just because some machine is not accessible.
I have an idea for you.... You may expose web service on each machine where from you want to get logs.These web services will read log files and send to your web application in bytes. You web application will call these service periodically and will take latest data. your entire system would work like a distributed system. you need to ensure that log file should generate with the name in uniform format - for eg.. log-24-12-2010.log or log24122010.log (if your log file generates on daily basis) - so that web services can form the right name of log and access it.
I recommand you to use RESTful web services because they are pretty easy for such purposes. Use JAX-RS APIs to develop such services.
I hope you would get my idea a little bit.
~~ Priyanjan

Categories

Resources