How to add the hostname to every line of SystemOut.log? - java

We have load balancing and the same name on multiple instances of WebSphere 6.1.
Is there a way to WebSphere need to add the physical hostname to the WebSphere SystemOut.log lines (for example, to prepend to every line)?
Thanks, Bert

I assume you are trying to see how the load is distributed across all the WAS Instances (in a cluster as you had mentioned load balancing)
Is that a web application that you are working with?
If yes the cloneID would give you the answers. Each Server in a cluster is given a unique clone ID.
Look at the Web Server's plugin logs and see which server received the request.
This can be used for a Web Application to see which server serviced the request.
HTH
Manglu

You can implement a custom log formatter and handler and attach them to the root logger. It should capture everything and you should be able to decide the complete logging format and location. The example is for 6.0 but the example should be still valid.
Alternatively you could implement similar log formatter and configure the JVM logs to use custom log format.

Related

How to get Tomcat upload/download speed with JMX

Is there any way to get Tomcat upload and download traffic using Java and JMX?
Tomcat version = ?
If you ask about the count of bytes transferred, then yes. The detailed status page in the Manager web application shows that information and it obtains it via JMX.
You can look into org.apache.catalina.manager package classes StatusManagerServlet and StatusTransformer for the actual source code.
If you ask about transfer rate, if I remember correctly there is no such information. It can also be defined in different ways, as it differs across clients.
You can write your own Filter or Valve or AccessLogValve to perform such calculations and expose via JMX.
You can also analyze an access log file.

Live web log viewer for tomcat catalina.out

With a standard webapp running in Tomcat with the Spring Framwork and Log4J logging to catalina.out I need to have a better access to logs than manual SSH and tail -f catina.out
I already know of some solution like logstash, ... but they require to send the log to a centralized server. I went through a lot of answers of various websites but none satisfies my needs. I just want to have access to the logs in a web browser on the same web server.
Is there any simple and straightforward way to do that ?
Update
I want to to that because I cannot always SSH and tail -f the logs because of the firewall IP security. I need to be able to see these logs from anywhere as long as I have an internet access to such a secure live web console.
Give logsniffer a try. It's a simple standalone Java web application which can run on the same host. log4j log format is supported out of the box, just type in the conversion pattern and the logs will be parsed properly. You can tail, search and monitor the logs in real-time. Last but not least, logsniffer is open source.
Disclaimer: This is my own project.

Logging from 3 different web applications on a tomcat cluster

Our project consists of 3 webapplcations that communicate with each other via web services.
All 3 web apps are running on 3 different web servers that run as a cluster with load balancer. (spring , tomcat, mysql)
Our CTO mentioned that in production, it can be very helpfull to invistigate errors on log on a single unified log file that is consist of all the webapplication log files combined together.
this way it is very easy to see in the log the whole flow across the webapps and not skipping from one log file to another (for each webapp log)
after a quick research we found that combining all the logs into a single file may cause corrupt file error of the log file itself. (we are using slf4j with log4j configuration)
So basically we have 3 questions:
1) Is it a good practice to combine all of the web apps log into one?
2) Whats the best way to achieve that (non corrupted log file will be nice)
3) Is it possible \ relevant to do the same concept of log unification in regard to tomcat logs? (unify all unified logs of all tomcats in the same cluster)
Logging to the same file from multiple servers can get very messy. You inevitably end up with multiple servers attempting to update files simultaneously, which has a habit of causing problems such as weirdly intermingled output and locking.
Given that you're using Log4J, then you should check out JMS queue appenders:
http://logging.apache.org/log4j/2.x/manual/appenders.html#JMSQueueAppender
Using this, every server logs to a JMS queue, and you can set up a listener which logs to file on a separate server.
A reasonable alternative would be to do a little bit of Perl scripting to grab the files and merge them periodically, or on demand.
You will probably find messages which are out of step with each other. That's because each server will be buffering up log output to avoid blocking your application processes.
Logging just the errors to a common place is useful. You can continue to log to each application's log, but you can add remote logging for selected entries (e.g. anything with Level=ERROR).
The easiest way to set this up is to run a SocketServer on one of your machines.
Here's an example that shows how to configure it.

Can i write log to another machine in the network?

I made a web app with a ServletContextListener that in its contextInitialized() just calls two methods from two jars. The jars use log4j to print logs in its execution, what is useful for me on testing. Now, I package this app in an ear file, and deploy into a WAS, that is located into a server to which I don't have access (meaning, I can't access FTP to see paths on the server, etc) to set the path for the logs in the server, and it will take some time to get actual permission to set this.
I thought that maybe I could set log4j to print the logs in my working machine (that is also connected to the network the server is connected)
Is there anyway to do this?
Log4j has many appenders: http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Appender.html
For Log to different machine you can use SocketAppender. But for yours situation better store logs in database with JDBCAppender

Practical usage of the T3 File Service

In the BEA WLS console, it's possible to define "T3 File Service". After googling about it, I was unable any practical info. Is it something useful ?
EDIT:
Deprecated since 6.1 ... a complete overview here , it's sad that no real alternative is provided.
The WebLogic file T3 service lets you provide high-speed, client-side access to native operating system files on the server.
Some people used it (with weblogic 6.1) to upload file attachments to an application in a cluster (in a C/S context I guess). Whether this was actually a good use case is another story.
Anyhow, the File Service has been deprecated in Weblogic 7.0, it just hasn't been removed for now (see the FileT3 in Weblogic 8.1 documentation or File T3 in Weblogic 10.0 documentation). If you need to write to the server file system, you'd better find another solution.
The T3 protocol is (was) a proprietary network protocol for Java object serialization and RMI (before there even was an official RMI). It was used to communicate within a cluster of WebLogic servers (and between servers and clients).
It is deprecated now, so unless you know what you need it for, you probably do not need it.

Categories

Resources