Skip to content

Instantly share code, notes, and snippets.

@max-rocket-internet
max-rocket-internet / prom-k8s-request-limits.md
Last active April 15, 2024 08:06
How to display Kubernetes request and limit in Grafana / Prometheus properly

CPU: percentage of limit

A lot of people land when trying to find out how to calculate CPU usage metric correctly in prometheus, myself included! So I'll post what I eventually ended up using as I think it's still a little difficult trying to tie together all the snippets of info here and elsewhere.

This is specific to k8s and containers that have CPU limits set.

To show CPU usage as a percentage of the limit given to the container, this is the Prometheus query we used to create nice graphs in Grafana:

sum(rate(container_cpu_usage_seconds_total{name!~".*prometheus.*", image!="", container_name!="POD"}[5m])) by (pod_name, container_name) /
@bourdeau
bourdeau / Python_Stuff.md
Last active April 21, 2023 05:58
Python Stuff

Inheritance & DI

Multiple inheritance can lead to multi level diamond diagram. In Python it is solved by C3 linearization.

Python doesn't need DI because it has super(). It doesn't work like parent() in other Typed programming languages such as Java or PHP.

In multiple inheritance super() doesn't call the parents but the ancestors:

class Adam(): pass
@dleske
dleske / k8s-update-secret.md
Last active January 29, 2024 17:12
k8s: Updating a Secret

Hopefully helped another k8s newbie with the following. The question was, how do you update a single key in a secret in k8s? I don't know anything about secrets but I will probably want to know this in the future, so here we go.

First, to create a dummy secret:

apiVersion: v1
kind: Secret
metadata:
  name: test-secret
data:
@marwei
marwei / how_to_reset_kafka_consumer_group_offset.md
Created November 9, 2017 23:39
How to Reset Kafka Consumer Group Offset

Kafka 0.11.0.0 (Confluent 3.3.0) added support to manipulate offsets for a consumer group via cli kafka-consumer-groups command.

  1. List the topics to which the group is subscribed
kafka-consumer-groups --bootstrap-server <kafkahost:port> --group <group_id> --describe

Note the values under "CURRENT-OFFSET" and "LOG-END-OFFSET". "CURRENT-OFFSET" is the offset where this consumer group is currently at in each of the partitions.

  1. Reset the consumer offset for a topic (preview)
@mjtamlyn
mjtamlyn / cursor.py
Last active December 2, 2021 08:42
Graphene pagination
import functools
from django.db.models import Prefetch, QuerySet
import attr
import graphene
from cursor_pagination import CursorPaginator
from graphene.utils.str_converters import to_snake_case
from graphql_relay import connection_from_list
@kevin-smets
kevin-smets / 1_kubernetes_on_macOS.md
Last active May 5, 2024 10:12
Local Kubernetes setup on macOS with minikube on VirtualBox and local Docker registry

Requirements

Minikube requires that VT-x/AMD-v virtualization is enabled in BIOS. To check that this is enabled on OSX / macOS run:

sysctl -a | grep machdep.cpu.features | grep VMX

If there's output, you're good!

Prerequisites

@gpessia
gpessia / 10 SASS (SCSS) mixins
Last active May 19, 2022 17:19
10 SASS (SCSS) mixins you should be using in your projects | Engage
/* ==========================================================================
10 SASS (SCSS) mixins you should be using in your projects | Engage
http://engageinteractive.co.uk/blog/top-10-scss-mixins
========================================================================== */
/* ==========================================================================
To quickly centre a block element without having to worry about if there is any top or bottom margin already applied.
========================================================================== */