Skip to content

Instantly share code, notes, and snippets.

View tsungtwu's full-sized avatar

Tsung Wu tsungtwu

View GitHub Profile
@tsungtwu
tsungtwu / prometheus.yml
Created March 2, 2021 18:21 — forked from KekSfabrik/prometheus.yml
prometheus consul SD config
global:
scrape_timeout: 10s
scrape_interval: 15s
external_labels:
cluster: 'MY CLUSTER NAME'
# alternatively can be found via consul -- for details see
# https://prometheus.io/docs/prometheus/latest/migration/#alertmanager-service-discovery
alerting:
alertmanagers:
@tsungtwu
tsungtwu / monzo-alertmanager-config.yaml
Created February 7, 2021 14:10 — forked from milesbxf/monzo-alertmanager-config.yaml
Monzo's Alertmanager Slack templates
###################################################
##
## Alertmanager YAML configuration for routing.
##
## Will route alerts with a code_owner label to the slack-code-owners receiver
## configured above, but will continue processing them to send to both a
## central Slack channel (slack-monitoring) and PagerDuty receivers
## (pd-warning and pd-critical)
##
@tsungtwu
tsungtwu / postgresql-set-id-seq.sql
Created December 27, 2020 02:33 — forked from henriquemenezes/postgresql-set-id-seq.sql
PostgreSQL set Next ID Sequence Value to MAX(id) from Table
-- Get Max ID from table
SELECT MAX(id) FROM table;
-- Get Next ID from table
SELECT nextval('table_id_seq');
-- Set Next ID Value to MAX ID
SELECT setval('table_id_seq', (SELECT MAX(id) FROM table));
@tsungtwu
tsungtwu / django-grafana-proxy.py
Created September 23, 2020 05:44 — forked from feroda/django-grafana-proxy.py
Django reverse proxy for Grafana SSO
"""
## Install the Django reverse proxy package: `pip install django-revproxy`
## Enable auth.proxy authentication in Grafana like the following
```
[auth.proxy]
enabled = true
header_name = X-WEBAUTH-USER
header_property = username
@tsungtwu
tsungtwu / postgres_queries_and_commands.sql
Last active December 1, 2020 17:15 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@tsungtwu
tsungtwu / README-setup-tunnel-as-systemd-service.md
Created July 27, 2020 09:43 — forked from drmalex07/README-setup-tunnel-as-systemd-service.md
Setup a secure (SSH) tunnel as a systemd service. #systemd #ssh #ssh-tunnel #ssh-forward

README

Create a template service file at /etc/systemd/system/secure-tunnel@.service. The template parameter will correspond to the name of target host:

[Unit]
Description=Setup a secure tunnel to %I
After=network.target
@tsungtwu
tsungtwu / nginx_secure_url.go
Created December 11, 2019 09:22 — forked from chocolatkey/nginx_secure_url.go
Generate signed URIs for a client to access links secured with ngx_http_secure_link_module
/**
Example of how to configure Nginx for signed urls. Make sure to replace YOUR_URL_SECRET_KEY_HERE with your url signing key
location /secrets/ {
# Headers for debugging
add_header X-Secure-Uri "$uri";
add_header X-Secure-Ip "$remote_addr";
add_header X-Secure-Expires "$arg_expires";
@tsungtwu
tsungtwu / nginx_reverse_proxy.md
Created November 27, 2019 04:51 — forked from KavenTheriault/nginx_reverse_proxy.md
Configure Nginx Reverse Proxy as failover

Configure Nginx Reverse Proxy as failover

In this exemple of configuration, if the first server fail (proxy_connect_timeout) one time (max_fails), the second server will be used for 60s (fail_timeout).

The SSL certificate need to be configure on the ReverseProxy server AND the proxyied servers. You can use the same certificate and configurations on all servers.

To test the configuration you can change your host file to simulate the correct domain name.

Use the following tool to configure SSL with optimal configuration.

@tsungtwu
tsungtwu / node_exporter-as-systemd-service.md
Created October 25, 2019 04:34 — forked from jarek-przygodzki/node_exporter-as-systemd-service.md
Installing node_exporter as systemd serivice
sudo useradd --no-create-home --shell /bin/false node_exporter
curl -fsSL https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz \
  | sudo tar -zxvf - -C /usr/local/bin --strip-components=1 node_exporter-0.17.0.linux-amd64/node_exporter \
  && sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
  • What do Etcd, Consul, and Zookeeper do?
    • Service Registration:
      • Host, port number, and sometimes authentication credentials, protocols, versions numbers, and/or environment details.
    • Service Discovery:
      • Ability for client application to query the central registry to learn of service location.
    • Consistent and durable general-purpose K/V store across distributed system.
      • Some solutions support this better than others.
      • Based on Paxos or some derivative (i.e. Raft) algorithm to quickly converge to a consistent state.
  • Centralized locking can be based on this K/V store.