Skip to content

Instantly share code, notes, and snippets.

View sanderson's full-sized avatar

Scott Anderson sanderson

View GitHub Profile
@sanderson
sanderson / dynamic-alert.flux
Created March 2, 2022 22:25
Example of a dynamic alerting script in Flux
import "experimental/http/requests"
import "influxdata/influxdb/secrets"
import "json"
import ejson "experimental/json"
import "slack"
option task = {name: "example-task", every: 10m}
slackToken = secrets.get(key: "SLACK_TOKEN")
.searchbox {
display: inline-block;
position: relative;
width: 200px;
height: 32px !important;
white-space: nowrap;
box-sizing: border-box;
visibility: visible !important;
}
@sanderson
sanderson / confirmed-cases-since-100th.flux
Last active April 1, 2020 17:27
COVID-19 Flux Queries
alignTime = (tables=<-, alignTo=time(v: 0)) => {
_tableInfo = tables |> tableFind(fn: (key) => true) |> getRecord(idx: 0)
_startTime = if alignTo != time(v: 0) then alignTo else if exists _tableInfo._start then _tableInfo._start else time(v: 0)
_data = tables
|> stateDuration(
fn: (r) => true,
column: "timeDiff",
unit: 1ns
)
|> map(fn: (r) => ({ r with _time: time(v: (int(v: _startTime ) + r.timeDiff))}))
@sanderson
sanderson / sample_data.txt
Created June 25, 2018 17:00
Sample time-series data with negative and positive field values
# DDL
CREATE DATABASE sample
# DML
# CONTEXT-DATABASE: sample
data a=1.33909108671076,b=-0.163643058925645 1529841600000000000
data a=-0.774984088561186,b=0.137034364053949 1529841660000000000
data a=-0.921037167720451,b=-0.482943221384294 1529841720000000000
@sanderson
sanderson / apple_stand.txt
Last active February 3, 2021 11:22
Sample time series data for an apple stand
# DDL
CREATE DATABASE apple_stand
# DML
# CONTEXT-DATABASE: apple_stand
variety granny_smith=30,golden_delicious=30,fuji=30,gala=30,braeburn=30,total_weight=150 1529323200000000000
variety granny_smith=29.22,golden_delicious=28.98,fuji=29.63,gala=28.92,braeburn=30,total_weight=146.75 1529323500000000000
variety granny_smith=29.22,golden_delicious=27.87,fuji=29.63,gala=28.57,braeburn=29.69,total_weight=144.98 1529323800000000000
@sanderson
sanderson / apple-weights-line-protocol.txt
Created June 13, 2018 21:05
Percentage with Cumulative Total
weight apple_weight=0.11 1528113660000000000
weight apple_weight=0.42 1528113720000000000
weight apple_weight=0.83 1528113780000000000
weight apple_weight=0.07 1528113840000000000
weight apple_weight=0.19 1528113900000000000
weight apple_weight=0.43 1528113960000000000
weight apple_weight=0.67 1528114020000000000
weight apple_weight=0.24 1528114080000000000
weight apple_weight=0.74 1528114140000000000
weight apple_weight=0.03 1528114200000000000
@sanderson
sanderson / boxfile.yml
Created March 8, 2018 18:11
Mapping Environment Variables with Nanobox
deploy.config:
transform:
- bash set-evars.sh
@sanderson
sanderson / Job#1.sh
Created March 6, 2018 15:41
Semaphore CI & Nanobox
nanobox run test-command
if [ "$BRANCH_NAME" = "master" ]; then nanobox remote add production-app ; elif [ "$BRANCH_NAME" = "staging" ]; then nanobox remote add staging-app ; fi
COMMIT_MESSAGE="$(git log -1 --pretty=%B)"; nanobox deploy -m \'"${COMMIT_MESSAGE}"\'
@sanderson
sanderson / boxfile.yml
Created February 22, 2018 15:19
New Relic with the PHP engine
run.config:
engine: php
engine.config:
extensions:
- newrelic
extra_packages:
- newrelic
web.site:
start:
@sanderson
sanderson / Environment Variables
Last active March 15, 2018 22:26
Configuring Nanobox to Use nullmailer
SMTP_HOST=smtp-host
SMTP_PORT=smtp-port
SMTP_USER=smtp-username
SMTP_PASS=smtp-password
SMTP_TLS=tls|ssl
SMTP_AUTH=login|plain