prometheus examples

This commit is contained in:
Marcel Dempers 2019-08-25 19:44:35 +10:00 committed by marcel-dempers
parent a0d7e2ad36
commit a906ff68b7
6 changed files with 123 additions and 1 deletions

View File

@ -1,9 +1,12 @@
# docker-development-youtube-series
# Docker Development Guide
## a Youtube Series
Hi!
This is the source code for the YouTube series covering docker-based development workflows.
## Docker Development Basics
Part #1: The Dockerfiles (.NET, Golang, Python, NodeJS) <br/>
Video: https://youtu.be/wyjNpxLRmLg <br/>
Source code for Part #1: https://github.com/marcel-dempers/docker-development-youtube-series/tree/part1
@ -24,4 +27,11 @@ Part #5: Debugging .NET Core code in Docker <br/>
Video: https://youtu.be/ds2bud0ZYTY <br/>
Source code for Part #5 https://github.com/marcel-dempers/docker-development-youtube-series/tree/part5
## Prometheus Monitoring
Let's take a look how to monitor application code using Prometheus.
See the [Prometheus Monitoring](./prometheus-monitoring/readme.md) readme guide for detailed steps
More details coming soon!

View File

@ -0,0 +1,30 @@
FROM golang:1.11.13-alpine3.10 as builder
# installing git
RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh
# setting working directory
WORKDIR /go/src/app
# installing dependencies
RUN go get github.com/leonelquinteros/gorand
RUN go get github.com/sirupsen/logrus
RUN go get github.com/prometheus/client_golang/prometheus
RUN go get github.com/prometheus/client_golang/prometheus/promauto
RUN go get github.com/prometheus/client_golang/prometheus/promhttp
COPY / /go/src/app/
RUN go build -o myapp
FROM alpine:3.10
RUN apk update && apk upgrade && \
apk add --no-cache openssh curl ca-certificates
WORKDIR /go/src/app
COPY --from=builder /go/src/app/myapp /go/src/app/myapp
EXPOSE 80
CMD ["./myapp"]

View File

@ -0,0 +1,46 @@
package main
import (
"fmt"
"time"
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
requestsProcessed = promauto.NewCounter(prometheus.CounterOpts{
Name: "request_operations_total",
Help: "The total number of processed requests",
})
)
var (
requestDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "request_duration_seconds",
Help: "Histogram for the runtime of a simple example function.",
Buckets: prometheus.LinearBuckets(0.5, 1.0, 2),
})
)
func main() {
fmt.Println("starting...")
http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {
timer := prometheus.NewTimer(requestDuration)
defer timer.ObserveDuration()
time.Sleep(1000 * time.Millisecond) //Sleep for a second
fmt.Fprint(w, "Welcome to my application!")
requestsProcessed.Inc()
})
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":80", nil)
}

View File

@ -0,0 +1,24 @@
version: "3"
services:
my-application:
build: ./application
container_name: my-application
image: my-application
ports:
- "80:80"
prometheus:
container_name: prometheus-svc
image: prom/prometheus
ports:
- "9090:9090"
command: --config.file=/etc/prometheus/prometheus.yaml
volumes:
- ./prometheus.yaml:/etc/prometheus/prometheus.yaml
grafana:
image: grafana/grafana:5.0.4
ports:
- "3000:3000"
environment:
- GF_AUTH_BASIC_ENABLED=false
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin

View File

@ -0,0 +1,8 @@
global:
scrape_interval: 5s
evaluation_interval: 30s
scrape_configs:
- job_name: my-application
honor_labels: true
static_configs:
- targets: ['my-application']

View File

@ -0,0 +1,4 @@
# Prometheus Application Monitoring
## a Video reference guide
coming soon!