Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# syntax=docker/dockerfile:1

FROM golang:1.16-alpine

WORKDIR /app

COPY go.mod ./
COPY go.sum ./
RUN go get github.com/prometheus/client_golang/prometheus/promhttp
RUN go mod download

COPY *.go ./

RUN go build -o /go-app
EXPOSE 8080

CMD [ "/go-app" ]
60 changes: 43 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
# Devops Test

### Overview
This is an application that is a dummy webservice that returns the
last update time. The last updated time is cached in redis and
resets every 5 seconds. It has a single '/' endpoint. The redis
address is passed in through the environment.

NOTE: The following tasks should take no more than 1 hour total.

### Tasks
1. create Dockerfile for this application
2. create docker-compose.yaml to replicate a full running environment
so that a developer can run the entire application locally without having
to run any dependencies (i.e. redis) in a separate process.
3. explain how you would monitor this application in production. Please
write code to do the monitoring.

Please fork this repository and make a pull request with your changes.
### Preparation
1. Rename file .env and change IP address
2. Add IP from Vault or change in the file _prometheus/prometheus.yml_

### Run monitoring resources
1. We need to create infrastructure with to commands
Create __Prometheus__, __Prometheus gateway__, __Grafana__
~~~
# sudo docker-compose -f gocker-compose.yml up -d
~~~
Create __Go application__
~~~
# sudo docker-compose -f go-compose.yml up -d
~~~

2. Check installation
__Prometheus__ {IP address}:9090
__Prometheus gateway__ {IP address}:9091
__Grafana__ {IP address}:3000
__Go application__ {IP address}:8080

3. Check targets
Go to __Prometheus -> targets__
```State = UP``` - it is normal
For __Go application__ ```State = Down``` - also normal, if error ```strconv.ParseFloat: parsing "world:": invalid syntax```

![Targets](img/prom_targets.jpg)

4. Check __Prometheus pushgatway__
Sent from console of PC
~~~
echo -e 'job_successful 100.0\njob_failed 0.0' | curl --data-binary @- http://localhost:9091/metrics/job/go_app_job
~~~

5. Grafana

![Targets](img/Grafana_dash.jpg)


### P.S. What next?

We could proceed to add blackbox for the monitoring of the web (like Go application too)
Can add alertmanager and setup Jenkins for starting of jobs for a schedule. We could add at this job some variables which send to the pushgateway info about application status, failes and a start/end time of job
65 changes: 65 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
version: "3"
services:
mongodb:
image: mongo
ports:
- "27017:27017"
container_name: bookmark-mongodb
networks:
- monitornet
node:
image: node:8-alpine
networks:
- monitornet
volumes:
- ./web:/web
- /tmp:/tmp
grafana:
image: grafana/grafana:5.1.0
volumes:
- grafana_data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=adminpass
ports:
- "3000:3000"
container_name: bookmark-grafana
networks:
- monitornet
depends_on:
- prometheus
- prometheus-pushgateway
prometheus:
image: prom/prometheus
ports:
- "9090:9090"
command:
- --config.file=/etc/prometheus/prometheus.yml
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
container_name: bookmark-prometheus
networks:
- monitornet
prometheus-pushgateway:
image: prom/pushgateway
container_name: bookmark-pushgateway
expose:
- 9091
ports:
- "9091:9091"
# cadvisor:
# image: gcr.io/cadvisor/cadvisor:v0.43.0
# volumes:
# - '/:/rootfs:ro'
# - '/var/run:/var/run:rw'
# - '/sys:/sys:ro'
# - '/var/lib/docker/:/var/lib/docker:ro'
# ports:
# - "8080:8080"

volumes:
grafana_data:

networks:
monitornet:
driver: bridge
1 change: 1 addition & 0 deletions env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IP_HOST=172.26.232.6
19 changes: 19 additions & 0 deletions go-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "3"
services:
go_app:
build:
dockerfile: go_app/Dockerfile
context: .
networks:
- monitornet
expose:
- 8080
ports:
- "8080:8080"
container_name: bookmark-go-app
environment:
- APP_PUSH_GATEWAY=http://${IP_HOST}:9091

networks:
monitornet:
driver: bridge
17 changes: 17 additions & 0 deletions go_app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# syntax=docker/dockerfile:1

FROM golang:1.16-alpine

WORKDIR /app

COPY go_app/go.mod ./
COPY go_app/go.sum ./
RUN go get github.com/prometheus/client_golang/prometheus/promhttp
RUN go mod download

COPY go_app/*.go ./

RUN go build -o /go-app
EXPOSE 8080

CMD [ "/go-app" ]
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions main.go → go_app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func main() {

logger.Info("server started on port 8080")
log.Fatal(http.ListenAndServe(":8080", router))

}

func (s *server) indexHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
Expand Down
Binary file added img/Grafana_dash.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/prom_targets.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093


# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
- job_name: go-app
metrics_path: /
scheme: http
scrape_interval: 10s
static_configs:
- targets:
- 172.26.232.6:8080
labels:
group: 'applications'

- job_name: prometheus
metrics_path: /metrics
scrape_interval: 10s
static_configs:
- targets:
- 172.26.232.6:9090
- 172.26.232.6:9115

- job_name: promgateway
metrics_path: /metrics
scrape_interval: 10s
static_configs:
- targets:
- 172.26.232.6:9091

- job_name: blackbox
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- 172.26.232.6:8080
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 172.26.232.6:9115