Skip to content

Instantly share code, notes, and snippets.

View adivinho's full-sized avatar
🔨

Vadim Yalovets adivinho

🔨
View GitHub Profile
@adivinho
adivinho / cleanup-dash.py
Last active March 15, 2021 16:03
automate dashboards importing in PMM2
#!/usr/bin/env python
import sys
import json
""" Prometheus has been replaced by VictoriaMetrics since PMM 2.13.0 """
datasources = [['${DS_METRICS}','Metrics'],
['${DS_PTSUMMARY}','PTSummary'],
['${DS_CLICKHOUSE}','ClickHouse'],
['${DS_PROMETHEUS_ALERTMANAGER}','Prometheus AlertManager']]
## Custom query
pg_database_size:
query: "SELECT pg_database.datname as datname, pg_database_size(pg_database.datname) AS bytes FROM pg_database"
metrics:
- datname:
usage: "LABEL"
description: "Name of the database that this table is in"
- bytes:
usage: "GAUGE"
description: "Total disk space in bytes used by the specified database"
## Custom query
pg_class:
query: "SELECT datname, COALESCE(sbtest.relname) as relname, COALESCE(sbtest.rows) as rows, COALESCE(sbtest.total) as total, COALESCE(sbtest.index) as index, COALESCE(sbtest.toast,0) as toast FROM pg_database LEFT OUTER JOIN dblink('dbname=sbtest','SELECT current_database(), relname, CAST(reltuples as BIGINT), pg_total_relation_size(oid), pg_indexes_size(oid), pg_total_relation_size(reltoastrelid) FROM pg_class') as sbtest(datname name, relname name, rows BIGINT, total BIGINT, index BIGINT, toast BIGINT) USING (datname) WHERE datname NOT LIKE 'template_' AND datname NOT LIKE 'postgres'"
metrics:
- datname:
usage: "LABEL"
description: "Name of the database that this table is in"
- relname:
usage: "LABEL"
description: "Name of the table, index, view, etc."
#!/bin/bash
# "---------------------------------------------------"
# " This is a simple script for creating a query "
# " that collects data from the table pg_class "
# " for list of databases "
# "---------------------------------------------------"
if [ "$#" -eq 0 ] ;
then
echo -e "\n\tYou must enter at least one database name as an argument."
@adivinho
adivinho / revert-a-commit.md
Created September 30, 2019 21:02 — forked from gunjanpatel/revert-a-commit.md
Git HowTo: revert a commit already pushed to a remote repository

Revert the full commit

Sometimes you may want to undo a whole commit with all changes. Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it.

git revert {commit_id}'

About History Rewriting

Delete the last commit

Deleting the last commit is the easiest case. Let's say we have a remote origin with branch master that currently points to commit dd61ab32. We want to remove the top commit. Translated to git terminology, we want to force the master branch of the origin remote repository to the parent of dd61ab32:

pg_stat_statements:
query: "SELECT
pg_get_userbyid(userid) as user,
pg_database.datname,
pg_stat_statements.queryid,
pg_stat_statements.query,
pg_stat_statements.calls,
pg_stat_statements.total_time as time_milliseconds,
pg_stat_statements.rows,
pg_stat_statements.shared_blks_hit,
@adivinho
adivinho / genhash
Created March 4, 2019 13:12 — forked from ianmariano/genhash
generate a base-64 encoded sha-256 password hash with openssl on the command line
# generate an SHA-256 password hash base64 encoded
echo -n "password" | openssl dgst -sha256 -binary | openssl base64
# better yet, use pepper (suffix the password with the pepper)
echo -n "passwordpepper" | openssl dgst -sha256 -binary | openssl base64
# better yet, use salt (prefix the password with the salt)
echo -n "saltpassword" | openssl dgst -sha256 -binary | openssl base64
@adivinho
adivinho / delete_git_submodule.md
Last active March 20, 2019 17:11 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm -r --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@adivinho
adivinho / postgres_query_generator.sh
Last active September 27, 2019 15:44
The scripts generates a code for custom query file related to tables pg_stat_user_tables (postgres_exporter)
#!/bin/bash
# "-----------------------------------------------------------"
# " This is a simple script for creating a query "
# " that collects data from the table pg_stat_user_tables "
# " for list of databases "
# "-----------------------------------------------------------"
if [ "$#" -eq 0 ] ;
then
echo -e "\n\tYou must enter at least one database name as an argument."
version: "3"
services:
pmm-server:
image: "perconalab/pmm-server:dev-latest"
ports:
- "443:443"
environment:
- SERVER_USER=pmm
- SERVER_PASSWORD=pmm