Buscar este blog

sábado, 21 de noviembre de 2020

qperf - Monitoring network bandwidth and latency

 

I will use qperf: https://docs.oracle.com/cd/E86824_01/html/E54763/qperf-1.html

You can check a detailed example here: https://access.redhat.com/solutions/2122681


In destination machine you need to run the following command:

qperf &

You need to open ports 19765 and 19766 in this machine.


In source machine you need to create the following script, in my case, network-monitoring.sh:

#!/bin/sh

echo "$(date +'%Y/%m/%d %H:%M:%S') comprobando red"
HOSTNAME=$(hostname)
DESTINO=[destinationMachine]

ANCHO_BANDA=$(qperf -v -ip 19766  -t 5 --use_bits_per_sec  $DESTINO  tcp_bw | grep bw | awk '{print $3";"$4}' | sed -n '2 p')
LATENCIA=$(qperf -v -ip 19766  -t 5 --use_bits_per_sec  $DESTINO  tcp_lat | grep latency | awk '{print $3";"$4}')


echo "$(date +'%d/%m/%Y');$(date +'%H:%M:%S');$HOSTNAME;$DESTINO;$ANCHO_BANDA;$LATENCIA" >> /root/network-monitoring.csv

 

jueves, 8 de octubre de 2020

Oracle - Count all rows in all tables in a database

 Count all rows in all tables in a database

CREATE GLOBAL TEMPORARY TABLE TMP_TOTALES (
  TABLA VARCHAR2(32),
  TOTAL NUMBER
)
ON COMMIT DELETE ROWS;
         
         

set serveroutput ON;
DECLARE        
          total NUMBER:=NULL;
          cursor tablas_cursor IS select TABLE_NAME from all_Tables where owner = 'myUser' AND NOT table_name like '%$%' ORDER BY TABLE_NAME ASC;
           
          v_sqltxt        varchar2(32767);
          no_privs        exception;
         pragma exception_init(no_privs, -1031);
 BEGIN
     FOR tabla IN tablas_cursor loop
        v_sqltxt:='select count(1) from '|| tabla.TABLE_NAME ||'';      
        BEGIN
          EXECUTE immediate v_sqltxt INTO total;
          INSERT INTO TMP_TOTALES(TABLA, TOTAL) VALUES (tabla.TABLE_NAME, total);
          dbms_output.put_line(tabla.TABLE_NAME || ' ' || total);                  
         END;     
      END loop;        
END;
/


select * from TMP_TOTALES ORDER BY TOTAL DESC;

domingo, 23 de agosto de 2020

Oracle DB - Check tablespaces usage

 Tablespaces and datafiles usage:

select
    DTFIL.tablespace_name, DTFIL.file_name,
    ROUND(DTFIL.bytes/power(1024,2),2) USED_MB,
    DTFIL.autoextensible,
    Round(DTFIL.maxbytes/power(1024,3), 2) Maxsize_GB,
    Round((DTFIL.bytes / DTFIL.maxbytes)*100, 2) USED,
    round((DTFIL.increment_by * TBSP.block_size)/power(1024,2), 2) step_MB,
    DTFIL.increment_by
from
    dba_data_files DTFIL join dba_tablespaces TBSP on DTFIL.TABLESPACE_NAME = TBSP.TABLESPACE_NAME
order by DTFIL.tablespace_name, DTFIL.file_name;

Tablespaces usage, including datafiles:

select
    DTFIL.tablespace_name,
    Round((sum(DTFIL.bytes) / sum(DTFIL.maxbytes))*100, 2) USED
from
    dba_data_files DTFIL join dba_tablespaces TBSP on DTFIL.TABLESPACE_NAME = TBSP.TABLESPACE_NAME
group by DTFIL.tablespace_name
order by 2 desc;


Tablespaces usage acording with actual allocated space:

-- Work tablespaces
SELECT
       a.tablespace_name AS tablespace_name,
       (100 - round((nvl(b.bytes_free, 0) / a.bytes_alloc)* 100)) percent_used,
       (100 - round((nvl(b.bytes_free, 0) / a.bytes_alloc)* 100, 2)) pct_used,
       round(a.bytes_alloc / 1024/ 1024,2) allocated,
       round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024/ 1024,2) used,      
       round(nvl(b.bytes_free, 0) / 1024/ 1024,2) free,
       a.datafiles
