Skip to content

Instantly share code, notes, and snippets.

@qsLI
qsLI / Monitors.java
Created September 28, 2022 06:57 — forked from apangin/Monitors.java
Java monitor contention profiler
public class Monitors {
public static native void startProfiling(Object monitor);
public static native void stopProfiling();
public static native long getBlockTime();
public static native long getBlockCount();
static {
System.loadLibrary("monitors");
}

To achieve this you can setup DNS Proxy Mode using the host's resolver with the following command: VBoxManage modifyvm "VM name" --natdnshostresolver1 on

As the result, guest OS DNS requests will be intercepted and resolved using host DNS API, rather than having guest OS connect to external DNS servers as with --netdnsproxy1 on.

You can get the name of the VM by running VBoxManage list runningvms.

@qsLI
qsLI / nc.server
Last active April 28, 2021 03:32
http server
while true ; do echo -e "HTTP/1.1 200 OK\nContent-Length: 1\n\n $(date)" | nc -l -p 7777 ; done
# watch alternative for macos
while :;
do
clear
date
netstat -nat | grep ::1.8080 | sort -k3
sleep 1
@qsLI
qsLI / tcpdump.md
Created September 21, 2020 03:41 — forked from qzaidi/tcpdump.md
capture http headers

HTTP Headers

tcpdump -A -s 10240 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' | egrep --line-buffered "^........(GET |HTTP\/|POST |HEAD )|^[A-Za-z0-9-]+: " | sed -r 's/^........(GET |HTTP\/|POST |HEAD )/\n\1/g'

HTTP Headers and body, on a given interface to a certain dst

tcpdump -i ens4 -A -s 10240 'dst 172.21.43.252 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'

Postgres Queries

sudo tcpdump -i lo -s0 -nl -w- dst port postgres | strings -n8
/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
@qsLI
qsLI / Execution-Cache-Single-Use-Plans-Explore.sql
Created November 21, 2019 06:56 — forked from LitKnd/Execution-Cache-Single-Use-Plans-Explore.sql
TSQL to do a quick and dirty look at single-use plans in the execution plan cache of a SQL Server.
/***********************************************************
TSQL to do a quick and dirty look at single-use plans in
the execution plan cache of a SQL Server.
************************************************************/
/* Size of single use adhoc plans in execution plan cache */
SELECT
objtype,
cacheobjtype,
SUM(size_in_bytes)/1024./1024. as [MB]

Object Query Language (OQL)

$ java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

OQL is SQL-like query language to query Java heap. OQL allows to filter/select information wanted from Java heap. While pre-defined queries such as "show all instances of class X" are already supported by HAT, OQL adds more flexibility. OQL is based on JavaScript expression language.

-- From this article: https://logicalread.com/troubleshoot-high-cpu-sql-server-pd01/#.WW_hjtPytuY
-- Show CPU Utilization by SQL Server, system idle time and other processes
DECLARE @ms_ticks_now BIGINT
SELECT @ms_ticks_now = ms_ticks
FROM sys.dm_os_sys_info;
SELECT TOP 15 record_id
,dateadd(ms, - 1 * (@ms_ticks_now - [timestamp]), GetDate()) AS EventTime
,SQLProcessUtilizationPercent
@qsLI
qsLI / log.bash
Created June 14, 2019 09:35
#bash #log
#!/bin/bash
readonly SCRIPT_NAME=$(basename $0)
log() {
logger -p user.notice -t $SCRIPT_NAME "$@"
}
err() {
logger -p user.error -t $SCRIPT_NAME "$@"
@qsLI
qsLI / README.md
Created May 27, 2019 08:49 — forked from sfgeorge/README.md
Carbon / Graphite tip: How to use whisper-resize to change xFilesFactor on existing stats

Carbon / Graphite tip: How to use whisper-resize to change xFilesFactor on existing stats

Detailed Steps

1.) Update /etc/carbon/storage-aggregation.conf to use the new xFilesFactor setting for new stats, if you haven't yet already

2.) Get the retention ranges as defined in storage-schemas.conf

fgrep retentions /etc/carbon/storage-schemas.conf | tr ',' ' '