Re: Prometheus on Apache Tomcat multiple tomcat Instances

2023-01-18 Thread Melvin Oosterveen
Hi Peter,

Thank you for your help, I got it to work!

I have added the lines below to the tomcat service file now and it works. A 
separate JMX process is now started for each of the apache tomcat instances I 
start, this could cause some port conflicts though - looks like a new challange.


#Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom 
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10080 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false"

Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"

Environment="CATALINA_PID=/var/tomcat/%i/run/tomcat.pid"

Environment="CATALINA_BASE=/var/tomcat/%i/"

Environment="CATALINA_HOME=/opt/tomcat/10/"

Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC 
-javaagent:/var/tomcat/tomcat10/lib/jmx_prometheus_javaagent-0.17.2.jar=10082:/var/tomcat/tomcat10/prometheus/config.yml"

Another challenge is to get it to configure it to HTTPS and HTTP, but I think 
ill be able to manage that by adding --web.config.file to the configuration.

Kind regards,
Melvin


From: l...@kreuser.name 
Sent: Monday, January 16, 2023 6:05 PM
To: Tomcat Users List 
Subject: Re: Prometheus on Apache Tomcat multiple tomcat Instances

Melvin,


> Am 16.01.2023 um 14:52 schrieb Melvin Oosterveen 
> :
>
>
> Hi all,
>
> I'm currently working on Apache Tomcat stacks within my company and I would 
> like to integrate Prometheus into our deployments. We have decided to go for 
> the Advanced Configuration - Multiple Tomcat Instances on UNIX systems 
> described in the RUNNING.txt.
>
> Does anyone have some experience with the setup of the JMX Prometheus 
> exporter using multiple Tomcat instances? My goal is to have a separate Java 
> process (Prometheus) started when I start an Apache Tomcat instance.
>

in my case the prometheus java agent is tied 1:1 to a tomcat process. In my 
understanding, that would mean 1 prometheus exporter per tomcat (each on a 
different port of course).


> So far I have downloaded the JMX 
> exporter<https://github.com/prometheus/jmx_exporter> and added it to the 
> created Tomcat Instance with a minimal Prometheus configuration.
>

As per the github page jmxagent is the recommended way and not the standalone 
http server (which queries tomcat remotely on the jmx port).
Can you explain which one you are really trying to use?

> ```bash
>
> [root@melvin prometheus]# cat config.yml
>
> hostPort: localhost:

is tomcat listening on this port with jmx? You are trying to query jmx on this 
host on this port (your tomcat process). But did you start the prometheus 
exporter as a separate java process?
java -jar jmx_prometheus_httpserver-0.17.2.jar 12345 config.yaml
prometheus >> exporter:12345 >> tomcat: (jmx)
>
> rules:
>
> - pattern: ".*"
>
> ```
>

> I have created a service file which allows me to start the Apache Tomcat 
> instances separately from each other. Inside this configuration I tried to 
> start the Prometheus Java process, but so far I have failed and the Java 
> process won't expose itself on the configured port.
> ```bash
>
> [root@melvin prometheus]# cat /etc/systemd/system/tomcat-10@.service
>
> [Unit]
>
> Description=Tomcat - instance %i
>
> After=syslog.target network.target
>
>
> [Service]
>
> Type=forking
>
>
> User=tomcat
>
> Group=tomcat
>
>
> WorkingDirectory=/var/tomcat/%i
>
>
> Environment="JAVA_HOME=/etc/alternatives/jre_openjdk"
>
> Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom 
> -Djavaagent:/var/tomcat/tomcat10/lib/jmx_prometheus_javaagent-0.17.2.jar=10080:/var/tomcat/tomcat10/prometheus/config.yml"

At this point you are using the jmxagent - inside the tomcat process. Then you 
MUST leave out the hostPort. Did you try to curl localhost:10080 ?

prometheus >> tomcat:10080 >> internal jmx lookup
If you really want to use the external exporter, you will have to configure jmx 
in JAVA_OPTS instead to run on port . I'm not sure if the following is 
enough or too much:

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port= 
-Dcom.sun.management.jmxremote.rmi.port=10002 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false

> Environment="CATALINA_PID=/var/tomcat/%i/run/tomcat.pid"
>
> Environment="CATALINA_BASE=/var/tomcat/%i/"
>
> Environment="CATALINA_HOME=/opt/tomcat/10/"
>
> Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
>
>
> ExecStart=/opt/tomcat/10/bin/startup.sh
>
> ExecStop=/opt/tomcat/10/bin/

Prometheus on Apache Tomcat multiple tomcat Instances

2023-01-16 Thread Melvin Oosterveen

Hi all,

I'm currently working on Apache Tomcat stacks within my company and I would 
like to integrate Prometheus into our deployments. We have decided to go for 
the Advanced Configuration - Multiple Tomcat Instances on UNIX systems 
described in the RUNNING.txt.

Does anyone have some experience with the setup of the JMX Prometheus exporter 
using multiple Tomcat instances? My goal is to have a separate Java process 
(Prometheus) started when I start an Apache Tomcat instance.

So far I have downloaded the JMX 
exporter<https://github.com/prometheus/jmx_exporter> and added it to the 
created Tomcat Instance with a minimal Prometheus configuration.

```bash