from (select
        f.tablespace_name,
        sum(f.bytes) bytes_alloc,
        sum(decode(f.autoextensible, 'yes', f.maxbytes, 'N0',f.bytes)) maxbytes,
        count(1) datafiles
      FROM
        dba_data_files f
      GROUP BY tablespace_name) a,
    (SELECT 
        f.tablespace_name,
        SUM(f.bytes) bytes_free
     FROM
        dba_free_space f
     GROUP BY tablespace_name) b
WHERE
    a.tablespace_name = b.tablespace_name(+)
 
UNION ALL
 
-- TEMP Tablespaces
select
    t.tablespace_name,
    t.percent_used,
    t.pct_used,
    t.allocated,
    t.used,
    t.free,
    f.datafiles
from
    (select
        h.tablespace_name as tablespace_name,
        (100 - round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / sum(h.bytes_used + h.bytes_free))* 100)) percent_used,
        (100 - round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / sum(h.bytes_used + h.bytes_free))* 100,2)) pct_used,
        round(sum(h.bytes_free + h.bytes_used) / 1048576,2) allocated,
        round(sum(nvl(p.bytes_used, 0))/ 1048576,2) used,
        round(sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / 1048576,2) free
    from
        sys.gv_$TEMP_SPACE_HEADER h,
        sys.gv_$Temp_extent_pool p,
        dba_temp_files f
        where
            p.file_id(+) = h.file_id
            and p.tablespace_name(+) = h.tablespace_name
            and f.file_id = h.file_id
            and f.tablespace_name = h.tablespace_name
        group by h.tablespace_name ) t,
    (select tablespace_name, count(1) datafiles from dba_temp_files group by tablespace_name ) f
where
    t.tablespace_name = f.tablespace_name
ORDER BY 3 desc

Oracle DB - SQLPLUS connect

Setup

System properties configuration
export ORACLE_HOME=/usr/lib/oracle/11.2/client64
export TNS_ADMIN=$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export PATH=$PATH:$ORACLE_HOME/bin

Connection

Connect with tnsnames from command line.
sqlplus username/pass@'(description=(address=(protocol=tcp)(host=myServer)(port=1521))(connect_data=(sid=mySID)))'



Connect with tnsnames from file
sqlplus username/pass@ORCL

Where tnsnames.ora file is as follows.
ORCL=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = myServer)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = myService)
    )
  )

Run SQL file

Run SQL from command line
sqlplus username/pass@'(description=(address=(protocol=tcp)(host=myServer)(port=1521))(connect_data=(sid=mySID)))' @myFile.sql

SQL file
set linesize 100 pagesize 50

select
    DTFIL.tablespace_name,
    Round((sum(DTFIL.bytes) / sum(DTFIL.maxbytes))*100, 2) USED
from
    dba_data_files DTFIL join dba_tablespaces TBSP on DTFIL.TABLESPACE_NAME = TBSP.TABLESPACE_NAME
group by DTFIL.tablespace_name
order by 2 desc;

exit;

martes, 14 de abril de 2020

CentOS check system info

Show system inf for a CentOS server:
# CPU info
 more /proc/cpuinfo

# Memory info
 dmidecode -t memory
 dmidecode -t memory | grep -i "installed size"

# Operatin System
 cat /etc/os-release
 hostnamectl
 uname -r

viernes, 10 de abril de 2020

Axis 1 - SLF4J Logging

In this post I´ll show you how to configure Axis 1 Logging with SLF4J-Log4j. The main purpose is to trace incoming and outcoming messages.

Axis uses Apache commons-logging as logging implementation. This dependecy is configured as runtime in Axis pom, so it will not be imported as transitive.
Any way, if you have commons-logging library in your project, exclude it.

As you exclude commons-logging, you need to add the corresponding slf4j bridge, i.e., jcl-over-slf4j library.

Add a file called common-logging.properties in src/main/resoruces with the following content:
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.SLF4JLogFactory

