Skip to content

Instantly share code, notes, and snippets.

View ruanbekker's full-sized avatar
🇿🇦

Ruan Bekker ruanbekker

🇿🇦
View GitHub Profile
@ruanbekker
ruanbekker / pushover_notifiers_examples.md
Created February 7, 2021 12:05
Pushover Notifiers Examples

In BASH:

# usage: ./pushover-notify home-pc "homepc notification"
#!/bin/bash
APP_TOKEN='x'
USER_TOKEN='x'
TITLE="$1"
MESSAGE="$2"
curl 'https://api.pushover.net/1/messages.json' -X POST -d "token=$APP_TOKEN&user=$USER_TOKEN&message=\"$MESSAGE\"&title=$TITLE"
@ruanbekker
ruanbekker / random_strings_or_numbers.md
Last active February 1, 2021 14:42
Bash: Return random number or string from array or range

Return random string from array:

#!/usr/bin/env bash
subnets[0]="subnet1"
subnets[1]="subnet2"
subnets[2]="subnet3"

size=${#subnets[@]}
index=$(($RANDOM % $size))
@ruanbekker
ruanbekker / grafana_cloud_agent.md
Created January 14, 2021 13:40
Setup Grafana Cloud Agent for Linux

Download:

curl -O -L "https://github.com/grafana/agent/releases/latest/download/agent-linux-amd64.zip";
unzip "agent-linux-amd64.zip";
chmod a+x "agent-linux-amd64";

Move to place:

@ruanbekker
ruanbekker / 01_unit_tests_with_flask.md
Created January 11, 2021 13:41
Python Flask Unit Tests
$ docker build -t local:flask .
$ docker run -it -p 8080:8080 local:flask
$ python app_test.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
@ruanbekker
ruanbekker / flask_prometheus.md
Created January 11, 2021 13:30
Python Flask with Prometheus Basic Example
$ curl http://localhost:5000/metrics
# HELP python_gc_objects_collected_total Objects collected during gc
# TYPE python_gc_objects_collected_total counter
python_gc_objects_collected_total{generation="0"} 317.0
python_gc_objects_collected_total{generation="1"} 71.0
python_gc_objects_collected_total{generation="2"} 0.0
# HELP python_gc_objects_uncollectable_total Uncollectable object found during GC
# TYPE python_gc_objects_uncollectable_total counter
python_gc_objects_uncollectable_total{generation="0"} 0.0
@ruanbekker
ruanbekker / flask_timing_requests.py
Created January 11, 2021 13:13
Timing requests with Python Flask
# source: https://opensource.com/article/18/4/metrics-monitoring-and-python
from flask import request
import csv
import time
def start_timer():
request.start_time = time.time()
def stop_timer(response):
# convert this into milliseconds for statsd
@ruanbekker
ruanbekker / gitea-docker-compose.yml
Created December 28, 2020 19:53
gitlab and drone server on docker for ubuntu 20
version: "3.7"
services:
# https://docs.gitea.io/en-us/install-with-docker/
gitea:
image: gitea/gitea:1.12.4
# https://hub.docker.com/r/gitea/gitea/tags
container_name: gitea
environment:
- APP_NAME=Gitea
@ruanbekker
ruanbekker / envsubst_example.md
Created December 17, 2020 12:30
Replacing Environment Variables with envsubst
$ cat test.tmpl
Hi ${USER}, this is a ${ENVIRONMENT} environment
USER=ruan ENVIRONMENT=test envsubst '${USER},${ENVIRONMENT}' < test.tmpl
Hi ruan, this is a test environment
@ruanbekker
ruanbekker / index.html
Created December 11, 2020 22:18
index.html sample page
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
<title>Sample Page</title>
</head>
<body>
<div class="container-fluid">
@ruanbekker
ruanbekker / 00_README.md
Created December 4, 2020 08:50
Loki absent_over_time workaround using AWS Lambda

Loki absent over time workaround

This is a workaround that works for my use-case when log content are not present withing a minute, using AWS Lambda and AWS CloudWatch Events

Setup:

  • AWS CloudWatch event triggers the Lambda every minute
  • Lambda uses the Loki API to search for logs, if nothing has been found it retries if still fails, it alerts
  • It alerts to slack.