[root@melvin prometheus]# cat config.yml

hostPort: localhost:

rules:

- pattern: ".*"

```

I have created a service file which allows me to start the Apache Tomcat 
instances separately from each other. Inside this configuration I tried to 
start the Prometheus Java process, but so far I have failed and the Java 
process won't expose itself on the configured port.
```bash

[root@melvin prometheus]# cat /etc/systemd/system/tomcat-10@.service

[Unit]

Description=Tomcat - instance %i

After=syslog.target network.target


[Service]

Type=forking


User=tomcat

Group=tomcat


WorkingDirectory=/var/tomcat/%i


Environment="JAVA_HOME=/etc/alternatives/jre_openjdk"

Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom 
-Djavaagent:/var/tomcat/tomcat10/lib/jmx_prometheus_javaagent-0.17.2.jar=10080:/var/tomcat/tomcat10/prometheus/config.yml"

Environment="CATALINA_PID=/var/tomcat/%i/run/tomcat.pid"

Environment="CATALINA_BASE=/var/tomcat/%i/"

Environment="CATALINA_HOME=/opt/tomcat/10/"

Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"


ExecStart=/opt/tomcat/10/bin/startup.sh

ExecStop=/opt/tomcat/10/bin/shutdown.sh


#RestartSec=10

#Restart=always


[Install]

WantedBy=multi-user.target

```

The instance then starts without errors and starts my sample.war application 
which I have downloaded from Apache.org. The initiated Java process is even 
shown.
```bash

tomcat115910   1  0 Jan12 ?00:02:24 
/etc/alternatives/jre_openjdk/bin/java 
-Djava.util.logging.config.file=/var/tomcat/tomcat10//conf/logging.properties 
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 
-Djava.security.egd=file:///dev/urandom 
-Djavaagent:/var/tomcat/tomcat10/lib/jmx_prometheus_javaagent-0.17.2.jar=10080:/var/tomcat/tomcat10/prometheus/config.yml
 -Djdk.tls.ephemeralDHKeySize=2048 
-Djava.protocol.handler.pkgs=org.apache.catalina.webresources 
-Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Xms512M -Xmx1024M 
-server -XX:+UseParallelGC -Dignore.endorsed.dirs= -classpath 
/opt/tomcat/10//bin/bootstrap.jar:/var/tomcat/tomcat10//bin/tomcat-juli.jar 
-Dcatalina.base=/var/tomcat/tomcat10/ -Dcatalina.home=/opt/tomcat/10/ 
-Djava.io.tmpdir=/var/tomcat/tomcat10//temp 
org.apache.catalina.startup.Bootstrap start

