Skip to content

Instantly share code, notes, and snippets.

View kozalosev's full-sized avatar

Leonid Kozarin kozalosev

View GitHub Profile
@kozalosev
kozalosev / serve-metrics-from-logs.sh
Created March 2, 2023 20:33
A simple bash script that collects logs from the Docker daemon and transforms counts of errors and warnings into metrics for Prometheus.
#!/bin/sh
err_metric_name=docker_logs_services_errors_total
warn_metric_name=docker_logs_services_warnings_total
collect_metrics() {
logs=$(docker ps --format '{{.Names}}' | xargs -L 1 docker logs 2>&1)
errors=$(echo "$logs" | grep -ic 'ERROR\|FATAL' | sed "s/.*/# TYPE ${err_metric_name} counter\\n# HELP ${err_metric_name} Errors metric\\n${err_metric_name} \\0/")
warnings=$(echo "$logs" | grep -ic 'WARN\(ING\)\?' | sed "s/.*/# TYPE ${warn_metric_name} counter\\n# HELP ${warn_metric_name} Errors metric\\n${warn_metric_name} \\0/")
echo "$errors\n$warnings"
}
@kozalosev
kozalosev / cloudflare-update-record.service
Created October 15, 2018 20:07 — forked from benkulbertis/cloudflare-update-record.sh
Cloudflare API v4 Dynamic DNS Update in Bash
[Unit]
Description=Update a DNS record using Cloudflare DDNS service
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
StandardOutput=journal
StandardError=journal
@kozalosev
kozalosev / search_for_vk_users.py
Created April 6, 2018 00:03
Search for VK users with specified name and count of friends
import vk
from time import sleep
from pprint import pprint
TOKEN = '<access token>'
FIRST_NAMES = ('Imya', 'Имя')
LAST_NAMES = ('Familiya', 'Фамилия')
FRIENDS_MIN = 100
FRIENDS_MAX = 120
@kozalosev
kozalosev / .cvimrc
Last active April 8, 2018 13:54
A configuration file for cVim (extension for Google Chrome)
""" SETTINGS """
set smoothscroll " Use smooth scrolling
set linkanimations " Show fade effect when link hints open and close
set cncpcompletion " Use <C-p> to cycle through completion results (I don't know how to make <C-n> work)
""" SEARCH ENGINES """
let searchengine yandex = ['https://yandex.ru', 'https://yandex.ru/search/?text=%s']
@kozalosev
kozalosev / we-need-you.groovy
Last active November 14, 2017 04:08
A simple plugin for the DeskChan application to urge other programmers to join us in plugin development.
import java.nio.file.Paths
def whatWeSearchingFor = [
'.gradle',
'.m2',
'.groovy',
'.Idea',
'.PyCharm',
'.eclipse',
@kozalosev
kozalosev / Demonstration.kt
Created October 22, 2017 22:43
An implementation of the switch-case operator in Kotlin
fun main(args : Array<String>) {
listOf("Hello!", "Bye!", "foo bar", "abcdefghijklmno").forEach {
val result = switch(it) {
case({ it.length > 10 }) { "The string is too long!" }
case("Hello!") { println("Hi!") }
case("Bye!") { println("See you next time!") }
default { "[Unexpected case]" }
}