When you configure log4j logging, for example in log4j.xml file,  add the following categories:
<logger name="org.apache.axis.providers" additivity="false">
 <level value="debug"/>
 <appender-ref ref="FILE"/>
</logger>

<logger name="org.apache.axis.transport.http" additivity="false">
 <level value="debug"/>
 <appender-ref ref="FILE"/>
</logger>

org.apache.axis.providers is used by web service providers in order to trace incoming messages and outcoming responses.

org.apache.axis.transport.http is used by web service clientes in order to trace outcoming messages and incoming responses.

sábado, 28 de marzo de 2020

CentOS 6 - Port forwarding

I have the following scenario:
  1. My computer
  2. CentOS 6.5 intermediate server IP_CENTOS
  3. Third party service: https://IP_SERVICE/domain/service-path 
From my computer I can reach the CentOS server, but not the third party service.
From CentOS server you can reach the third party service.

I want to use CentOS server as a bridge in order to forward traffic from my computer to the third party service and vice versa.

Set configuration

Step 1

Enable ip forward in iptables:
 
    echo 1 >/proc/sys/net/ipv4/ip_forward

Step 2

Configure forwarding:
    iptables -t nat -A PREROUTING -p tcp --dport 9443 -j DNAT --to-destination [IP_SERVICE]:443
    iptables -t nat -A POSTROUTING -p tcp -d [IP_SERVICE] --dport 443 -j SNAT --to-source [IP_CENTOS]


Here you have:
  • 9443 is the fake port used in CentOS server.
  • IP_SERVICE is the IP address of the third party service
  • 443 is the default HTTPS port, as the third party service is in https://xxxxxx
  • IP_CENTOS is the IP address of the CentOS server

Step 3

Save the rules:
    service iptables save
    service iptables reload

You can check the configuration as follow:
    iptables -t nat --line-numbers -L

    more /etc/sysconfig/iptables

Test

From My Computer you can check to access to https://IP_CENTOS:9443/domain/service-path 

Rollback configuration

In order to restore configuration and delete all previous work, do as follows:
    echo 0 >/proc/sys/net/ipv4/ip_forward

Check the rules and delete them one by one:
    iptables -t nat --line-numbers -L

    iptables -t nat -D PREROUTING|POSTROUTING [num]

jueves, 19 de marzo de 2020

Apache Camel - Proxy route

In this example I will configure a Camel route proxy. Camel will publish a http servlet and redirect all request to a external provider.

Configuration

You need to configure as follow:
  • Configure dependencies
  • Configure Camel servlet
  • Configure Camel route

Configure dependencies

In pom.xml:
<dependency>
 <groupId>org.apache.camel</groupId>
 <artifactId>camel-servlet</artifactId>
 <version>${camel.version}</version> 
</dependency>

<dependency>
 <groupId>org.apache.camel</groupId>
 <artifactId>camel-http4</artifactId>
 <version>${camel.version}</version> 
</dependency>

Configure Camel servlet

In web.xml:
<servlet>
 <servlet-name>CamelServlet</servlet-name>
 <display-name>Camel Http Transport Servlet</display-name>
 <servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
</servlet>

