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 / gist:968a79a602288a04e19918031b0b80dc
Last active August 5, 2020 03:47
jq convert Prometheus /api/v1/targets to file discovery json
curl localhost:9090/api/v1/targets | jq '.data.activeTargets[] | . + {"targets": [.labels.instance]} | del(.scrapeUrl, .lastError, .lastScrape, .health, .discoveredLabels)' | jq --slurp '.'
@brancz
brancz / gist:b2fc399257ca650952fe2522c657b70f
Created June 20, 2017 12:01
kube-controller-manager metrics
claims_depth
etcd_helper_cache_hit_count
replicationmanager_adds
deployment_adds
serviceaccount_tokens_secret_work_duration_sum
disruption_work_duration_sum
garbage_collector_operation_extensions_v1beta1_rate_limiter_use
resourcequota_primary_retries
serviceaccount_tokens_service_queue_latency_count
service_queue_latency_sum
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
)
@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")
@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 / 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: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 / 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 / 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: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))