Tuesday, November 12, 2019

Shell Script to simulate API requests for Load Tests


You can use below shell script to simulate a pre-defined load on an API.

       
#!/bin/bash

#########################################################
# This is simple shell script to simulate API load      #
# for given duration                                    #
# Eg: DURATION=60 and TPS=20, This script will trigger  #
# 20 requests per second for 1 minute.                  #
#########################################################


#define variables

set -x # run in debug mode
DURATION=60 # how long should load be applied ? - in seconds
TPS=20 # number of requests per second
end=$((SECONDS+$DURATION))

#start load
while [ $SECONDS -lt $end ];
do
    for ((i=1;i<=$TPS;i++)); do
        curl -X POST  -H 'Accept: application/json' -H 'Authorization: Bearer xxxxxxxxxxxxx' -H 'Content-Type: application/json' -d '{}' --cacert /path/to/cert/cert.crt -o /dev/null -s -w '%{time_starttransfer}\n' >> response-times.log &
    done
    sleep 1
done
wait

#end load
echo "Load test has been completed" 
       
Download the script from here.

Here while loop is to run this load for given time period
for loop is to fire given number of requests per second
cacert is optional - only used for https request, you can use -k option as well
-o /dev/null is to write the output to empty
-s is to silence the process
-w '%{timestarttransfer}%' is to retrieve the response time. This time will be written to a file
this request will run in background and script will initiate next request.

Monday, November 11, 2019

HTTPS connection using CURL command

When you need to try HTTP connection using CURL command you will return below error,

* Issuer certificate is invalid: 
* NSS error -8156
* Closing connection

Here you need to specify the cert in curl command using --cacert. before that you need to get the cert for your server. You can try below command to get cert.

openssl s_client -connect <host>:<port>

Eg: openssl s_client -connect localhost:8243

Now you can see the ssl certificate. You can extract the text between "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" including these two line and save as ssl.crt.

Now you can trigger HTTPS request according to below format

curl -X POST https://localhost:8243/xxxx/v1/test  -d '{}' --cacert /path/to/ssl.crt

Friday, November 8, 2019

How to fix "Could not get lock" Error while apt install


Sometimes we are having below error while trying to install a package using apt install in linux.

sudo apt install default-jre
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

Reason: some other process is using /var/lib/dpkg/lock

Resolution: 

1. Check whether any other apt install process is running or not. If any process is running wait for that process

2. Reboot OS and try again

3. If above [1] and [2] are not working, the worst option will be removing /var/lib/dpkg/lock file.
     sudo rm /var/lib/dpkg/lock

Thursday, October 31, 2019

How to build SOAP mock service using SOAP UI

Here I have described step by step guidelines to create SOAP mock service using SOAP UI

Prerequisites:

  • SOAP UI
  • Simple SOAP WS (we are going to mock this service)
STEP 01:

Right click on your SOAP project interface and go to "Generate SOAP Mock Service"


STEP 02:
 Here you can design your mock service. eg: path, port, operation, etc And then click OK.


 STEP 03:

Your MOCK service has been created. Now you can define the response as below.


 STEP 04:

 Once updated, you can start the MOCK service.


 STEP 05:

 Now your MOCK service is running on given port


 STEP 06:

 Now you can trigger MOCK service using SOAP UI and see the configured response.


 STEP 07:

 You can see the log in start window as well.




Friday, September 6, 2019

Find if a SSL certificate is self signed or CA signed

Try below command for .pem certificate file

       
openssl x509 -in certificate.pem -inform PEM -noout -subject -issuer
       

If subject and issuer are same : It is self signed certificate
If subject and issuer are different : It is CA signed certificate and issuer will be CA

Tuesday, April 16, 2019

How to remove ssh-agent process in redhat


When you log out, you want the ssh-agent process to be terminated automatically.

You can add below command in .bash_profile file

trap 'test -n "$SSH_AGENT_PID" && eval `/usr/bin/ssh-agent -k`' 0

If you need to remove existing processes,

for(( ; ; )); do kill $(ps -ef | grep ssh-agent | grep -v grep  | grep -v grep | awk -F' ' '{print($2)}' | head -1 );echo "done"; done


Friday, April 5, 2019

Mysql Load Balancing with Nginx (Ubuntu)


Environment setup:

Mysql master server : 192.168.1.10
Mysql slave server : 192.168.1.12

Nginx server : 192.168.1.14

1. Add Nginx configurations

Add below configuration to nginx main configuration file (/etc/nginx/nginx.conf) just after the http block     
stream {
    upstream mysql_cluster {
        server 192.168.1.10:3306; # node1
        server 192.168.1.12:3306 backup; # node2
    }
    server {
        listen 3306; 
        proxy_pass mysql_cluster;
    }
}
2. Open 3306 port in Nginx server

Since we are using 3306 port, we need to use SELinux and open port privileges
Try below command in Nginx server
sudo semanage port -l | grep http_port_t
check port 3306 is there, if not we can add it by using below command
sudo semanage port -a -t http_port_t  -p tcp 3306 
3. Enable firewall

 If you are using CentOS, you may use below command to enable firewall rules in Nginx server

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

File Sharing using NFS in GKE Cluster

 File Sharing using NFS in GKE Cluster There was a requirement to create common file sharing location which should be accessible by specific...