<servlet-mapping>
 <servlet-name>CamelServlet</servlet-name>
 <url-pattern>/services/*</url-pattern>
</servlet-mapping>


Or, alternatively, in java:
import javax.servlet.annotation.WebServlet;

@WebServlet(name = "CamelServlet", urlPatterns = { "/services/*" }, loadOnStartup = 1)
public class CamelRestServlet extends org.apache.camel.component.servlet.CamelHttpTransportServlet { 
 private static final long serialVersionUID = 2886685336873526067L;
 //Servlet secuestrado por Camel para procesar las peticiones de entrada a su ruta proxy
}

Configure Camel route

In camel-context.xml:
<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
 <route>
  <from uri="servlet:/service1?matchOnUriPrefix=true"/>
  <log message="Redirecting to service1"/>
  <to uri="http4://otherDomain:8080/otherApp/service1?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>
 </route>
 
 
 <route>
  <from uri="servlet:/service2?matchOnUriPrefix=true"/>
  <log message="Redirecting to service2"/>
  <to uri="http4://otherDomain:8080/otherApp/service2?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>
 </route>
</camelContext>

Testing

In your app is published in http://localhost:8080/myApp, then you will get the following behaviour:

When calling http://localhost:8080/myApp/services/service1/test?a=b Camel will redirect to http://otherDomain:8080/otherApp/service1/test?a=b

viernes, 13 de marzo de 2020

Tomcat -JConsole - Remote connection

This is the procedure to connect JConsole to a remote tomcat server.

[Remote] Configure tomcat

Edit/create a file $TOMCAT_HOME/bin/setenv.sh.

Add de following JAVA_OPTS params:

  • -Dcom.sun.management.jmxremote
  • -Dcom.sun.management.jmxremote.port=9999
  • -Dcom.sun.management.jmxremote.rmi.port=9998
  • -Dcom.sun.management.jmxremote.authenticate=false
  • -Dcom.sun.management.jmxremote.ssl=false
You can add them as follow:
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.rmi.port=9998 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
Restart tomcat.

[Remote] Configure host

You need to open these ports in order to allow remote connections from other machines. You can do that by using "firewall-cmd":
   firewall-cmd --zone=public --add-port=9999/tcp
   firewall-cmd --zone=public --add-port=9998/tcp
   firewall-cmd --zone=public --permanent --list-ports
   firewall-cmd --zone=public --list-ports

[Local] Configure JConsole

From local host launch JConsole targeting 9999 (in my case, the target server is in PRE-C01-SRV01)






If you have problems you can enable JConsole log by creating a logging config file, for example, jconsole-logging.properties:
Logging.properties

handlers = java.util.logging.ConsoleHandler


.level = INFO

java.util.logging.ConsoleHandler.level = FINEST

java.util.logging.ConsoleHandler.formatter = \

java.util.logging.SimpleFormatter

// Use FINER or FINEST for javax.management.remote.level - FINEST is

// very verbose...

javax.management.level = FINEST

javax.management.remote.level = FINEST

Launch JConsole from command line with the following params:
    jconsole -J-Djava.util.logging.config.file=jconsole-logging.properties

jueves, 12 de marzo de 2020

Camel - CXF - Remove SOAP Headers

import java.util.List;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.cxf.binding.soap.SoapHeader;
import org.apache.cxf.headers.Header;

public class ReaProcessor implements Processor {  
 
 @Override
 public void process(Exchange exchange) throws Exception {
  @SuppressWarnings("unchecked")
  final List<SoapHeader> soapHeaders = (List<SoapHeader>) exchange.getIn().getHeader(Header.HEADER_LIST);
  soapHeaders.clear();   
 }

}
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://camel.apache.org/schema/cxf"
 xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:http="http://cxf.apache.org/transports/http/configuration"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
              http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
              http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
              http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd
              http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd">

 <bean id="reaProcessor" class="xxxxxxxxxxx.ReaProcessor"></bean>
 
 <!-- CAMEL CONTEXT -->
 <camelContext id="camelContextRea" xmlns="http://camel.apache.org/schema/spring">
  <!-- CAMEL ROUTE -->
  <route id="ReaWSRoute">
   <description>
    Ruta camel para Rea
   </description>
   
   <from uri="cxf:bean:servicioReaProvider?loggingFeatureEnabled=true&amp;dataFormat=POJO" />
   
   <to uri="cxf:bean:servicioReaClient?loggingFeatureEnabled=true&amp;dataFormat=POJO" />
   
   <process ref="reaProcessor"></process>
  </route>
 </camelContext>

</beans>

domingo, 12 de enero de 2020

MavenReportException: Error while generating Javadoc

Error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.1.1:jar (attach-javadocs) on project XXXXXX: MavenReportException: Error while generating Javadoc:
[ERROR] Exit code: 1 - /src/main/java/xxxxxxxxxxxxxxxx/Xxxxxxxxxxxxxx.java:28: warning: no description for @param
[ERROR] * @param clazz
[ERROR] ^

Solution, in pom.xml:
<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-javadoc-plugin</artifactId>
 <version>2.9</version>
 <configuration>
  <additionalparam>-Xdoclint:none</additionalparam>
 </configuration>
</plugin>