Skip to content

Instantly share code, notes, and snippets.

View spacez320's full-sized avatar

Matthew Coleman spacez320

View GitHub Profile
@spacez320
spacez320 / gist:fb02f3d5110f01d6ec0225c351e4de39
Last active April 3, 2024 19:23
How to delete an AWS Hosted Zone and all contained Records using just the AWS CLI
#!/bin/bash
#
# This demonstrates how to remove all records within a hosted zone in order to delete it. This is tricky because hosted zones
# must be empty (minus their standard SOA and NS records) and the removal of a record requires some non-trivial payload
# construction.
#
# Requires jq.
#
# Be careful deleting things!
@spacez320
spacez320 / insecure_ssl_pushgateway_handler.py
Created June 13, 2019 23:37
Insecure Pushgateway Connection Handler
def insecure_ssl_pushgateway_handler(url, method, timeout, headers, data):
"""Defines a handler which manages unverified SSL connections.
NOTE: This is used because client Python code will be addressing HTTPS endpoints that use TLS originating from
PathAI's CA, which is not normally verifiable.
Arguments are required by the handler interface in prometheus_client.push_to_gateway.
See: https://github.com/prometheus/client_py
@spacez320
spacez320 / timed_training.py
Created June 13, 2019 23:34
Summary Timer for Training
from my_metrics_lib import generate_push_metric, summary_timer
TRAINING_SUMMARY = generate_push_metric(
"Summary", "training_summary", "Time spent on training." )
@summary_timer(TRAINING_SUMMARY)
def do_training_make_models():
… money-making model training goes here …
@spacez320
spacez320 / summary_timer.py
Last active June 13, 2019 23:39
Summary Timer Function Decorator
def summary_timer(summary):
"""Decorator for timing functions using Pushgateway.
Args:
summary (prometheus_client.Summary): Summary to update and push.
Returns:
func: Summary timer decorator.
Example:
@spacez320
spacez320 / metric_example.py
Last active June 14, 2019 11:54
Metric Example
from my_metrics_lib import generate_push_metric
TRAINING_SUMMARY = generate_push_metric(
"Summary", "training_summary", "Time spent on training."
)
@spacez320
spacez320 / generate_push_metric.py
Last active June 13, 2019 23:05
Generate Push Metric Function
def generate_push_metric(metric_type, name, description, labels=None):
"""Creates a Prometheus metric for Pushgateway.
Args:
metric_type: Supported prometheus_client metric. Counter, Gauge, Summary, Histogram, Info, Enum.
name: Metric name.
description: Metric description.
labels: Metric labels. Default is None.
"""
# Figure out labels.
@spacez320
spacez320 / pushgateway_helper_library.py
Last active June 13, 2019 23:07
Pushgateway Helper Library
import prometheus_client
# Pushgateway endpoint, defaults to production Prometheus.
PUSHGATEWAY_URL = os.getenv('PROMETHEUS_PUSHGATEWAY_URL', 'https://production-pushgateway.our.services.com')
# Set up a registry for pushed metrics.
registry = prometheus_client.CollectorRegistry()
@spacez320
spacez320 / keybase.md
Created October 2, 2014 15:47
keybase.md

Keybase proof

I hereby claim:

  • I am spacez320 on github.
  • I am spacez320 (https://keybase.io/spacez320) on keybase.
  • I have a public key whose fingerprint is 0A1E EC57 77EE 6014 3C87 87C0 2163 6158 A09C CF45

To claim this, I am signing this object: