Skip to content

Instantly share code, notes, and snippets.

View poy's full-sized avatar

Andrew Poydence poy

View GitHub Profile
@poy
poy / InstallJava8.sh
Created October 28, 2014 22:49
Testing ADD from url
#!/bin/bash -ex
OPENJDK8=openjdk-1.8
cd /tmp
rm -rf $OPENJDK8
mkdir $OPENJDK8
cd $OPENJDK8
# Grab latest URL
package main
import (
"doppler/dopplerservice"
"errors"
"log"
"os"
"strings"
"github.com/cloudfoundry/gosteno"
@poy
poy / subcommands.go
Last active February 27, 2023 06:02
Simple Subcommands in Go
package subcommands
import (
"fmt"
"log"
"os"
"strings"
)
type Command interface {

Multi-line Java message workaround

Having log lines out of order can be painful when monitoring Java stack traces. There is a work around involving modifing the Java log output to have your app reformat your stacktrace messages so any newline characters are replaced by a token; and then have your log parsing code replace that token with newline characters again. The following example is for the Java Logback library and ELK, but you may be able to use the same strategy for other Java log libraries and log aggregators.

With the Java Logback library you do this by adding %replace(%xException){'\n','\u2028'}%nopex to your logging config , and then use the following logstash conf.

# Replace the unicode newline character \u2028 with \n, which Kibana will display as a new line.
    mutate {
      gsub => [ "[@message]", '\u2028', "
"]
@poy
poy / dropped_udp.sh
Created June 6, 2017 15:55
Detects and counts dropped UDP packets for 60 seconds (for port 0x0d81)
#!/bin/bash
for i in `seq 0 60`; do
echo "sample $i";
timestamp=$(date +%s)
value=$(cat /proc/net/udp | grep ": 0100007F:0D81" | tr -s [:space:] '|' | sed 's/|/ /g' | awk '{print $13}')
echo "$timestamp $value"
sleep 1
done
@poy
poy / duration
Last active July 17, 2017 18:09
Prints duration between ns timestamps from stdin
package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
"time"
)
package bench_test
import (
"crypto/rand"
"fmt"
"os"
"testing"
"code.cloudfoundry.org/loggregator/doppler/internal/grpcmanager/v1"
"code.cloudfoundry.org/loggregator/plumbing"
package tree_test
import (
"math/rand"
"sort"
"testing"
avl "github.com/emirpasic/gods/trees/avltree"
"github.com/emirpasic/gods/utils"
)
fly -t loggregator builds -j=loggregator/loggregator-tests | grep -m1 -B 999999 failed | grep succeeded | wc -l
#!/bin/bash
for i in `ls`
do
for j in `ls $i`
do
repo="$i/$j"
echo $repo
pushd $repo