Skip to content

Commit a906ff6

Browse files
prometheus examples
1 parent a0d7e2a commit a906ff6

File tree

6 files changed

+123
-1
lines changed

6 files changed

+123
-1
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
# docker-development-youtube-series
1+
# Docker Development Guide
2+
## a Youtube Series
23

34
Hi!
45

56
This is the source code for the YouTube series covering docker-based development workflows.
67

8+
## Docker Development Basics
9+
710
Part #1: The Dockerfiles (.NET, Golang, Python, NodeJS) <br/>
811
Video: https://youtu.be/wyjNpxLRmLg <br/>
912
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/>
2427
Video: https://youtu.be/ds2bud0ZYTY <br/>
2528
Source code for Part #5 https://github.com/marcel-dempers/docker-development-youtube-series/tree/part5
2629

30+
## Prometheus Monitoring
31+
32+
Let's take a look how to monitor application code using Prometheus.
33+
34+
See the [Prometheus Monitoring](./prometheus-monitoring/readme.md) readme guide for detailed steps
35+
36+
2737
More details coming soon!
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM golang:1.11.13-alpine3.10 as builder
2+
3+
# installing git
4+
RUN apk update && apk upgrade && \
5+
apk add --no-cache bash git openssh
6+
7+
# setting working directory
8+
WORKDIR /go/src/app
9+
10+
# installing dependencies
11+
RUN go get github.com/leonelquinteros/gorand
12+
RUN go get github.com/sirupsen/logrus
13+
RUN go get github.com/prometheus/client_golang/prometheus
14+
RUN go get github.com/prometheus/client_golang/prometheus/promauto
15+
RUN go get github.com/prometheus/client_golang/prometheus/promhttp
16+
17+
COPY / /go/src/app/
18+
RUN go build -o myapp
19+
20+
FROM alpine:3.10
21+
22+
RUN apk update && apk upgrade && \
23+
apk add --no-cache openssh curl ca-certificates
24+
25+
WORKDIR /go/src/app
26+
COPY --from=builder /go/src/app/myapp /go/src/app/myapp
27+
28+
EXPOSE 80
29+
30+
CMD ["./myapp"]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"time"
6+
"net/http"
7+
"github.com/prometheus/client_golang/prometheus"
8+
"github.com/prometheus/client_golang/prometheus/promauto"
9+
"github.com/prometheus/client_golang/prometheus/promhttp"
10+
)
11+
12+
var (
13+
requestsProcessed = promauto.NewCounter(prometheus.CounterOpts{
14+
Name: "request_operations_total",
15+
Help: "The total number of processed requests",
16+
})
17+
)
18+
19+
var (
20+
requestDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
21+
Name: "request_duration_seconds",
22+
Help: "Histogram for the runtime of a simple example function.",
23+
Buckets: prometheus.LinearBuckets(0.5, 1.0, 2),
24+
})
25+
)
26+
27+
28+
29+
func main() {
30+
31+
fmt.Println("starting...")
32+
33+
http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {
34+
35+
timer := prometheus.NewTimer(requestDuration)
36+
defer timer.ObserveDuration()
37+
time.Sleep(1000 * time.Millisecond) //Sleep for a second
38+
fmt.Fprint(w, "Welcome to my application!")
39+
40+
requestsProcessed.Inc()
41+
})
42+
43+
http.Handle("/metrics", promhttp.Handler())
44+
http.ListenAndServe(":80", nil)
45+
46+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: "3"
2+
services:
3+
my-application:
4+
build: ./application
5+
container_name: my-application
6+
image: my-application
7+
ports:
8+
- "80:80"
9+
prometheus:
10+
container_name: prometheus-svc
11+
image: prom/prometheus
12+
ports:
13+
- "9090:9090"
14+
command: --config.file=/etc/prometheus/prometheus.yaml
15+
volumes:
16+
- ./prometheus.yaml:/etc/prometheus/prometheus.yaml
17+
grafana:
18+
image: grafana/grafana:5.0.4
19+
ports:
20+
- "3000:3000"
21+
environment:
22+
- GF_AUTH_BASIC_ENABLED=false
23+
- GF_AUTH_ANONYMOUS_ENABLED=true
24+
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
global:
2+
scrape_interval: 5s
3+
evaluation_interval: 30s
4+
scrape_configs:
5+
- job_name: my-application
6+
honor_labels: true
7+
static_configs:
8+
- targets: ['my-application']

prometheus-monitoring/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Prometheus Application Monitoring
2+
## a Video reference guide
3+
4+
coming soon!

0 commit comments

Comments
 (0)