Skip to content

Instantly share code, notes, and snippets.

View zokis's full-sized avatar

Marcelo Fonseca Tambalo zokis

View GitHub Profile
@max-rocket-internet
max-rocket-internet / prom-k8s-request-limits.md
Last active June 5, 2024 02:27
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) /
@zokis
zokis / parcelas.py
Last active August 29, 2015 14:23
calcula parcelas
from decimal import Decimal
from math import floor
def parcelas(valor, n, div=False, primeira=False):
formato = Decimal('0.00')
valor = Decimal(valor)
if div:
parcela = Decimal(floor(valor * 100 / n) / 100)
else:
@zokis
zokis / url_p.py
Created August 26, 2012 03:43
URL Parser
"""
http://www.gmail.com/g/mail?fr=3&ui=2
http://gmail.com
ssh://marcelo@git.com
ftp://ime.usp.com.br/~denis/?model=SistemasDeArquivo
"""
import unittest
import string
@jeffkistler
jeffkistler / geojson.py
Created May 11, 2011 20:30
GeoJSON Django GeoQuerySet Serializer
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
import datetime
import decimal
from django.core.serializers.python import Serializer as PythonSerializer
from django.core.serializers.json import DjangoJSONEncoder
from django.utils.encoding import is_protected_type, smart_unicode