Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Shahid1993/a6e47c720b14aec9a4cc1931c51a1c96 to your computer and use it in GitHub Desktop.

Select an option

Save Shahid1993/a6e47c720b14aec9a4cc1931c51a1c96 to your computer and use it in GitHub Desktop.

Revisions

  1. @ipedrazas ipedrazas created this gist Apr 23, 2018.
    28 changes: 28 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    // https://github.com/stefanprodan/k8s-podinfo/blob/master/pkg/server/instrument.go

    func NewInstrument() *Instrument {
    // used for monitoring and alerting (RED method)
    histogram := prometheus.NewHistogramVec(prometheus.HistogramOpts{
    Subsystem: "http",
    Name: "requests",
    Help: "Seconds spent serving HTTP requests.",
    Buckets: prometheus.DefBuckets,
    }, []string{"method", "path", "status"})
    // used for horizontal pod auto-scaling (Kubernetes HPA v2)
    counter := prometheus.NewCounterVec(
    prometheus.CounterOpts{
    Subsystem: "http",
    Name: "requests_total",
    Help: "The total number of HTTP requests.",
    },
    []string{"status"},
    )

    prometheus.MustRegister(histogram)
    prometheus.MustRegister(counter)

    return &Instrument{
    Histogram: histogram,
    Counter: counter,
    }
    }