Skip to content

Instantly share code, notes, and snippets.

View dpsoft's full-sized avatar

Diego Parra dpsoft

View GitHub Profile
use std::{sync, thread};
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::{Duration, Instant};
use hdrhistogram::Histogram;
pub struct HiccupMonitor {
hiccup_nanos: u64,
histogram: Arc<Mutex<Histogram<u64>>>,
@dpsoft
dpsoft / Armeria.scala
Last active July 9, 2020 14:02
Armeria Instrumentation(first working approach)
package kamon.armeria
import kamon.instrumentation.http.HttpMessage.Request
import kamon.instrumentation.http.HttpOperationNameGenerator
object Armeria
class DefaultNameGenerator extends HttpOperationNameGenerator {
import java.util.Locale
@dpsoft
dpsoft / KamonSpringExampleApplication.java
Last active January 16, 2020 13:39
kamon-spring-example
package com.example.demo;
import kamon.Kamon;
import kamon.prometheus.PrometheusReporter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class KamonSpringExampleApplication {
@dpsoft
dpsoft / TCPDUMP.md
Created December 13, 2018 20:11
TCPDUMP

TCPDUMP

Muy útil para depurar los mensajes que se envían por la red.

Permite ver en tiempo real los paquetes TCP/UDP que están pasando por la red. Por ejemplo, podríamos entrar a una app y ver como se comunica con otra. Supongamos que se comunica app-02 mediante el puerto 2020:

sudo tcpdump -i any -A "host app-02 and port 2020"
@dpsoft
dpsoft / FileTransport.java
Created November 29, 2018 17:26
Smart Batching
package smart;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
public class FileTransport implements Transport {
private final RandomAccessFile file;
object GoogleService {
def service[F[_]: Effect](c: Client[F]): HttpService[F] = {
val dsl = new Http4sDsl[F]{}
import dsl._
HttpService[F] {
case GET -> Root / "not" =>
Thread.sleep((Math.random() * 1000).toLong)
NotFound("NotFound")
case req@GET -> Root / "call-google" =>
/*
* =========================================================================================
* Copyright © 2013-2018 the kamon project <http://kamon.io/>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
object Process {
type UserTime = Long
type KernelTime = Long
type StartTime = Long
//Hertz (number of clock ticks per second) of your system.
val Hz: Long = executeCmd("getconf CLK_TCK").map(_.toLong).getOrElse(100L)
/**
import java.util.concurrent.atomic.AtomicLong
import scala.annotation.tailrec
class LongMaxUpdater(value:AtomicLong) {
def update(newMax:Long):Long = {
@tailrec def compare():Long = {
val currentMax = value.get()
if(newMax > currentMax) {
if (!value.compareAndSet(currentMax, newMax)) compare()
else newMax