mirror of
https://github.com/marcel-dempers/docker-development-youtube-series.git
synced 2025-06-06 17:01:30 +00:00
prometheus examples
This commit is contained in:
parent
a0d7e2ad36
commit
a906ff68b7
12
README.md
12
README.md
@ -1,9 +1,12 @@
|
|||||||
# docker-development-youtube-series
|
# Docker Development Guide
|
||||||
|
## a Youtube Series
|
||||||
|
|
||||||
Hi!
|
Hi!
|
||||||
|
|
||||||
This is the source code for the YouTube series covering docker-based development workflows.
|
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/>
|
Part #1: The Dockerfiles (.NET, Golang, Python, NodeJS) <br/>
|
||||||
Video: https://youtu.be/wyjNpxLRmLg <br/>
|
Video: https://youtu.be/wyjNpxLRmLg <br/>
|
||||||
Source code for Part #1: https://github.com/marcel-dempers/docker-development-youtube-series/tree/part1
|
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/>
|
Video: https://youtu.be/ds2bud0ZYTY <br/>
|
||||||
Source code for Part #5 https://github.com/marcel-dempers/docker-development-youtube-series/tree/part5
|
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!
|
More details coming soon!
|
||||||
|
30
prometheus-monitoring/application/dockerfile
Normal file
30
prometheus-monitoring/application/dockerfile
Normal 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"]
|
46
prometheus-monitoring/application/main.go
Normal file
46
prometheus-monitoring/application/main.go
Normal 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)
|
||||||
|
|
||||||
|
}
|
24
prometheus-monitoring/docker-compose.yaml
Normal file
24
prometheus-monitoring/docker-compose.yaml
Normal 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
|
8
prometheus-monitoring/prometheus.yaml
Normal file
8
prometheus-monitoring/prometheus.yaml
Normal 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']
|
4
prometheus-monitoring/readme.md
Normal file
4
prometheus-monitoring/readme.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Prometheus Application Monitoring
|
||||||
|
## a Video reference guide
|
||||||
|
|
||||||
|
coming soon!
|
Loading…
x
Reference in New Issue
Block a user