SQL Server: List active queries

Here is a SQL query that will list the active queries running in the current MS SQL Server instance.

select
    P.spid
,   right(convert(varchar, 
            dateadd(ms, datediff(ms, P.last_batch, getdate()), '1900-01-01'), 
            121), 12) as 'batch_duration'
,   P.program_name
,   P.hostname
,   P.loginame
from master.dbo.sysprocesses P
where P.spid > 50
and      P.status not in ('background', 'sleeping')
and      P.cmd not in ('AWAITING COMMAND'
                    ,'MIRROR HANDLER'
                    ,'LAZY WRITER'
                    ,'CHECKPOINT SLEEP'
                    ,'RA MANAGER')
order by batch_duration desc

JMeter : How to set a Cookie using Beanshell

Here is a Beanshell script that will add a cookie to the cookies sent in every HTTP request.

import org.apache.jmeter.protocol.http.control.Cookie;

// Retrieve the cookie value from a JMeter variable called "myCookieValue"
String cookieValue = vars.get("myCookieValue");

// Create a new Cookie and add it to the cookie manager
Cookie cookie = new Cookie("cookieName", cookieValue , "localhost", "/", false, -1);
ctx.getCurrentSampler().getCookieManager().add(cookie); 

log.info("Cookie added: "+cookie);

NB: Please remind to add a ´HTTP Cookie Manager´ to your thread group.

How to configure Log4j 2 with a properties file

You may want to migrate from Log4j 1.x to Log4j 2, for example because of performance improvements.

But, you don’t want to rewrite all your Log4j 1.x properties file, to use them for Log4j2, you have to slightly change them.

Here is an example of Log4j 2 configuration using properties. It defines two appenders: a console appender and a rolling file appender. (You can find a full working example in my Github repo)

# Declare loggers
name=LoggingConfig
appenders=a_console, a_rolling
rootLogger.level=info
rootLogger.appenderRefs=ar_console,ar_rolling
rootLogger.appenderRef.ar_console.ref=StdoutAppender
rootLogger.appenderRef.ar_rolling.ref=DailyRollingAppender

# Console logger
appender.a_console.type=Console
appender.a_console.name=StdoutAppender
appender.a_console.layout.type=PatternLayout
appender.a_console.layout.pattern=%d{ISO8601} [%t] %-5p (%F\:%L) - %m%n

# File logger
appender.a_rolling.type=RollingFile
appender.a_rolling.name=DailyRollingAppender
appender.a_rolling.layout.pattern=%d{ISO8601} [%t] %-5p (%F\:%L) - %m%n

appender.a_rolling.fileName=log4j2-sample.log
appender.a_rolling.filePattern=log4j2-sample-%d{yyyy-MM-dd}.log

appender.a_rolling.layout.type=PatternLayout
appender.a_rolling.policies.type=Policies
appender.a_rolling.policies.time.type=TimeBasedTriggeringPolicy
appender.a_rolling.policies.time.interval=1

Don’t hesitate to send me a message if you have any issue/question.