Skip to content

Instantly share code, notes, and snippets.

@mrsiano
mrsiano / simple-dag.py
Created August 6, 2020 09:02
simple-dag.py
#!/usr/bin/env python
import logging
import time
import luigi
logger = logging.getLogger(__name__)
while true; do
# capture pidstat
pidstat_in_mem=$(pidstat -l -w -u -h -d -r -p ALL) |grep -v 'Time UID\|Linux'
# the template
#Time,UID,PID,%usr,%system,%guest,%CPU,CPU,minflt/s,majflt/s,VSZ,RSS,%MEM,kB_rd/s,kB_wr/s,kB_ccwr/s,iodelay,cswch/s,nvcswch/s,Command
# index's
time_idx=1
pid=3
@mrsiano
mrsiano / GenData.pm
Last active January 14, 2019 13:29
GenData.pm
#!/usr/bin/perl
# -*- mode: perl; indent-tabs-mode: t; perl-indent-level: 8 -*-
# Author: Andrew Theurer
#
package GenData;
use strict;
use warnings;
use File::Basename;
@mrsiano
mrsiano / pidstat-toolsctip.sh
Last active January 16, 2019 13:36
pbench pidstat-toolscript new gen - the actual pistat script
# index's
time_idx=1
pid=3
cpu_pres=7
mem_pres=13
rss=12
cmd=20
pidstat_in_mem=$(pidstat -l -w -u -h -d -r -p ALL |grep -v 'Time UID\|Linux')
@mrsiano
mrsiano / binsearch.py
Last active December 27, 2018 11:28
binsearch.py
#!/bin/python
# -*- coding: utf-8 -*-
def search_item_with_index_of(arr, target):
"""Scan list of integers (sorted) and retrive the smaller index using python
standart list libary l.index().
Args:
arr (list): list of integers.
target (target): The target int to lookup.
@mrsiano
mrsiano / promethues_on_osa_get_targets.sh
Last active December 5, 2018 12:50
openshift on azure will not expose the infra nodes by default, therefore we can't access the prometheus ui, so we can use the following script to check the prometheus targets health
#!/bin/sh
oc exec -ti prometheus-k8s-0 -c prometheus -- curl -s http://localhost:9090/targets |grep -i '<a id="job'
######## example output #####
# <a id="job-alertmanager-main" href="#job-alertmanager-main">alertmanager-main (3/3 up)</a>
# <a id="job-apiserver" href="#job-apiserver">apiserver (3/3 up)</a>
# <a id="job-cluster-monitoring-operator" href="#job-cluster-monitoring-operator">cluster-monitoring-operator (1/1 up)</a>
# <a id="job-kube-state-metrics" href="#job-kube-state-metrics">kube-state-metrics (2/2 up)</a>
# <a id="job-kubelet" href="#job-kubelet">kubelet (210/210 up)</a>
# <a id="job-node-exporter" href="#job-node-exporter">node-exporter (105/105 up)</a>
package main
// POC for pre-loaded search engine, the following code impl a search component
// based on a Document files i.e (ELK system).
// DataSet object must initialized first (pre-load - in order to map text to document(s)), in
// real life, we will need to sync the Objct and update it when new documents arrives
// currently this is a single thread app.
// the DataSet Object is a singleton instance (thread safe), to support multiple clients.
// Object updates are not thread safe yet!
// time complaxity:
@mrsiano
mrsiano / find_single_int_in_pairs.go
Last active December 20, 2018 01:04
the following function will find a single element in list of pairs, expose binary search and naive linear search
// Interpolation Search in Golang
package main
import (
"fmt"
"math"
)
var (
index int
@mrsiano
mrsiano / promethues_profiling.sh
Last active December 16, 2018 15:25
Profile the promethus app inside a container (openshift-monitoring) using nsenter.
#!/bin/sh
cname=$(docker ps --filter name=k8s_prometheus_prometheus-k8s --format "{{.Names}}")
ppid=$(pgrep -f '/bin/prometheus --web')
mkdir -p ./prometheus_profiler/
# start monitor
while true; do
d=$(date "+%s")
nsenter --target $ppid --mount --uts --ipc --net --pid curl http://localhost:9090/debug/pprof/heap > ./prometheus_profiler/heap_${d}.pprof
for arg in inuse_space inuse_objects alloc_space alloc_objects; do
@mrsiano
mrsiano / origin_prometheus_storage_usage.sh
Created September 2, 2018 16:12
primitive monitor for prometheus storage mount
while true;
do
echo "$(date +'%m-%d-%y-%H:%M:%S') $(oc exec prometheus-k8s-0 -n openshift-monitoring -c prometheus -- df |grep -v tmp |grep '/prometheus')" >> ~/pvc_monitor_0.log
echo "$(date +'%m-%d-%y-%H:%M:%S') $(oc exec prometheus-k8s-1 -n openshift-monitoring -c prometheus -- df |grep -v tmp |grep '/prometheus')" >> ~/pvc_monitor_1.log
sleep 15
done
exit 0