```

I wonder if anyone could help me out with the right setup of Prometheus on 
Apache Tomcat multiple tomcat Instances.

Thanks in advance,

Melvin Oosterveen


Re: Context specific context.xml not loading.

2018-12-20 Thread Melvin
ThankYou Mark.

Regards,
Melvin A


On Thu, Dec 20, 2018 at 2:51 PM Mark Thomas  wrote:

> On 20/12/2018 06:44, Melvin wrote:
> > Hello All,
> >
> > Just came across a problem today. Hope someone will clarify it.
> >
> > Tomcat 9.0.13.
> > I wanted to customize ErrorReportValve by setting showReport="false"
> > showServerInfo="false".
> >
> > Below is the META-INF/context.xml -
> > 
> >  > showReport="false" showServerInfo="false" />
> > 
> >
> > It works fine for any internal server error produced or exceptions
> > thrown. But for the case when the browser sends unencoded characters the
> > URL becomes invalid and Exception is thrown and stacktrace is shown in
> > the browser.
> > When I give this valve in server.xml. It works fine. No issues. No
> > stacktrace is shown on the browser when sending unencoded characters.
> > When I give it in my context it fails only for this case.
> >
> > Can anyone please help me on this.
>
> You are configuring the Valve on different elements. In server.xml you
> are configuring it on the Host. In context.xml you are configuring it
> for a single web application.
>
> If the URL is invalid then the request will never be mapped to a web
> application so the ErrorReportVlave on the default Host will be used.
>
> Mark
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>


Re: Context specific context.xml not loading.

2018-12-20 Thread Melvin
Ryan Palmer,

CATALINA_BASE/conf/Catalina/localhost/ directory is empty. Also, I haven't
given any context in server.xml either.

Regards,
Melvin A


On Thu, Dec 20, 2018 at 1:53 PM Ryan Palmer  wrote:

> Melvin,
>
> Do you have any context.xml for this context in the
> CATALINA_BASE/conf/Catalina/localhost/ directory? It may be overriding your
> META-INF/context.xml
>
> -Ryan
> On Dec 19, 2018, at 10:45 PM, Melvin  melvind...@gmail.com>> wrote:
> Hello All,
>
> Just came across a problem today. Hope someone will clarify it.
>
> Tomcat 9.0.13.
> I wanted to customize ErrorReportValve by setting showReport="false"
> showServerInfo="false".
>
> Below is the META-INF/context.xml -
> 
>  showReport="false" showServerInfo="false" />
> 
>
> It works fine for any internal server error produced or exceptions thrown.
> But for the case when the browser sends unencoded characters the URL
> becomes invalid and Exception is thrown and stacktrace is shown in the
> browser.
> When I give this valve in server.xml. It works fine. No issues. No
> stacktrace is shown on the browser when sending unencoded characters. When
> I give it in my context it fails only for this case.
>
> Can anyone please help me on this.
> Thanks in advance for your help.
> Regards,
> Melvin A
>


Context specific context.xml not loading.

2018-12-19 Thread Melvin
Hello All,

Just came across a problem today. Hope someone will clarify it.

Tomcat 9.0.13.
I wanted to customize ErrorReportValve by setting showReport="false"
showServerInfo="false".

Below is the META-INF/context.xml -




It works fine for any internal server error produced or exceptions thrown.
But for the case when the browser sends unencoded characters the URL
becomes invalid and Exception is thrown and stacktrace is shown in the
browser.
When I give this valve in server.xml. It works fine. No issues. No
stacktrace is shown on the browser when sending unencoded characters. When
I give it in my context it fails only for this case.

Can anyone please help me on this.
Thanks in advance for your help.
Regards,
Melvin A

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Re: Tomcat 9 throws exception when sending unencoded charecters in QueryString

2018-12-18 Thread Melvin
Hi Christopher Schultz,

I did not mean that the browser is throwing an error. My problem is that in
9.0.13 tomcat's error page is shown instead of my error page. I have given
error page location in web.xml. error.jsp is located in the root of my
webapp.

I know that if I add '^' in relaxedquerychars there will be no error thrown
by the server. I have no characters in my relaxedquerychars. In 8.5.35 the
requested is rejected and tomcat's error page with exception is not shown,
but it does in 9.0.13.

I will attach both the screenshots of 9.0.13 and 8.5.35. You kindly check
and let me know.

Regards,
Melvin A


On Tue, Dec 18, 2018 at 8:48 PM Christopher Schultz <
ch...@christopherschultz.net> wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA256
>
> Melvin,
>
> On 12/18/18 04:21, Melvin wrote:
> > Tomcat 9.0.13 I switched from tomcat 8.5.35 to 9.0.13. In 8.5 when
> > I send an unencoded character in queryString it throws 400 error in
> > the browser itself and no Exception is thrown or seen explicitly.
>
> That doesn't make any sense. Browsers don't throw HTTP errors.
>
> > After I switched to tomcat 9, when I send an unencoded character
> > in queryString it throws Exception and tomcat error page is shown.
> As it should be.
>
> > I configured error-page in both the servers.
>
> How/where?
>
> > I know that these characters can be relaxed by adding them in
> > relaxedquerychars in server.xml. But still it is a 400 error and
> > ideally it must redirect me to the configured error page.
> Are you saying that configuring relaxedquerychars does not work? If
> so, please post that configuration.
>
> > Also when the response.setStatus(400) is called, error page is not
> > redirected in both the servers.
>
> Where are you configuring your error page. This isn't unambiguous:
>
> > web.xml   400
> > /error.jsp  
> > 500 /error.jsp
> >  
>
>
> > URL=http://localhost:9013/app1/paramTest.jsp?name=^ Tomcat 8.5.32
> > - 'This page isn’t working' is shown in browser. Tomcat 9.0.13 -
> > java.lang.IllegalArgumentException: Invalid character found in the
> > request target. The valid characters are defined in RFC 7230 and
> > RFC 3986
> > org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11Inpu
> tBuffer.java:467)
> >
> >
> org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:29
> 4)
> > org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLigh
> t.java:66)
> >
> >
> org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractPro
> tocol.java:791)
> > org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoi
> nt.java:1417)
> >
> >
> org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.j
> ava:49)
> > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.j
> ava:1149)
> >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.ja
> va:624)
> > org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThr
> ead.java:61)
> >
> >
> java.lang.Thread.run(Thread.java:748) is thrown and tomcat error page is
> > shown. I have attached the screenshot of the exception thrown.
>
> Attachments are stripped, but presumably, it's just a screenshot of
> the above.
>
> Please explain where you have configured that error page, and show
> your relaxedquerychars setting (if you have one).
>
> - -chris
> -BEGIN PGP SIGNATURE-
> Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/
>
> iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAlwZD7oACgkQHPApP6U8
> pFg+1xAAsK6do1HFtdhQG4uNczRo/NgHOvDF0Z4yWolntEEZdDb+dzsqqtUZhRNg
> 5n3q9o3hL2bLBjy+zetuuIVBg7ZxmgcC0QnlhLW+zgOScvGRRSwFi/NOieBgEOe4
> fite15CdaSd9OSv/jVTDqkgL0LEGVnioGgzYaXlzmGWEI/6BpEbBwmLJpqofQ6ij
> EFVbDis2tPc/kwP8JPYll2ihFpPNUacEE+SB/BQyAzOXR1OzAGRYqMFZlfpwfpZ4
> cwCsTwWZeWmKX7PLQjyhE2lCT5a3tioLRAbIyw3P92WJTy4Iwn65EBnf6BcXLF0f
> zuYZYwV1VXut81g8nBcby08si2R+qFHyJ2nIQ2oJWurtf+W4FiQ6Sh4fF7pSN9aI
> FSEknFeFiAYgP/tNDCi40uRVe+HfRczMnYWScR7QmO0U5Ir6/5gM3I6hUOaOYQpl
> s1uL6Tqq7+/7HxSP5PKjxgYg6sJVk8qo7nHuUH/kvJP/gbEQtghJUhQ/xIrZq/e8
> Gg1xTmm4DGZ9xFl9RLHQQqvlbHVQuVfYYVsbfC3pHz2SSevIye+ZAg0CnyXCzFGs
> Ywgsf8VJ/yVbOp80wLd95zsbvmZ/7qK1mtx8aeeLzE8gCrOVr0yYagFsV+AiyQU7
> iGfckuRXbztZ33oJK1fY4Y+QELFuUD3ceAYTy+/L/Exw6NQg8Kc=
> =0by1
> -END PGP SIGNATURE-
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Tomcat 9 throws exception when sending unencoded charecters in QueryString

2018-12-18 Thread Melvin
Tomcat 9.0.13

I switched from tomcat 8.5.35 to 9.0.13. In 8.5 when I send an
unencoded character in queryString it throws 400 error in the browser
itself and no Exception is thrown or seen explicitly.

After I switched to tomcat 9, when I send an unencoded character in
queryString it throws Exception and tomcat error page is shown. I
configured error-page in
both the servers.

I know that these characters can be relaxed by adding them in
relaxedquerychars in server.xml. But still it is a 400 error and
ideally it must redirect me to the configured error page.

Also when the response.setStatus(400) is called, error page is not
redirected in both the servers.

web.xml -


  
400
/error.jsp
  
  
500
/error.jsp
  



URL=http://localhost:9013/app1/paramTest.jsp?name=^
Tomcat 8.5.32 - 'This page isn’t working' is shown in browser.
Tomcat 9.0.13 - java.lang.IllegalArgumentException: Invalid character
found in the request target. The valid characters are defined in RFC
7230 and RFC 3986

org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:467)

org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:294)

org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791)

org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)

org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:748)

is thrown and tomcat error page is shown. I have attached the
screenshot of the exception thrown. Do the needful.

Regards,
Melvin A

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org