Giter Club home page Giter Club logo

go-prom-pprof-utils's Introduction

example

package main

import (
	"context"
	su "github.com/ppzxc/go-prom-pprof-utils"
	"github.com/sirupsen/logrus"
	"net"
	"os"
	"time"
)

func main() {
	ctx, _ := context.WithCancel(context.Background())

	addr := net.TCPAddr{
		IP:   net.ParseIP("0.0.0.0"),
		Port: 8080,
	}

	logger := logrus.Logger{
		Out:          os.Stdout,
		Formatter:    &logrus.TextFormatter{},
		ReportCaller: true,
		Level:        logrus.TraceLevel,
	}

	err := su.NewStatUtils(ctx, "TEST", true, &addr, &logger)
	if err != nil {
		panic(err)
	}

	su.SetGauge("fill")
	su.SetGauge("session", "type")
	su.SetCounter("fill2")
	su.SetCounter("session2", "type")
	su.SetHistogram("fill3", []float64{0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.5, 1, 5, 10, 20, 30})
	su.SetHistogram("session3", []float64{0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.5, 1, 5, 10, 20, 30}, "type", "query", "dd")

	go func() {
		for {
			now := time.Now()
			su.Increase("fill")
			su.Increase("session", "tcp")
			su.Increase("session", "websocket")
			su.Increase("fill2")
			su.Increase("session2", "tcp")
			su.Increase("session2", "websocket")
			su.IncreaseHistogram("fill3", now)
			su.IncreaseHistogram("session3", now, "db", "query1", "ee")
			su.IncreaseHistogram("session3", now, "db", "query3", "ee")
			su.IncreaseHistogram("session3", now, "db", "query2", "ee")
			su.IncreaseHistogram("session3", now, "db", "query5", "ee")
			time.Sleep(1 * time.Second)
		}
	}()

	su.Serve()
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.