Skip to content

Instantly share code, notes, and snippets.

View niedbalski's full-sized avatar
👋
Be humble. Stay focused.

Jorge Niedbalski niedbalski

👋
Be humble. Stay focused.
View GitHub Profile
@niedbalski
niedbalski / juju-pwhash
Last active June 10, 2020 20:45
juju-passwd
This file has been truncated, but you can view the full file.
@niedbalski
niedbalski / mongodb_collection_sizes.js
Created April 28, 2020 16:46 — forked from freyes/mongodb_collection_sizes.js
List mongodb collections in descending order of size. Helpful for finding largest collections. First number is "size," second is "storageSize."
# for juju on xenial
cat << EOF > /tmp/a.js
db = db.getSiblingDB('juju');
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); }
EOF
/usr/lib/juju/mongo3.2/bin/mongo --sslAllowInvalidCertificates --ssl -u admin -p $(grep oldpassword /var/lib/juju/agents/machine-0/agent.conf | awk -e '{print $2}') localhost:37017/admin /tmp/a.js
LB_ID="6899b9b1-2bb7-4771-999f-6cced80cc321"
LB_DATA=$(neutron lbaas-loadbalancer-show ${LB_ID} --format yaml)
LB_LISTENERS_ID=$(echo -e "$LB_DATA" | awk -F'"' '/listeners/ {print $4}')
LB_POOL_ID=$(echo -e "$LB_DATA" | awk -F'"' '/pools/ {print $4}')
LB_HEALTH_ID=$(neutron lbaas-pool-show ${LB_POOL_ID} | awk '/healthmonitor_id/ {print $4}')
neutron lbaas-listener-delete "${LB_LISTENERS_ID}"
neutron lbaas-healthmonitor-delete "${LB_HEALTH_ID}"
neutron lbaas-pool-delete "${LB_POOL_ID}"
neutron lbaas-loadbalancer-delete "${LB_ID}"
@niedbalski
niedbalski / monitor-mongorestore.sh
Created December 6, 2019 14:25
monitor-mongorestore.sh
#!/bin/bash
dbpass=$(grep statepassword /var/lib/juju/agents/machine-*/agent.conf | cut -d' ' -f2)
while true; do mongo 127.0.0.1:37017/juju -u "machine-0" -p "$dbpass" --sslAllowInvalidCertificates --ssl --authenticationDatabase admin --eval "printjson(db.stats())" | grep -Ei '(datasize|storage|objects)' && sleep 1;done
@niedbalski
niedbalski / sockstats-report.sh
Last active December 3, 2019 17:41
sockstats-report.sh
#!/bin/bash
# gather metrics about sockstat and buffer size.
currdate=$(date +"%m-%d-%Y")
timeout=${1:-600}
every=${2:-1}
basepath=${3:-./sockstat-report-${currdate}/}
function watch_it() {
timeout $1 watch -t -n $2 "cat $3 | tee -a ${basepath}$(basename ${3})_${currdate}.log" &>/dev/null &
@niedbalski
niedbalski / check-sockstats.sh
Created December 3, 2019 17:26
check-sockstats.sh
#!/bin/bash
#
# gather metrics about sockstat and buffer size.
#
timeout=${1:-600}
every=${2:-1}
function watch_it() {
timeout $1 watch -t -n $2 "cat $3 | tee -a $(basename ${3})_$(date +"%m-%d-%Y").log" &>/dev/null &
@niedbalski
niedbalski / search-refs.sh
Created October 16, 2019 18:09
search-refs.sh
for f in $(ldd /usr/sbin/named|cut -d" " -f1 | cut -d "." -f1); do sudo apt-cache search $f | grep dbgsym | grep $f | cut -d " " -f1| xargs apt -yyq install;done
@niedbalski
niedbalski / update-hosts-juju.py
Created August 20, 2019 15:53
update-hosts-juju.py
#!/usr/bin/env python
import subprocess
import yaml
import sys
def juju_status(juju_env=None):
cmd = ['juju', 'status', '--format=yaml']
status_raw = subprocess.check_output(cmd)
return yaml.safe_load(status_raw)
@niedbalski
niedbalski / manual-juju.sh
Last active August 16, 2019 07:58
Setup a ISCSI target multipath with Juju
$ juju bootstrap -e openstack_env
$ juju add-machine
$ nova interface-attach be8c7ed3-9f5c-41f8-b596-0ae7f35c773d
$ nova interface-list be8c7ed3-9f5c-41f8-b596-0ae7f35c773d
+------------+--------------------------------------+--------------------------------------+--------------+-------------------+
| Port State | Port ID | Net ID | IP addresses | MAC Addr |
+------------+--------------------------------------+--------------------------------------+--------------+-------------------+
| ACTIVE | 9c58bd7f-324a-490e-881f-65134ba17915 | 2d5c6949-ae3d-4980-99cf-b17dcb56424a | 10.5.1.30 | fa:16:3e:73:ad:dd |
| ACTIVE | c76d3bf1-9107-4f15-90e2-753c24b219b4 | 2d5c6949-ae3d-4980-99cf-b17dcb56424a | 10.5.1.31 | fa:16:3e:48:a3:4c |
+------------+--------------------------------------+--------------------------------------+--------------+-------------------+
@niedbalski
niedbalski / charmhead.sh
Created June 10, 2019 18:48
charmhead.sh
function charmhead() {
if [ ! ${#@} -ge 2 ]; then
echo "usage ./$0 charm revision" && return;
fi
q=$(curl -s https://api.jujucharms.com/charmstore/v5/$1-$2/archive/repo-info | python -c "import sys, re; q=map(lambda x: re.search('.*commit-short\: (.*)', x), sys.stdin.readlines()); print(q[1].group(1))")
if [ -n "$q" ]; then
echo "$q";
else
echo "Not found revision for charm: $1"
fi