Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/monitor #74

Merged
merged 18 commits into from
Mar 14, 2023
Merged
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
4 changes: 3 additions & 1 deletion .env.schema
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ SSH_KEY_NAME=
DIGITAL_OCEAN_TOKEN=
DOCKER_USERNAME=
POSTGRES_USERNAME=
POSTGRES_PASSWORD=
POSTGRES_PASSWORD=
GRAFANA_USERNAME=
GRAFANA_PASSWORD=
4 changes: 3 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ Vagrant.configure("2") do |config|
server.vm.hostname = "webserver"
server.vm.provision "shell", inline: 'echo "export DOCKER_USERNAME=' + "'" + ENV["DOCKER_USERNAME"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export POSTGRES_USERNAME=' + "'" + ENV["POSTGRES_USERNAME"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export POSTGRES_PASSWORD=' + "'" + ENV["POSTGRES_PASSWORD"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export POSTGRES_PASSWORD=' + "'" + ENV["POSTGRES_PASSWORD"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export GRAFANA_USERNAME=' + "'" + ENV["GRAFANA_USERNAME"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export GRAFANA_PASSWORD=' + "'" + ENV["GRAFANA_PASSWORD"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: <<-SHELL
sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
cd /vagrant
Expand Down
3 changes: 2 additions & 1 deletion controllers/messageController.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

func AddMessageHandler() gin.HandlerFunc {
return func(c *gin.Context) {
helpers.TweetsProcessed.Inc()
user, err := helpers.GetUserSession(c)
if err != nil {
c.AbortWithStatus(http.StatusUnauthorized)
Expand Down Expand Up @@ -113,7 +114,7 @@ func GetMessageUserHandler() gin.HandlerFunc {

func PostMessageUserHandler() gin.HandlerFunc {
return func(c *gin.Context) {

helpers.TweetsProcessed.Inc()
var postMessage simModels.MessageRequest

// bind JSON body to postMessage
Expand Down
56 changes: 56 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
container_name: minitwit
networks:
- database-network
- prometheus-network
ports:
- "8080:8080"
depends_on:
Expand All @@ -32,10 +33,65 @@ services:
volumes:
- postgres-db:/data/postgres

prometheus:
image: prom/prometheus:latest
container_name: prometheus
networks:
- prometheus-network
- monitoring
ports:
- "9090:9090"
volumes:
- prometheus-data:/prometheus
- type: bind
source: ./prometheus.yml
target: /prometheus/prometheus.yml
read_only: true
restart: unless-stopped
command:
- "--config.file=prometheus.yml"

grafana:
image: grafana/grafana-oss:latest
container_name: grafana
ports:
- "3000:3000"
environment:
GF_SECURITY_ADMIN_USER: ${GRAFANA_USERNAME}
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD}
volumes:
- grafana-data:/var/lib/grafana
- ./grafana/provisioning/:/etc/grafana/provisioning/
- ./grafana/dashboards:/var/lib/grafana/dashboards
restart: unless-stopped
node_exporter:
image: prom/node-exporter:latest
container_name: node-exporter
restart: unless-stopped
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- "--path.procfs=/host/proc"
- "--path.rootfs=/rootfs"
- "--path.sysfs=/host/sys"
- "--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)"
networks:
- monitoring

volumes:
postgres-db:
driver: local
prometheus-data:
driver: local
grafana-data:
driver: local

networks:
database-network:
name: database-network
prometheus-network:
name: prometheus-network
monitoring:
driver: bridge
10 changes: 9 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ go 1.20
require github.com/gin-gonic/gin v1.9.0

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.8.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1 // indirect
Expand All @@ -25,10 +28,14 @@ require (
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
Expand All @@ -43,6 +50,7 @@ require (
github.com/gin-contrib/sessions v0.0.5
github.com/jmoiron/sqlx v1.3.5
github.com/mattn/go-sqlite3 v2.0.3+incompatible
github.com/prometheus/client_golang v1.14.0
github.com/stretchr/testify v1.8.2
golang.org/x/crypto v0.7.0
gorm.io/driver/postgres v1.5.0
Expand Down
Loading