diff --git a/README.md b/README.md index 9c173f9..d6c613d 100644 --- a/README.md +++ b/README.md @@ -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)
Video: https://youtu.be/wyjNpxLRmLg
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
Video: https://youtu.be/ds2bud0ZYTY
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! diff --git a/prometheus-monitoring/application/dockerfile b/prometheus-monitoring/application/dockerfile new file mode 100644 index 0000000..11e3ef9 --- /dev/null +++ b/prometheus-monitoring/application/dockerfile @@ -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"] \ No newline at end of file diff --git a/prometheus-monitoring/application/main.go b/prometheus-monitoring/application/main.go new file mode 100644 index 0000000..c250070 --- /dev/null +++ b/prometheus-monitoring/application/main.go @@ -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) + +} diff --git a/prometheus-monitoring/docker-compose.yaml b/prometheus-monitoring/docker-compose.yaml new file mode 100644 index 0000000..11d4375 --- /dev/null +++ b/prometheus-monitoring/docker-compose.yaml @@ -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 \ No newline at end of file diff --git a/prometheus-monitoring/prometheus.yaml b/prometheus-monitoring/prometheus.yaml new file mode 100644 index 0000000..ebda551 --- /dev/null +++ b/prometheus-monitoring/prometheus.yaml @@ -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'] \ No newline at end of file diff --git a/prometheus-monitoring/readme.md b/prometheus-monitoring/readme.md new file mode 100644 index 0000000..a80d17f --- /dev/null +++ b/prometheus-monitoring/readme.md @@ -0,0 +1,4 @@ +# Prometheus Application Monitoring +## a Video reference guide + +coming soon! \ No newline at end of file