Skip to content

Instantly share code, notes, and snippets.

View pmuellr's full-sized avatar
🌀
Software developer @ Elastic working on Kibana. Previously @ NodeSource, IBM.

Patrick Mueller pmuellr

🌀
Software developer @ Elastic working on Kibana. Previously @ NodeSource, IBM.
View GitHub Profile
@pmuellr
pmuellr / cpu-percent.js
Created April 12, 2016 14:59
get CPU usage percent for a process in node, using proposed `process.cpuUsage()` function
'use strict'
// see: https://github.com/nodejs/node/pull/6157
var startTime = process.hrtime()
var startUsage = process.cpuUsage()
// spin the CPU for 500 milliseconds
var now = Date.now()
while (Date.now() - now < 500)
@pmuellr
pmuellr / eah-2024-mermaid.md
Last active February 29, 2024 06:42
eah 2024 images
sequenceDiagram
    participant Client
    participant Server
    Client->>Server: HTTP request
    Server->>Client: HTTP response
sequenceDiagram
@pmuellr
pmuellr / override-addEventListener.html
Created March 4, 2011 16:35
test to see what we can do when we override addEventListener
<!--
======================================================================
Example trying to show hooking addEventListener to see if we can
capture error state for errors that occur in the handler.
Basically, we can capture that an error occurred, and get the
error message, and the event and object that was fired that
caused code to run that caused the error. But no stack trace
or line information.
@pmuellr
pmuellr / git-wt-create.js
Created January 26, 2024 21:28
git-wt-create.js - print the command to create a git worktree given an issue number and branch name
#!/usr/bin/env node
const pathMod = require('node:path')
const PROGRAM = pathMod.basename(__filename)
const [issue, branch] = process.argv.slice(2)
if (!issue || !branch) {
console.log(`
Usage: ${PROGRAM} <issue #> <git branch name>
@pmuellr
pmuellr / zod+js+jsdoc.js
Created October 31, 2020 16:04
trying to use zod in js with jsdoc type comments for vs code - almost works!
'use strict'
// examples from https://github.com/vriad/zod
// trying to use zod in JS w/ jsdoc type comments in vsCode
const z = require('zod')
const dogSchema = z.object({
name: z.string(),
@pmuellr
pmuellr / event-log-rule-perf.txt
Created September 7, 2023 00:30
ES|QL to dump rule execution data
# https://www.elastic.co/guide/en/elasticsearch/reference/master/esql.html
POST /_query
{
"query": """
FROM .kibana-event-log-*
| WHERE event.provider == "alerting"
| WHERE event.action == "execute"
@pmuellr
pmuellr / ow23-05-visualizations.ndjson
Created May 12, 2023 13:37
onweek 2023-05 dashboard with event log visualizations
{"attributes":{"fieldAttrs":"{\"provider_rule_type\":{\"count\":1},\"event.action\":{\"count\":1}}","fieldFormatMap":"{\"event.duration\":{\"id\":\"duration\",\"params\":{\"parsedUrl\":{\"origin\":\"https://pmuellr-8-7-0.kb.us-central1.gcp.cloud.es.io:9243\",\"pathname\":\"/app/management/kibana/dataViews/patterns/kibana-event-log\",\"basePath\":\"\"},\"inputFormat\":\"nanoseconds\",\"outputFormat\":\"asSeconds\",\"outputPrecision\":2,\"includeSpaceWithSuffix\":true,\"showSuffix\":true,\"useShortSuffix\":true}}}","fields":"[]","name":"ow23-05-event-log","runtimeFieldMap":"{\"provider_rule_type\":{\"type\":\"keyword\",\"script\":{\"source\":\"def provider = doc[\\\"event.provider\\\"];\\ndef ruleTyp1 = doc[\\\"rule.category\\\"];\\ndef ruleTyp2 = doc[\\\"kibana.alert.rule.rule_type_id\\\"];\\n\\nif (provider == null || provider.size() == 0) return;\\n\\nif (ruleTyp1 != null && ruleTyp1.size() != 0) {\\n emit(provider.value + \\\"::\\\" + ruleTyp1.value);\\n return;\\n} \\n\\nif (ruleTyp2 != null && ruleT
@pmuellr
pmuellr / cid.js
Created October 5, 2012 23:05
Cordova iOS Developer tool
#!/usr/bin/env node
fs = require("fs")
path = require("path")
child_process = require("child_process")
//------------------------------------------------------------------------------
PROGRAM = path.basename(__filename)
VERSION = "0.2.0.2012-10-09"
@pmuellr
pmuellr / kbn-flapping-example.mjs
Created February 15, 2023 17:09
kbn-flapping-example.mjs - use the flapping rule example to test flapping
#!/usr/bin/env npx zx
import https from 'node:https'
import path from 'node:path'
const NAME = path.basename(import.meta.url)
$.verbose = false
const KBN_URL = process.env.KBN_URL
@pmuellr
pmuellr / hits2ndjson.js
Created December 14, 2022 18:11
Convert Elasticsearch "hits" JSON response to NDJSON format for easy importing back to Elasticsearch
#!/usr/bin/env node
const fs = require('fs')
const [ fileName ] = process.argv.slice(2)
if (fileName == null) {
console.error('input file with search response required')
process.exit(0)
}