Skip to content

Instantly share code, notes, and snippets.

@chasers
chasers / logflare_cloudflare_worker_with_batching.js
Created May 17, 2021 17:07
logflare_cloudflare_worker_with_batching
const sleep = ms => {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
}
const makeid = length => {
let text = ""
const possible = "ABCDEFGHIJKLMNPQRSTUVWXYZ0123456789"
for (let i = 0; i < length; i += 1) {
@chasers
chasers / find_dbconnection_procs_erlang_elxir.ex
Created October 25, 2023 20:43
Finds DBConnection processes from Process.info
Enum.each(Process.list, fn pid ->
case Process.info(pid)[:dictionary] do
[_, "$initial_call": {:supervisor, DBConnection.ConnectionPool.Pool, _}] ->
state = :sys.get_state(pid, 5000)
case elem(state, 11) do
{pid, _, Postgrex.Protocol, opts} ->
if opts[:hostname] == "db.REDACTED.supabase.co" do
IO.inspect({pid, state})
end
_ -> nil
@chasers
chasers / simple-logflare-cloudflare-worker.js
Created November 23, 2021 16:01
Simple Logflare Cloudflare worker no batching.
const makeid = length => {
let text = ""
const possible = "ABCDEFGHIJKLMNPQRSTUVWXYZ0123456789"
for (let i = 0; i < length; i += 1) {
text += possible.charAt(Math.floor(Math.random() * possible.length))
}
return text
}
const buildMetadataFromHeaders = headers => {
@chasers
chasers / vector_pg_csv_parser.toml
Last active February 3, 2022 00:09
Vector Config to Parse Postgres CSV Logs and Send to Logflare
# Logs
[sources.pg_query_log]
type = "file"
include = [ "/logs/postgresql.csv" ]
read_from = "end"
[sources.pg_query_log.multiline]
start_pattern = "^20[0-9][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9].[0-9]{3} UTC,\""
mode = "halt_before"
@chasers
chasers / logflare_generic_json_ingest.sh
Created December 22, 2021 13:14
Ingest any JSON with Logflare
curl -X "POST" "https://api.logflare.app/logs/json?source=SOURCE_UUID" \
-H 'Content-Type: application/json; charset=utf-8' \
-H 'X-API-KEY: YOUR_API_KEY' \
-d $'[
{
"yellow": true,
"tags": [
"popular, tropical, organic"
],
"store": {
@chasers
chasers / logflare-custom-ingest.sh
Last active December 22, 2021 13:07
Logflare custom ingest POST request example
curl -X "POST" "https://api.logflare.app/api/logs?source=SOURCE_UUID" \
-H 'Content-Type: application/json' \
-H 'X-API-KEY: API_KEY' \
-d $'{
"message": "This is another log message.",
"metadata": {
"ip_address": "100.100.100.100",
"request_method": "POST",
"custom_user_data": {
"vip": true,
@chasers
chasers / logflare_ingest_api_request_curl_example.sh
Created December 22, 2021 13:07
Send Logflare log event batches with an API request
curl -X "POST" "https://api.logflare.app/api/logs?source=YOUR_SOURCE_UUID" \
-H 'Content-Type: application/json' \
-H 'X-Api-Key: YOUR_INGEST_API_KEY' \
-d $'{
"batch": [
{
"message": "A human readable event message!",
"metadata": {
"ip_address": "1.2.3.4",
"datacenter": "aws",
@chasers
chasers / cloudflare_decode_jwt.js
Created December 15, 2021 21:54
Cloudflare JWT decoding worker
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const token = getJwt(request)
const payload = get_payload(token)
@chasers
chasers / cmc_to_logflare.sh
Created September 24, 2021 17:59
Send crypto data to Logflare from CoinMarketCap
watch -n 10 \
'curl https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?slug=ethereum -H "X-CMC_PRO_API_KEY: CMC_KEY" -H "Accept: application/json" \
| curl -X POST --data-binary @- "https://api.logflare.app/logs/json?api_key=LOGFLARE_KEY&source=LOGFLARE_SOURCE_UUID" -H "Accept: application/json" -H "Content-Type: application/json"'
@chasers
chasers / logflare_fluentbit.txt
Created August 11, 2021 19:15
Logflare FluentBit Config
[INPUT]
Name tail
Path /var/log/syslog
[OUTPUT]
Name http
Match *
tls On
Host api.logflare.app
Port 443