Skip to content

Instantly share code, notes, and snippets.

View brancz's full-sized avatar
❄️
Something something Polar Signals

Frederic Branczyk brancz

❄️
Something something Polar Signals
View GitHub Profile
@brancz
brancz / main_test.go
Created December 11, 2020 09:31
Small tests of pprof merges being associative. Not exhaustive, but running this multiple times showed no failures.
package main
import (
"bytes"
"io/ioutil"
"math/rand"
"reflect"
"testing"
"time"
@brancz
brancz / gist:1ae60ec709ab49a9541bdfbfce50a11f
Created June 25, 2020 14:29
GB available for request on nodes excluding master and infra role nodes.
(kube_node_status_allocatable_memory_bytes * on(node) group_left() (kube_node_role{role="worker"} unless ignoring(role) kube_node_role{role="infra"}) - on(node) sum by(node) (kube_pod_container_resource_requests_memory_bytes * on(node) group_left() (kube_node_role{role="worker"} unless ignoring(role) kube_node_role{role="infra"}))) / 1e9

Keybase proof

I hereby claim:

  • I am brancz on github.
  • I am brancz (https://keybase.io/brancz) on keybase.
  • I have a public key ASDCk1EoKCq2Z_dzuRM8suxa7qivP6oofgEIFo0BMtMR4Ao

To claim this, I am signing this object:

@brancz
brancz / gist:d5c1db85cd09ccf42229f9c2c162ab18
Created February 17, 2020 13:47
Resource saturation by requests per node roles.
(sum by(role) (kube_pod_container_resource_requests_cpu_cores * on(node) group_left(role) kube_node_role)) / (sum by(role) (kube_node_status_allocatable_cpu_cores * on(node) group_left(role) kube_node_role))
@brancz
brancz / prometheus.yml
Last active August 9, 2019 11:53
Example Prometheus config hashing the `job` label before sending it out via remote-write.
scrape_configs:
- job_name: "node"
scrape_interval: "1s"
static_configs:
- targets: ["localhost:9100"]
remote_write:
- url: "http://localhost:1234/receive"
write_relabel_configs:
- source_labels: ["job"]
action: "hashmod"
@brancz
brancz / gist:0cf807bc76857a971ffe92a4beb58e9d
Created December 15, 2018 22:20
access kubelet pods API
kubectl get --insecure-skip-tls-verify --server https://192.168.99.100:10250 --raw /pods
@brancz
brancz / gist:69ae3a9434d8aa8bae0cea94a49b0ffc
Created August 5, 2018 12:14
Kubernetes Ordinal Statefulset members
apiVersion: v1
kind: Service
metadata:
name: ordinal-test
labels:
name: ordinal-test
spec:
clusterIP: None
ports:
- name: http-metrics
@brancz
brancz / configmap-binpack.libsonnet
Created May 24, 2018 09:14
Bin-packing a large object into smaller enumerated objects with max size in jsonnet.
local cm = {
binPack(data, maxSize, nameTemplate)::
self.innerBinPack(data, maxSize, nameTemplate, std.objectFields(data), maxSize, 0),
innerBinPack(data, maxSize, nameTemplate, items, remainingSize, count)::
if std.length(items) == 0 then
{}
else
local curName = items[0];
local cur = { [curName]: data[curName] };
// Size is the sum of the length of the key + length of the content plus
@brancz
brancz / gist:2bd616ef9107021a51c42fb602927fea
Created September 7, 2017 15:10
failed attempt of scraping grafana dashboards off of its api, turns out the output is not compatible with what the create endpoint expects
#!/bin/bash
grafanaapi="http://localhost:8001/api/v1/proxy/namespaces/tectonic-system/services/grafana:3000/api"
dir="./assets/grafana/"
dashboards=`curl $grafanaapi/search | jq -r ".[] .uri"`
while read -r d; do
name=`echo $d | cut -c 3-`
curl "$grafanaapi/dashboards/$d" | jq -r ".dashboard" | jq -r '. + {"__inputs":[{"name": "DS_PROMETHEUS","label": "prometheus","description": "","type": "datasource","pluginId": "prometheus","pluginName": "Prometheus"}]}' > "./assets/grafana/$name-dashboard.json"
@brancz
brancz / gist:4e8603d6e209cc8396866d721c30397e
Created August 11, 2017 09:02
configure glog with standard flag package even without using the flag package otherwise
package main
import (
"flag"
)
func main() {
flag.Parse()
flag.Lookup("logtostderr").Value.Set("true")
flag.Lookup("v").Value.Set("10")