├── .gitignore ├── 1.2-instalacion-prometheus ├── .gitignore ├── docker-compose.yml ├── etc │ └── prometheus │ │ └── prometheus.yml └── var │ └── .gitkeep ├── 2.1-caad-exporter ├── .gitignore ├── docker-compose.yml ├── etc │ └── prometheus │ │ └── prometheus.yml └── var │ └── .gitkeep ├── 2.2-mysql-exporter ├── .gitignore ├── docker-compose.yml ├── etc │ └── prometheus │ │ └── prometheus.yml └── ops │ └── database │ └── schema.sql ├── 3.1-app-exporter-go ├── .gitignore ├── Dockerfile ├── app │ ├── go.mod │ ├── go.sum │ └── main.go ├── docker-compose.yml └── etc │ └── prometheus │ └── prometheus.yml ├── 3.2-app-exporter-java ├── .gitignore ├── Dockerfile ├── app │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ │ └── main │ │ └── java │ │ └── prometheusdemo │ │ └── App.java ├── docker-compose.yml └── etc │ └── prometheus │ └── prometheus.yml ├── 3.3-app-exporter-js ├── .gitignore ├── Dockerfile ├── app │ ├── .gitignore │ ├── package.json │ ├── src │ │ └── main.js │ └── yarn.lock ├── docker-compose.yml ├── etc │ └── prometheus │ │ └── prometheus.yml └── ops │ └── database │ └── schema.sql ├── 3.4-app-exporter-php ├── .gitignore ├── Dockerfile ├── app │ ├── composer.json │ ├── composer.lock │ └── index.php ├── docker-compose.yml └── etc │ └── prometheus │ └── prometheus.yml ├── 4.1-push-gateway ├── .gitignore ├── Dockerfile ├── app │ ├── go.mod │ ├── go.sum │ └── main.go ├── docker-compose.yml └── etc │ └── prometheus │ └── prometheus.yml ├── 4.2-remote-write-cortex ├── .gitignore ├── Dockerfile ├── app │ ├── go.mod │ ├── go.sum │ └── main.go ├── docker-compose.yml └── etc │ ├── cortex │ └── single-process-config.yaml │ └── prometheus │ └── prometheus.yml ├── 4.3-promql ├── .gitignore ├── Dockerfile ├── app │ ├── go.mod │ ├── go.sum │ └── main.go ├── docker-compose.yml └── etc │ ├── cortex │ └── single-process-config.yaml │ └── prometheus │ └── prometheus.yml ├── 5.1-grafana ├── .gitignore ├── Dockerfile ├── app │ ├── go.mod │ ├── go.sum │ └── main.go ├── docker-compose.yml └── etc │ ├── grafana │ └── provisioning │ │ └── datasource.yml │ └── prometheus │ └── prometheus.yml ├── 5.2-grafana-dashboard ├── .gitignore ├── Dockerfile ├── app │ ├── go.mod │ ├── go.sum │ └── main.go ├── docker-compose.yml └── etc │ ├── grafana │ └── provisioning │ │ ├── dashboards │ │ ├── all.yml │ │ └── codely.json │ │ └── datasources │ │ └── datasource.yml │ └── prometheus │ └── prometheus.yml ├── 6.3-alert-manager ├── .gitignore ├── Dockerfile ├── app │ ├── go.mod │ ├── go.sum │ └── main.go ├── docker-compose.yml └── etc │ └── prometheus │ ├── alertmanager │ ├── config.yml │ └── rules.yml │ └── prometheus.yml ├── 7.1-prometheus-k8s ├── Makefile ├── app │ ├── .helmignore │ ├── Chart.yaml │ ├── templates │ │ ├── NOTES.txt │ │ ├── _helpers.tpl │ │ ├── deployment.yaml │ │ ├── ingress.yaml │ │ ├── service.yaml │ │ ├── serviceaccount.yaml │ │ └── tests │ │ │ └── test-connection.yaml │ └── values.yaml └── prometheus │ └── extraScrapeConfigs.yaml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /1.2-instalacion-prometheus/.gitignore: -------------------------------------------------------------------------------- 1 | var -------------------------------------------------------------------------------- /1.2-instalacion-prometheus/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | 4 | prometheus: 5 | image: prom/prometheus:v2.19.0 6 | volumes: 7 | - ./etc/prometheus/:/etc/prometheus/ 8 | - ./var/prometheus/prometheus_data:/prometheus 9 | command: 10 | - '--config.file=/etc/prometheus/prometheus.yml' 11 | - '--storage.tsdb.path=/prometheus' 12 | - '--web.console.libraries=/usr/share/prometheus/console_libraries' 13 | - '--web.console.templates=/usr/share/prometheus/consoles' 14 | ports: 15 | - 9090:9090 16 | -------------------------------------------------------------------------------- /1.2-instalacion-prometheus/etc/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | scrape_configs: 2 | 3 | - job_name: 'prometheus' 4 | scrape_interval: 5s 5 | static_configs: 6 | - targets: ['localhost:9090'] 7 | labels: 8 | env: local 9 | region: us-east-1 10 | -------------------------------------------------------------------------------- /1.2-instalacion-prometheus/var/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodelyTV/prometheus-course/51198162c55ebaf595c61dd0d2fd18647615f528/1.2-instalacion-prometheus/var/.gitkeep -------------------------------------------------------------------------------- /2.1-caad-exporter/.gitignore: -------------------------------------------------------------------------------- 1 | var -------------------------------------------------------------------------------- /2.1-caad-exporter/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | 4 | prometheus: 5 | image: prom/prometheus:v2.19.0 6 | volumes: 7 | - ./etc/prometheus/:/etc/prometheus/ 8 | - ./var/prometheus/prometheus_data:/prometheus 9 | command: 10 | - '--config.file=/etc/prometheus/prometheus.yml' 11 | - '--storage.tsdb.path=/prometheus' 12 | - '--web.console.libraries=/usr/share/prometheus/console_libraries' 13 | - '--web.console.templates=/usr/share/prometheus/consoles' 14 | ports: 15 | - 9090:9090 16 | 17 | cadvisor: 18 | image: google/cadvisor 19 | volumes: 20 | - /:/rootfs:ro 21 | - /var/run:/var/run:rw 22 | - /sys:/sys:ro 23 | - /var/lib/docker/:/var/lib/docker:ro 24 | ports: 25 | - 8080:8080 26 | -------------------------------------------------------------------------------- /2.1-caad-exporter/etc/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | scrape_configs: 2 | 3 | - job_name: 'prometheus' 4 | scrape_interval: 5s 5 | static_configs: 6 | - targets: ['localhost:9090'] 7 | 8 | - job_name: 'cadvisor' 9 | scrape_interval: 5s 10 | static_configs: 11 | - targets: ['cadvisor:8080'] -------------------------------------------------------------------------------- /2.1-caad-exporter/var/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodelyTV/prometheus-course/51198162c55ebaf595c61dd0d2fd18647615f528/2.1-caad-exporter/var/.gitkeep -------------------------------------------------------------------------------- /2.2-mysql-exporter/.gitignore: -------------------------------------------------------------------------------- 1 | var -------------------------------------------------------------------------------- /2.2-mysql-exporter/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | 4 | prometheus: 5 | image: prom/prometheus:v2.19.0 6 | volumes: 7 | - ./etc/prometheus/:/etc/prometheus/ 8 | - ./var/prometheus/prometheus_data:/prometheus 9 | command: 10 | - '--config.file=/etc/prometheus/prometheus.yml' 11 | - '--storage.tsdb.path=/prometheus' 12 | - '--web.console.libraries=/usr/share/prometheus/console_libraries' 13 | - '--web.console.templates=/usr/share/prometheus/consoles' 14 | ports: 15 | - 9090:9090 16 | 17 | mysql: 18 | image: mysql:5.7 19 | restart: always 20 | environment: 21 | MYSQL_DATABASE: 'db' 22 | MYSQL_USER: 'user' 23 | MYSQL_PASSWORD: 'password' 24 | MYSQL_ROOT_PASSWORD: 'password' 25 | ports: 26 | - '3306:3306' 27 | volumes: 28 | - './var/mysql:/var/lib/mysql' 29 | - './ops/database:/docker-entrypoint-initdb.d' 30 | - './var/log/mysql:/var/log/mysql' 31 | 32 | mysqld_exporter: 33 | image: prom/mysqld-exporter 34 | user: root 35 | ports: 36 | - '9104:9104' 37 | links: 38 | - mysql 39 | environment: 40 | - "DATA_SOURCE_NAME=root:password@(mysql:3306)/db" 41 | - "collect.info_schema.tablestats=true" 42 | - "collect.info_schema.userstats=true" 43 | - "collect.info_schema.query_response_time=true" 44 | - "collect.auto_increment.columns=true" 45 | - "collect.perf_schema.tableiowaits=true" 46 | - "collect.perf_schema.tablelocks=true" 47 | depends_on: 48 | - mysql -------------------------------------------------------------------------------- /2.2-mysql-exporter/etc/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | scrape_configs: 2 | 3 | - job_name: 'prometheus' 4 | scrape_interval: 5s 5 | static_configs: 6 | - targets: ['localhost:9090'] 7 | 8 | - job_name: 'mysqld_exporter' 9 | scrape_interval: 5s 10 | static_configs: 11 | - targets: ['mysqld_exporter:9104'] -------------------------------------------------------------------------------- /2.2-mysql-exporter/ops/database/schema.sql: -------------------------------------------------------------------------------- 1 | CREATE USER 'mysqld_exporter'@'localhost' IDENTIFIED BY 'password' WITH MAX_USER_CONNECTIONS 3; 2 | 3 | CREATE TABLE IF NOT EXISTS `users` ( 4 | `id` INT NOT NULL AUTO_INCREMENT, 5 | `name` VARCHAR(255), 6 | `email` VARCHAR(255), 7 | PRIMARY KEY (`id`) 8 | ); -------------------------------------------------------------------------------- /3.1-app-exporter-go/.gitignore: -------------------------------------------------------------------------------- 1 | var 2 | main 3 | -------------------------------------------------------------------------------- /3.1-app-exporter-go/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:latest AS builder 2 | ADD ./app /app 3 | WORKDIR /app 4 | RUN go mod download 5 | RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o /main . 6 | 7 | FROM alpine:latest 8 | RUN apk --no-cache add ca-certificates 9 | COPY --from=builder /main ./ 10 | RUN chmod +x ./main 11 | ENTRYPOINT ["./main"] 12 | EXPOSE 80 -------------------------------------------------------------------------------- /3.1-app-exporter-go/app/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rubencougil/geekshubs/prometheus/app 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 7 | github.com/modern-go/reflect2 v1.0.1 // indirect 8 | github.com/prometheus/client_golang v1.2.1 // indirect 9 | ) 10 | -------------------------------------------------------------------------------- /3.1-app-exporter-go/app/go.sum: -------------------------------------------------------------------------------- 1 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 2 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 3 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 4 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 5 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 6 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 7 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 8 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 9 | github.com/cespare/xxhash/v2 v2.1.0 h1:yTUvW7Vhb89inJ+8irsUqiWjh8iT6sQPZiQzI6ReGkA= 10 | github.com/cespare/xxhash/v2 v2.1.0/go.mod h1:dgIUBU3pDso/gPgZ1osOZ0iQf77oPR28Tjxl5dIMyVM= 11 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 13 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 14 | github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 15 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 16 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 17 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 18 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 19 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 20 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 21 | github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= 22 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 23 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 24 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 25 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 26 | github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 27 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 28 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 29 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 30 | github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= 31 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 32 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 33 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 34 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 35 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 36 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 37 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 38 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 39 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 40 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 41 | github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= 42 | github.com/prometheus/client_golang v1.2.1 h1:JnMpQc6ppsNgw9QPAGF6Dod479itz7lvlsMzzNayLOI= 43 | github.com/prometheus/client_golang v1.2.1/go.mod h1:XMU6Z2MjaRKVu/dC1qupJI9SiNkDYzz3xecMgSW/F+U= 44 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 45 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 46 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= 47 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 48 | github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 49 | github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY= 50 | github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= 51 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 52 | github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 53 | github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= 54 | github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= 55 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 56 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 57 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 58 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 59 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 60 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 61 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 62 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 63 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 64 | golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 65 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 66 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 67 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 68 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 69 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 70 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 71 | golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 72 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 73 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 74 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 75 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 76 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 77 | -------------------------------------------------------------------------------- /3.1-app-exporter-go/app/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "github.com/prometheus/client_golang/prometheus" 6 | "github.com/prometheus/client_golang/prometheus/promauto" 7 | "log" 8 | "math/rand" 9 | "net/http" 10 | "time" 11 | 12 | "github.com/prometheus/client_golang/prometheus/promhttp" 13 | ) 14 | 15 | var addr = flag.String("listen-address", ":8081", "The address to listen on for HTTP requests.") 16 | 17 | var ( 18 | c = promauto.NewCounter(prometheus.CounterOpts{ 19 | Name: "codely_app_sample_metric", 20 | Help: "Sample counter for Codely course", 21 | }) 22 | 23 | h = promauto.NewHistogram(prometheus.HistogramOpts{ 24 | Name: "codely_app_sample_histogram", 25 | Help: "Sample histogram for Codely course", 26 | }) 27 | 28 | d = promauto.NewCounterVec(prometheus.CounterOpts{ 29 | Name: "codely_app_sample_devices", 30 | Help: "Sample counter with devices label for Codely course"}, []string{"device"}) 31 | ) 32 | 33 | func main() { 34 | 35 | rand.Seed(time.Now().UnixNano()) 36 | 37 | go func() { 38 | for { 39 | rand.Seed(time.Now().UnixNano()) 40 | h.Observe(float64(rand.Intn(100-0+1) + 0)) 41 | d.With(prometheus.Labels{"device":"/dev/sda"}).Inc() 42 | c.Inc() 43 | time.Sleep(1 * time.Second) 44 | } 45 | }() 46 | 47 | http.Handle("/metrics", promhttp.Handler()) 48 | log.Fatal(http.ListenAndServe(*addr, nil)) 49 | } 50 | -------------------------------------------------------------------------------- /3.1-app-exporter-go/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | 4 | prometheus: 5 | image: prom/prometheus:v2.19.0 6 | volumes: 7 | - ./etc/prometheus/:/etc/prometheus/ 8 | - ./var/prometheus/prometheus_data:/prometheus 9 | command: 10 | - '--config.file=/etc/prometheus/prometheus.yml' 11 | - '--storage.tsdb.path=/prometheus' 12 | - '--web.console.libraries=/usr/share/prometheus/console_libraries' 13 | - '--web.console.templates=/usr/share/prometheus/consoles' 14 | ports: 15 | - 9090:9090 16 | 17 | app: 18 | build: . 19 | ports: 20 | - 8081:8081 21 | depends_on: 22 | - prometheus 23 | -------------------------------------------------------------------------------- /3.1-app-exporter-go/etc/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | scrape_configs: 2 | 3 | - job_name: 'prometheus' 4 | scrape_interval: 5s 5 | static_configs: 6 | - targets: ['localhost:9090'] 7 | 8 | - job_name: 'codely' 9 | scrape_interval: 5s 10 | static_configs: 11 | - targets: ['app:8081'] 12 | -------------------------------------------------------------------------------- /3.2-app-exporter-java/.gitignore: -------------------------------------------------------------------------------- 1 | var 2 | .gradle 3 | build 4 | -------------------------------------------------------------------------------- /3.2-app-exporter-java/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gradle:latest 2 | 3 | RUN mkdir /app 4 | WORKDIR /app 5 | COPY ./app/ /app/ 6 | ENTRYPOINT ["gradle", "run"] 7 | 8 | EXPOSE 8081 8082 9 | -------------------------------------------------------------------------------- /3.2-app-exporter-java/app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'application' 4 | } 5 | 6 | repositories { 7 | jcenter() 8 | } 9 | 10 | dependencies { 11 | implementation 'com.google.guava:guava:29.0-jre' 12 | implementation 'io.prometheus:simpleclient:0.9.0' 13 | implementation 'io.prometheus:simpleclient_hotspot:0.9.0' 14 | implementation 'io.prometheus:simpleclient_httpserver:0.9.0' 15 | implementation 'io.prometheus:simpleclient_pushgateway:0.9.0' 16 | } 17 | 18 | application { 19 | mainClassName = 'prometheusdemo.App' 20 | } 21 | -------------------------------------------------------------------------------- /3.2-app-exporter-java/app/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodelyTV/prometheus-course/51198162c55ebaf595c61dd0d2fd18647615f528/3.2-app-exporter-java/app/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /3.2-app-exporter-java/app/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /3.2-app-exporter-java/app/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /3.2-app-exporter-java/app/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | 88 | @rem Execute Gradle 89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 90 | 91 | :end 92 | @rem End local scope for the variables with windows NT shell 93 | if "%ERRORLEVEL%"=="0" goto mainEnd 94 | 95 | :fail 96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 97 | rem the _cmd.exe /c_ return code! 98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 99 | exit /b 1 100 | 101 | :mainEnd 102 | if "%OS%"=="Windows_NT" endlocal 103 | 104 | :omega 105 | -------------------------------------------------------------------------------- /3.2-app-exporter-java/app/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'prometheusdemo' 2 | -------------------------------------------------------------------------------- /3.2-app-exporter-java/app/src/main/java/prometheusdemo/App.java: -------------------------------------------------------------------------------- 1 | package prometheusdemo; 2 | 3 | import com.sun.net.httpserver.HttpExchange; 4 | import com.sun.net.httpserver.HttpHandler; 5 | import com.sun.net.httpserver.HttpServer; 6 | import io.prometheus.client.Counter; 7 | import io.prometheus.client.Gauge; 8 | import io.prometheus.client.exporter.HTTPServer; 9 | 10 | import java.io.IOException; 11 | import java.net.InetSocketAddress; 12 | import java.util.Timer; 13 | import java.util.TimerTask; 14 | 15 | public class App { 16 | static final Counter counter = Counter.build() 17 | .name("test_counter") 18 | .labelNames("code") 19 | .help("Example of a counter.") 20 | .register(); 21 | static final Gauge gauge = Gauge.build() 22 | .name("test_gauge") 23 | .help("Example of a gauge") 24 | .labelNames("method", "code") 25 | .register(); 26 | 27 | public static void main(String[] args) throws IOException { 28 | scheduleIncrements(); 29 | 30 | HttpServer server = HttpServer.create(new InetSocketAddress(8082), 0); 31 | server.createContext("/send", new SendMetricsHandler()); 32 | server.setExecutor(null); 33 | server.start(); 34 | 35 | new HTTPServer(8081); 36 | } 37 | 38 | private static void scheduleIncrements() { 39 | new Timer().scheduleAtFixedRate(new TimerTask() { 40 | @Override 41 | public void run() { 42 | counter.labels("code").inc(200); 43 | } 44 | }, 1000, 1000); 45 | 46 | new Timer().scheduleAtFixedRate(new TimerTask() { 47 | @Override 48 | public void run() { 49 | counter.labels("code").inc(400); 50 | } 51 | }, 1000, 4000); 52 | } 53 | 54 | static class SendMetricsHandler implements HttpHandler { 55 | @Override 56 | public void handle(HttpExchange http) throws IOException { 57 | gauge.labels("get", "200").set(Math.random()); 58 | gauge.labels("post", "300").inc(); 59 | http.sendResponseHeaders(201, 0); 60 | http.getResponseBody().close(); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /3.2-app-exporter-java/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | 4 | prometheus: 5 | image: prom/prometheus:v2.1.0 6 | volumes: 7 | - ./etc/prometheus/:/etc/prometheus/ 8 | - ./var/prometheus/prometheus_data:/prometheus 9 | command: 10 | - '--config.file=/etc/prometheus/prometheus.yml' 11 | - '--storage.tsdb.path=/prometheus' 12 | - '--web.console.libraries=/usr/share/prometheus/console_libraries' 13 | - '--web.console.templates=/usr/share/prometheus/consoles' 14 | ports: 15 | - 9090:9090 16 | 17 | app: 18 | build: . 19 | ports: 20 | - 8081:8081 21 | - 8082:8082 22 | depends_on: 23 | - prometheus 24 | -------------------------------------------------------------------------------- /3.2-app-exporter-java/etc/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | evaluation_interval: 15s 4 | external_labels: 5 | monitor: 'codely-app' 6 | 7 | scrape_configs: 8 | 9 | - job_name: 'prometheus' 10 | scrape_interval: 5s 11 | static_configs: 12 | - targets: ['localhost:9090'] 13 | 14 | - job_name: 'codely' 15 | scrape_interval: 5s 16 | static_configs: 17 | - targets: ['app:8081'] 18 | -------------------------------------------------------------------------------- /3.3-app-exporter-js/.gitignore: -------------------------------------------------------------------------------- 1 | var 2 | main 3 | -------------------------------------------------------------------------------- /3.3-app-exporter-js/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:latest 2 | 3 | RUN mkdir /app 4 | WORKDIR /app 5 | 6 | ENV PATH /app/node_modules/.bin:$PATH 7 | ADD ./app/package.json ./app/yarn.lock /app/ 8 | COPY ./app/ /app/ 9 | 10 | RUN yarn install 11 | ENTRYPOINT ["node", "src/main.js"] 12 | 13 | EXPOSE 8081 14 | -------------------------------------------------------------------------------- /3.3-app-exporter-js/app/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /3.3-app-exporter-js/app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "codely-monitoring", 3 | "dependencies": { 4 | "express": "^4.17.1", 5 | "prom-client": "^11.5.3" 6 | } 7 | } -------------------------------------------------------------------------------- /3.3-app-exporter-js/app/src/main.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const client = require('prom-client'); 3 | const server = express(); 4 | 5 | const counter = require('prom-client').Counter; 6 | const gauge = require('prom-client').Gauge; 7 | 8 | const c = new counter({ 9 | name: 'test_counter', 10 | help: 'Example of a counter', 11 | labelNames: ['code'] 12 | }); 13 | const g = new gauge({ 14 | name: 'test_gauge', 15 | help: 'Example of a gauge', 16 | labelNames: ['method', 'code'] 17 | }); 18 | 19 | setInterval(() => { 20 | c.inc(({ code: 200 })) 21 | }, 1000); 22 | 23 | setInterval(() => { 24 | c.inc(({ code: 400 })) 25 | }, 4000); 26 | 27 | server.get('/send', function (req, res) { 28 | g.set({ method: 'get', code: 200 }, Math.random()); 29 | g.set(Math.random()); 30 | g.labels('post', '300').inc(); 31 | res.end(); 32 | }); 33 | 34 | server.get('/metrics', function (req, res) { 35 | res.end(client.register.metrics()); 36 | }); 37 | 38 | server.listen(8081, '0.0.0.0'); -------------------------------------------------------------------------------- /3.3-app-exporter-js/app/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | accepts@~1.3.7: 6 | version "1.3.7" 7 | resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd" 8 | integrity sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA== 9 | dependencies: 10 | mime-types "~2.1.24" 11 | negotiator "0.6.2" 12 | 13 | array-flatten@1.1.1: 14 | version "1.1.1" 15 | resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2" 16 | integrity sha1-ml9pkFGx5wczKPKgCJaLZOopVdI= 17 | 18 | bintrees@1.0.1: 19 | version "1.0.1" 20 | resolved "https://registry.yarnpkg.com/bintrees/-/bintrees-1.0.1.tgz#0e655c9b9c2435eaab68bf4027226d2b55a34524" 21 | integrity sha1-DmVcm5wkNeqraL9AJyJtK1WjRSQ= 22 | 23 | body-parser@1.19.0: 24 | version "1.19.0" 25 | resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.19.0.tgz#96b2709e57c9c4e09a6fd66a8fd979844f69f08a" 26 | integrity sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw== 27 | dependencies: 28 | bytes "3.1.0" 29 | content-type "~1.0.4" 30 | debug "2.6.9" 31 | depd "~1.1.2" 32 | http-errors "1.7.2" 33 | iconv-lite "0.4.24" 34 | on-finished "~2.3.0" 35 | qs "6.7.0" 36 | raw-body "2.4.0" 37 | type-is "~1.6.17" 38 | 39 | bytes@3.1.0: 40 | version "3.1.0" 41 | resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6" 42 | integrity sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg== 43 | 44 | content-disposition@0.5.3: 45 | version "0.5.3" 46 | resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.3.tgz#e130caf7e7279087c5616c2007d0485698984fbd" 47 | integrity sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g== 48 | dependencies: 49 | safe-buffer "5.1.2" 50 | 51 | content-type@~1.0.4: 52 | version "1.0.4" 53 | resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b" 54 | integrity sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA== 55 | 56 | cookie-signature@1.0.6: 57 | version "1.0.6" 58 | resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c" 59 | integrity sha1-4wOogrNCzD7oylE6eZmXNNqzriw= 60 | 61 | cookie@0.4.0: 62 | version "0.4.0" 63 | resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.0.tgz#beb437e7022b3b6d49019d088665303ebe9c14ba" 64 | integrity sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg== 65 | 66 | debug@2.6.9: 67 | version "2.6.9" 68 | resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" 69 | integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA== 70 | dependencies: 71 | ms "2.0.0" 72 | 73 | depd@~1.1.2: 74 | version "1.1.2" 75 | resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" 76 | integrity sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak= 77 | 78 | destroy@~1.0.4: 79 | version "1.0.4" 80 | resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80" 81 | integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA= 82 | 83 | ee-first@1.1.1: 84 | version "1.1.1" 85 | resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" 86 | integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= 87 | 88 | encodeurl@~1.0.2: 89 | version "1.0.2" 90 | resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" 91 | integrity sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k= 92 | 93 | escape-html@~1.0.3: 94 | version "1.0.3" 95 | resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" 96 | integrity sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg= 97 | 98 | etag@~1.8.1: 99 | version "1.8.1" 100 | resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887" 101 | integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc= 102 | 103 | express@^4.17.1: 104 | version "4.17.1" 105 | resolved "https://registry.yarnpkg.com/express/-/express-4.17.1.tgz#4491fc38605cf51f8629d39c2b5d026f98a4c134" 106 | integrity sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g== 107 | dependencies: 108 | accepts "~1.3.7" 109 | array-flatten "1.1.1" 110 | body-parser "1.19.0" 111 | content-disposition "0.5.3" 112 | content-type "~1.0.4" 113 | cookie "0.4.0" 114 | cookie-signature "1.0.6" 115 | debug "2.6.9" 116 | depd "~1.1.2" 117 | encodeurl "~1.0.2" 118 | escape-html "~1.0.3" 119 | etag "~1.8.1" 120 | finalhandler "~1.1.2" 121 | fresh "0.5.2" 122 | merge-descriptors "1.0.1" 123 | methods "~1.1.2" 124 | on-finished "~2.3.0" 125 | parseurl "~1.3.3" 126 | path-to-regexp "0.1.7" 127 | proxy-addr "~2.0.5" 128 | qs "6.7.0" 129 | range-parser "~1.2.1" 130 | safe-buffer "5.1.2" 131 | send "0.17.1" 132 | serve-static "1.14.1" 133 | setprototypeof "1.1.1" 134 | statuses "~1.5.0" 135 | type-is "~1.6.18" 136 | utils-merge "1.0.1" 137 | vary "~1.1.2" 138 | 139 | finalhandler@~1.1.2: 140 | version "1.1.2" 141 | resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.1.2.tgz#b7e7d000ffd11938d0fdb053506f6ebabe9f587d" 142 | integrity sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA== 143 | dependencies: 144 | debug "2.6.9" 145 | encodeurl "~1.0.2" 146 | escape-html "~1.0.3" 147 | on-finished "~2.3.0" 148 | parseurl "~1.3.3" 149 | statuses "~1.5.0" 150 | unpipe "~1.0.0" 151 | 152 | forwarded@~0.1.2: 153 | version "0.1.2" 154 | resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84" 155 | integrity sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ= 156 | 157 | fresh@0.5.2: 158 | version "0.5.2" 159 | resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7" 160 | integrity sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac= 161 | 162 | http-errors@1.7.2: 163 | version "1.7.2" 164 | resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.7.2.tgz#4f5029cf13239f31036e5b2e55292bcfbcc85c8f" 165 | integrity sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg== 166 | dependencies: 167 | depd "~1.1.2" 168 | inherits "2.0.3" 169 | setprototypeof "1.1.1" 170 | statuses ">= 1.5.0 < 2" 171 | toidentifier "1.0.0" 172 | 173 | http-errors@~1.7.2: 174 | version "1.7.3" 175 | resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.7.3.tgz#6c619e4f9c60308c38519498c14fbb10aacebb06" 176 | integrity sha512-ZTTX0MWrsQ2ZAhA1cejAwDLycFsd7I7nVtnkT3Ol0aqodaKW+0CTZDQ1uBv5whptCnc8e8HeRRJxRs0kmm/Qfw== 177 | dependencies: 178 | depd "~1.1.2" 179 | inherits "2.0.4" 180 | setprototypeof "1.1.1" 181 | statuses ">= 1.5.0 < 2" 182 | toidentifier "1.0.0" 183 | 184 | iconv-lite@0.4.24: 185 | version "0.4.24" 186 | resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" 187 | integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== 188 | dependencies: 189 | safer-buffer ">= 2.1.2 < 3" 190 | 191 | inherits@2.0.3: 192 | version "2.0.3" 193 | resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" 194 | integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4= 195 | 196 | inherits@2.0.4: 197 | version "2.0.4" 198 | resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" 199 | integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== 200 | 201 | ipaddr.js@1.9.0: 202 | version "1.9.0" 203 | resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.9.0.tgz#37df74e430a0e47550fe54a2defe30d8acd95f65" 204 | integrity sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA== 205 | 206 | media-typer@0.3.0: 207 | version "0.3.0" 208 | resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" 209 | integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g= 210 | 211 | merge-descriptors@1.0.1: 212 | version "1.0.1" 213 | resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61" 214 | integrity sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E= 215 | 216 | methods@~1.1.2: 217 | version "1.1.2" 218 | resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" 219 | integrity sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4= 220 | 221 | mime-db@1.42.0: 222 | version "1.42.0" 223 | resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.42.0.tgz#3e252907b4c7adb906597b4b65636272cf9e7bac" 224 | integrity sha512-UbfJCR4UAVRNgMpfImz05smAXK7+c+ZntjaA26ANtkXLlOe947Aag5zdIcKQULAiF9Cq4WxBi9jUs5zkA84bYQ== 225 | 226 | mime-types@~2.1.24: 227 | version "2.1.25" 228 | resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.25.tgz#39772d46621f93e2a80a856c53b86a62156a6437" 229 | integrity sha512-5KhStqB5xpTAeGqKBAMgwaYMnQik7teQN4IAzC7npDv6kzeU6prfkR67bc87J1kWMPGkoaZSq1npmexMgkmEVg== 230 | dependencies: 231 | mime-db "1.42.0" 232 | 233 | mime@1.6.0: 234 | version "1.6.0" 235 | resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" 236 | integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== 237 | 238 | ms@2.0.0: 239 | version "2.0.0" 240 | resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" 241 | integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g= 242 | 243 | ms@2.1.1: 244 | version "2.1.1" 245 | resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a" 246 | integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg== 247 | 248 | negotiator@0.6.2: 249 | version "0.6.2" 250 | resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb" 251 | integrity sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw== 252 | 253 | on-finished@~2.3.0: 254 | version "2.3.0" 255 | resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947" 256 | integrity sha1-IPEzZIGwg811M3mSoWlxqi2QaUc= 257 | dependencies: 258 | ee-first "1.1.1" 259 | 260 | parseurl@~1.3.3: 261 | version "1.3.3" 262 | resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.3.tgz#9da19e7bee8d12dff0513ed5b76957793bc2e8d4" 263 | integrity sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ== 264 | 265 | path-to-regexp@0.1.7: 266 | version "0.1.7" 267 | resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" 268 | integrity sha1-32BBeABfUi8V60SQ5yR6G/qmf4w= 269 | 270 | prom-client@^11.5.3: 271 | version "11.5.3" 272 | resolved "https://registry.yarnpkg.com/prom-client/-/prom-client-11.5.3.tgz#5fedfce1083bac6c2b223738e966d0e1643756f8" 273 | integrity sha512-iz22FmTbtkyL2vt0MdDFY+kWof+S9UB/NACxSn2aJcewtw+EERsen0urSkZ2WrHseNdydsvcxCTAnPcSMZZv4Q== 274 | dependencies: 275 | tdigest "^0.1.1" 276 | 277 | proxy-addr@~2.0.5: 278 | version "2.0.5" 279 | resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.5.tgz#34cbd64a2d81f4b1fd21e76f9f06c8a45299ee34" 280 | integrity sha512-t/7RxHXPH6cJtP0pRG6smSr9QJidhB+3kXu0KgXnbGYMgzEnUxRQ4/LDdfOwZEMyIh3/xHb8PX3t+lfL9z+YVQ== 281 | dependencies: 282 | forwarded "~0.1.2" 283 | ipaddr.js "1.9.0" 284 | 285 | qs@6.7.0: 286 | version "6.7.0" 287 | resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc" 288 | integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ== 289 | 290 | range-parser@~1.2.1: 291 | version "1.2.1" 292 | resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031" 293 | integrity sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg== 294 | 295 | raw-body@2.4.0: 296 | version "2.4.0" 297 | resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.4.0.tgz#a1ce6fb9c9bc356ca52e89256ab59059e13d0332" 298 | integrity sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q== 299 | dependencies: 300 | bytes "3.1.0" 301 | http-errors "1.7.2" 302 | iconv-lite "0.4.24" 303 | unpipe "1.0.0" 304 | 305 | safe-buffer@5.1.2: 306 | version "5.1.2" 307 | resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" 308 | integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== 309 | 310 | "safer-buffer@>= 2.1.2 < 3": 311 | version "2.1.2" 312 | resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" 313 | integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== 314 | 315 | send@0.17.1: 316 | version "0.17.1" 317 | resolved "https://registry.yarnpkg.com/send/-/send-0.17.1.tgz#c1d8b059f7900f7466dd4938bdc44e11ddb376c8" 318 | integrity sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg== 319 | dependencies: 320 | debug "2.6.9" 321 | depd "~1.1.2" 322 | destroy "~1.0.4" 323 | encodeurl "~1.0.2" 324 | escape-html "~1.0.3" 325 | etag "~1.8.1" 326 | fresh "0.5.2" 327 | http-errors "~1.7.2" 328 | mime "1.6.0" 329 | ms "2.1.1" 330 | on-finished "~2.3.0" 331 | range-parser "~1.2.1" 332 | statuses "~1.5.0" 333 | 334 | serve-static@1.14.1: 335 | version "1.14.1" 336 | resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.14.1.tgz#666e636dc4f010f7ef29970a88a674320898b2f9" 337 | integrity sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg== 338 | dependencies: 339 | encodeurl "~1.0.2" 340 | escape-html "~1.0.3" 341 | parseurl "~1.3.3" 342 | send "0.17.1" 343 | 344 | setprototypeof@1.1.1: 345 | version "1.1.1" 346 | resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.1.tgz#7e95acb24aa92f5885e0abef5ba131330d4ae683" 347 | integrity sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw== 348 | 349 | "statuses@>= 1.5.0 < 2", statuses@~1.5.0: 350 | version "1.5.0" 351 | resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" 352 | integrity sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow= 353 | 354 | tdigest@^0.1.1: 355 | version "0.1.1" 356 | resolved "https://registry.yarnpkg.com/tdigest/-/tdigest-0.1.1.tgz#2e3cb2c39ea449e55d1e6cd91117accca4588021" 357 | integrity sha1-Ljyyw56kSeVdHmzZEReszKRYgCE= 358 | dependencies: 359 | bintrees "1.0.1" 360 | 361 | toidentifier@1.0.0: 362 | version "1.0.0" 363 | resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553" 364 | integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw== 365 | 366 | type-is@~1.6.17, type-is@~1.6.18: 367 | version "1.6.18" 368 | resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131" 369 | integrity sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g== 370 | dependencies: 371 | media-typer "0.3.0" 372 | mime-types "~2.1.24" 373 | 374 | unpipe@1.0.0, unpipe@~1.0.0: 375 | version "1.0.0" 376 | resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" 377 | integrity sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw= 378 | 379 | utils-merge@1.0.1: 380 | version "1.0.1" 381 | resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" 382 | integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM= 383 | 384 | vary@~1.1.2: 385 | version "1.1.2" 386 | resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" 387 | integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw= 388 | -------------------------------------------------------------------------------- /3.3-app-exporter-js/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | 4 | prometheus: 5 | image: prom/prometheus:v2.19.0 6 | volumes: 7 | - ./etc/prometheus/:/etc/prometheus/ 8 | - ./var/prometheus/prometheus_data:/prometheus 9 | command: 10 | - '--config.file=/etc/prometheus/prometheus.yml' 11 | - '--storage.tsdb.path=/prometheus' 12 | - '--web.console.libraries=/usr/share/prometheus/console_libraries' 13 | - '--web.console.templates=/usr/share/prometheus/consoles' 14 | ports: 15 | - 9090:9090 16 | 17 | app: 18 | build: . 19 | ports: 20 | - 8081:8081 21 | depends_on: 22 | - prometheus 23 | -------------------------------------------------------------------------------- /3.3-app-exporter-js/etc/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | evaluation_interval: 15s 4 | external_labels: 5 | monitor: 'codely-app' 6 | 7 | scrape_configs: 8 | 9 | - job_name: 'prometheus' 10 | scrape_interval: 5s 11 | static_configs: 12 | - targets: ['localhost:9090'] 13 | 14 | - job_name: 'codely' 15 | scrape_interval: 5s 16 | static_configs: 17 | - targets: ['app:8081'] 18 | -------------------------------------------------------------------------------- /3.3-app-exporter-js/ops/database/schema.sql: -------------------------------------------------------------------------------- 1 | CREATE USER 'mysqld_exporter'@'localhost' IDENTIFIED BY 'password' WITH MAX_USER_CONNECTIONS 3; 2 | 3 | CREATE TABLE IF NOT EXISTS `users` ( 4 | `id` INT NOT NULL AUTO_INCREMENT, 5 | `name` VARCHAR(255), 6 | `email` VARCHAR(255), 7 | PRIMARY KEY (`id`) 8 | ); -------------------------------------------------------------------------------- /3.4-app-exporter-php/.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | storage 3 | -------------------------------------------------------------------------------- /3.4-app-exporter-php/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.3 2 | 3 | RUN pecl install apcu-5.1.18 && docker-php-ext-enable apcu 4 | 5 | RUN mkdir /app 6 | WORKDIR /app 7 | 8 | ENV PATH /app/node_modules/.bin:$PATH 9 | ADD ./app/package.json ./app/yarn.lock /app/ 10 | COPY ./app/ /app/ 11 | 12 | RUN composer install 13 | ENTRYPOINT ["php", "-S", "0.0.0.0:8081", "index.php"] 14 | 15 | EXPOSE 8081 16 | -------------------------------------------------------------------------------- /3.4-app-exporter-php/app/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "laravel/lumen": "^7.0", 4 | "endclothing/prometheus_client_php": "^1.0" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /3.4-app-exporter-php/app/index.php: -------------------------------------------------------------------------------- 1 | getOrRegisterCounter('', 'test_counter', 'Example of a counter', ['code']); 14 | $gauge = $registry->getOrRegisterGauge('', 'test_gauge', 'Example of a gauge', ['method', 'code']); 15 | 16 | $counter->inc(['code' => 200]); 17 | $counter->inc(['code' => 400]); 18 | 19 | $app->router->get( 20 | '/', 21 | static function () { 22 | return "hola"; 23 | } 24 | ); 25 | 26 | $app->router->get( 27 | '/send', 28 | function () use ($gauge) { 29 | $gauge->set(mt_rand(0, 1000), ['method' => 'get', 'code' => '200']); 30 | } 31 | ); 32 | 33 | $app->router->get( 34 | '/metrics', 35 | function () use ($registry) { 36 | $renderer = new RenderTextFormat(); 37 | $result = $renderer->render($registry->getMetricFamilySamples()); 38 | return (new \Illuminate\Http\Response($result, 200)) 39 | ->header('Content-Type', RenderTextFormat::MIME_TYPE); 40 | } 41 | ); 42 | 43 | $app->run(); 44 | -------------------------------------------------------------------------------- /3.4-app-exporter-php/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | 4 | prometheus: 5 | image: prom/prometheus:v2.1.0 6 | volumes: 7 | - ./etc/prometheus/:/etc/prometheus/ 8 | - ./var/prometheus/prometheus_data:/prometheus 9 | command: 10 | - '--config.file=/etc/prometheus/prometheus.yml' 11 | - '--storage.tsdb.path=/prometheus' 12 | - '--web.console.libraries=/usr/share/prometheus/console_libraries' 13 | - '--web.console.templates=/usr/share/prometheus/consoles' 14 | ports: 15 | - 9090:9090 16 | 17 | app: 18 | build: . 19 | ports: 20 | - 8081:8081 21 | depends_on: 22 | - prometheus 23 | -------------------------------------------------------------------------------- /3.4-app-exporter-php/etc/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | evaluation_interval: 15s 4 | external_labels: 5 | monitor: 'codely-app' 6 | 7 | scrape_configs: 8 | 9 | - job_name: 'prometheus' 10 | scrape_interval: 5s 11 | static_configs: 12 | - targets: ['localhost:9090'] 13 | 14 | - job_name: 'codely' 15 | scrape_interval: 5s 16 | static_configs: 17 | - targets: ['app:8081'] 18 | -------------------------------------------------------------------------------- /4.1-push-gateway/.gitignore: -------------------------------------------------------------------------------- 1 | var 2 | main 3 | -------------------------------------------------------------------------------- /4.1-push-gateway/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:latest AS builder 2 | ADD ./app /app 3 | WORKDIR /app 4 | RUN go mod download 5 | RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o /main . 6 | 7 | FROM alpine:latest 8 | RUN apk --no-cache add ca-certificates 9 | COPY --from=builder /main ./ 10 | RUN chmod +x ./main 11 | ENTRYPOINT ["./main"] 12 | EXPOSE 80 -------------------------------------------------------------------------------- /4.1-push-gateway/app/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rubencougil/geekshubs/prometheus/app 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 7 | github.com/modern-go/reflect2 v1.0.1 // indirect 8 | github.com/prometheus/client_golang v1.2.1 // indirect 9 | ) 10 | -------------------------------------------------------------------------------- /4.1-push-gateway/app/go.sum: -------------------------------------------------------------------------------- 1 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 2 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 3 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 4 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 5 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 6 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 7 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 8 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 9 | github.com/cespare/xxhash/v2 v2.1.0 h1:yTUvW7Vhb89inJ+8irsUqiWjh8iT6sQPZiQzI6ReGkA= 10 | github.com/cespare/xxhash/v2 v2.1.0/go.mod h1:dgIUBU3pDso/gPgZ1osOZ0iQf77oPR28Tjxl5dIMyVM= 11 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 13 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 14 | github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 15 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 16 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 17 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 18 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 19 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 20 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 21 | github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= 22 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 23 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 24 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 25 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 26 | github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 27 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 28 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 29 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 30 | github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= 31 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 32 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 33 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 34 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 35 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 36 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 37 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 38 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 39 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 40 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 41 | github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= 42 | github.com/prometheus/client_golang v1.2.1 h1:JnMpQc6ppsNgw9QPAGF6Dod479itz7lvlsMzzNayLOI= 43 | github.com/prometheus/client_golang v1.2.1/go.mod h1:XMU6Z2MjaRKVu/dC1qupJI9SiNkDYzz3xecMgSW/F+U= 44 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 45 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 46 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= 47 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 48 | github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 49 | github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY= 50 | github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= 51 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 52 | github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 53 | github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= 54 | github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= 55 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 56 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 57 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 58 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 59 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 60 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 61 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 62 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 63 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 64 | golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 65 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 66 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 67 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 68 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 69 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 70 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 71 | golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 72 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 73 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 74 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 75 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 76 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 77 | -------------------------------------------------------------------------------- /4.1-push-gateway/app/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "github.com/prometheus/client_golang/prometheus" 7 | "github.com/prometheus/client_golang/prometheus/promauto" 8 | "github.com/prometheus/client_golang/prometheus/push" 9 | "log" 10 | "math/rand" 11 | "net/http" 12 | "time" 13 | 14 | "github.com/prometheus/client_golang/prometheus/promhttp" 15 | ) 16 | 17 | var addr = flag.String("listen-address", ":8081", "The address to listen on for HTTP requests.") 18 | 19 | var ( 20 | c = promauto.NewCounter(prometheus.CounterOpts{ 21 | Name: "codely_app_sample_metric", 22 | Help: "Sample counter for Codely course", 23 | }) 24 | 25 | h = promauto.NewHistogram(prometheus.HistogramOpts{ 26 | Name: "codely_app_sample_histogram", 27 | Help: "Sample histogram for Codely course", 28 | }) 29 | 30 | d = promauto.NewCounterVec(prometheus.CounterOpts{ 31 | Name: "codely_app_sample_devices", 32 | Help: "Sample counter with devices label for Codely course"}, []string{"device"}) 33 | 34 | e = promauto.NewCounter(prometheus.CounterOpts{ 35 | Name: "codely_app_push_metric", 36 | Help: "Sample metric for Codely course (push)", 37 | }) 38 | ) 39 | 40 | func main() { 41 | 42 | rand.Seed(time.Now().UnixNano()) 43 | 44 | go func() { 45 | for { 46 | rand.Seed(time.Now().UnixNano()) 47 | h.Observe(float64(rand.Intn(100-0+1) + 0)) 48 | d.With(prometheus.Labels{"device":"/dev/sda"}).Inc() 49 | c.Inc() 50 | time.Sleep(1 * time.Second) 51 | } 52 | }() 53 | 54 | go func() { 55 | for { 56 | // Example of metric push 57 | _ = push.New("http://pushgateway:9091", "codely_job").Collector(e).Add() 58 | e.Inc() 59 | fmt.Print("_") 60 | time.Sleep(1 * time.Second) 61 | } 62 | }() 63 | 64 | http.Handle("/metrics", promhttp.Handler()) 65 | log.Fatal(http.ListenAndServe(*addr, nil)) 66 | } 67 | -------------------------------------------------------------------------------- /4.1-push-gateway/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | 4 | prometheus: 5 | image: prom/prometheus:v2.19.0 6 | volumes: 7 | - ./etc/prometheus/:/etc/prometheus/ 8 | - ./var/prometheus/prometheus_data:/prometheus 9 | command: 10 | - '--config.file=/etc/prometheus/prometheus.yml' 11 | - '--storage.tsdb.path=/prometheus' 12 | - '--web.console.libraries=/usr/share/prometheus/console_libraries' 13 | - '--web.console.templates=/usr/share/prometheus/consoles' 14 | ports: 15 | - 9090:9090 16 | 17 | app: 18 | build: . 19 | ports: 20 | - 8081:8081 21 | depends_on: 22 | - prometheus 23 | 24 | pushgateway: 25 | image: prom/pushgateway 26 | ports: 27 | - "9091:9091" 28 | depends_on: 29 | - prometheus 30 | -------------------------------------------------------------------------------- /4.1-push-gateway/etc/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | scrape_configs: 2 | 3 | - job_name: 'prometheus' 4 | scrape_interval: 5s 5 | static_configs: 6 | - targets: ['localhost:9090'] 7 | 8 | - job_name: 'codely' 9 | scrape_interval: 5s 10 | static_configs: 11 | - targets: ['app:8081'] 12 | 13 | - job_name: 'pushgateway' 14 | scrape_interval: 10s 15 | honor_labels: true 16 | static_configs: 17 | - targets: ['pushgateway:9091'] 18 | -------------------------------------------------------------------------------- /4.2-remote-write-cortex/.gitignore: -------------------------------------------------------------------------------- 1 | var 2 | main 3 | -------------------------------------------------------------------------------- /4.2-remote-write-cortex/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:latest AS builder 2 | ADD ./app /app 3 | WORKDIR /app 4 | RUN go mod download 5 | RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o /main . 6 | 7 | FROM alpine:latest 8 | RUN apk --no-cache add ca-certificates 9 | COPY --from=builder /main ./ 10 | RUN chmod +x ./main 11 | ENTRYPOINT ["./main"] 12 | EXPOSE 80 -------------------------------------------------------------------------------- /4.2-remote-write-cortex/app/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rubencougil/geekshubs/prometheus/app 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 7 | github.com/modern-go/reflect2 v1.0.1 // indirect 8 | github.com/prometheus/client_golang v1.2.1 // indirect 9 | ) 10 | -------------------------------------------------------------------------------- /4.2-remote-write-cortex/app/go.sum: -------------------------------------------------------------------------------- 1 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 2 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 3 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 4 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 5 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 6 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 7 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 8 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 9 | github.com/cespare/xxhash/v2 v2.1.0 h1:yTUvW7Vhb89inJ+8irsUqiWjh8iT6sQPZiQzI6ReGkA= 10 | github.com/cespare/xxhash/v2 v2.1.0/go.mod h1:dgIUBU3pDso/gPgZ1osOZ0iQf77oPR28Tjxl5dIMyVM= 11 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 13 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 14 | github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 15 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 16 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 17 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 18 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 19 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 20 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 21 | github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= 22 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 23 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 24 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 25 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 26 | github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 27 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 28 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 29 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 30 | github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= 31 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 32 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 33 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 34 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 35 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 36 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 37 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 38 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 39 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 40 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 41 | github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= 42 | github.com/prometheus/client_golang v1.2.1 h1:JnMpQc6ppsNgw9QPAGF6Dod479itz7lvlsMzzNayLOI= 43 | github.com/prometheus/client_golang v1.2.1/go.mod h1:XMU6Z2MjaRKVu/dC1qupJI9SiNkDYzz3xecMgSW/F+U= 44 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 45 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 46 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= 47 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 48 | github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 49 | github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY= 50 | github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= 51 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 52 | github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 53 | github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= 54 | github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= 55 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 56 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 57 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 58 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 59 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 60 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 61 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 62 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 63 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 64 | golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 65 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 66 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 67 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 68 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 69 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 70 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 71 | golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 72 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 73 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 74 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 75 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 76 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 77 | -------------------------------------------------------------------------------- /4.2-remote-write-cortex/app/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "github.com/prometheus/client_golang/prometheus" 7 | "github.com/prometheus/client_golang/prometheus/promauto" 8 | "log" 9 | "math/rand" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/prometheus/client_golang/prometheus/promhttp" 14 | ) 15 | 16 | var addr = flag.String("listen-address", ":8081", "The address to listen on for HTTP requests.") 17 | 18 | var ( 19 | c = promauto.NewCounter(prometheus.CounterOpts{ 20 | Name: "codely_app_sample_metric", 21 | Help: "Sample metric for Codely course", 22 | }) 23 | 24 | h = promauto.NewHistogram(prometheus.HistogramOpts{ 25 | Name: "codely_app_sample_histogram", 26 | Help: "Sample histogram for Codely course", 27 | }) 28 | 29 | d = promauto.NewCounterVec(prometheus.CounterOpts{ 30 | Name: "codely_app_sample_devices", 31 | Help: "Sample counter opts devices for Codely course"}, []string{"device"}) 32 | ) 33 | 34 | func main() { 35 | 36 | rand.Seed(time.Now().UnixNano()) 37 | 38 | go func() { 39 | for { 40 | rand.Seed(time.Now().UnixNano()) 41 | h.Observe(float64(rand.Intn(100-0+1) + 0)) 42 | d.With(prometheus.Labels{"device":"/dev/sda"}).Inc() 43 | c.Inc() 44 | fmt.Print(".") 45 | time.Sleep(1 * time.Second) 46 | } 47 | }() 48 | 49 | http.Handle("/metrics", promhttp.Handler()) 50 | log.Fatal(http.ListenAndServe(*addr, nil)) 51 | } 52 | -------------------------------------------------------------------------------- /4.2-remote-write-cortex/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | 4 | prometheus: 5 | image: prom/prometheus:v2.19.0 6 | volumes: 7 | - ./etc/prometheus/:/etc/prometheus/ 8 | - ./var/prometheus/prometheus_data:/prometheus 9 | command: 10 | - '--config.file=/etc/prometheus/prometheus.yml' 11 | - '--storage.tsdb.path=/prometheus' 12 | - '--web.console.libraries=/usr/share/prometheus/console_libraries' 13 | - '--web.console.templates=/usr/share/prometheus/consoles' 14 | ports: 15 | - 9090:9090 16 | 17 | cortex: 18 | image: cortexproject/cortex:v0.1.0 19 | ports: 20 | - "9009:9009" 21 | command: "-config.file=/etc/single-process-config.yaml" 22 | depends_on: 23 | - prometheus 24 | volumes: 25 | - "./etc/cortex/single-process-config.yaml:/etc/single-process-config.yaml" 26 | 27 | grafana: 28 | image: grafana/grafana 29 | ports: 30 | - 3000:3000 31 | volumes: 32 | - "./var/grafana/grafana_data:/var/lib/grafana" 33 | depends_on: 34 | - prometheus 35 | environment: 36 | - GF_SECURITY_ADMIN_PASSWORD=foobar 37 | - GF_USERS_ALLOW_SIGN_UP=false 38 | 39 | app: 40 | build: . 41 | ports: 42 | - 8081:8081 43 | depends_on: 44 | - prometheus 45 | -------------------------------------------------------------------------------- /4.2-remote-write-cortex/etc/cortex/single-process-config.yaml: -------------------------------------------------------------------------------- 1 | # Configuration for running Cortex in single-process mode. 2 | # This should not be used in production. It is only for getting started 3 | # and development. 4 | 5 | # Disable the requirement that every request to Cortex has a 6 | # X-Scope-OrgID header. `fake` will be substituted in instead. 7 | auth_enabled: false 8 | 9 | server: 10 | http_listen_port: 9009 11 | 12 | # Configure the server to allow messages up to 100MB. 13 | grpc_server_max_recv_msg_size: 104857600 14 | grpc_server_max_send_msg_size: 104857600 15 | grpc_server_max_concurrent_streams: 1000 16 | 17 | distributor: 18 | shard_by_all_labels: true 19 | pool: 20 | health_check_ingesters: true 21 | 22 | ingester_client: 23 | grpc_client_config: 24 | # Configure the client to allow messages up to 100MB. 25 | max_recv_msg_size: 104857600 26 | max_send_msg_size: 104857600 27 | use_gzip_compression: true 28 | 29 | ingester: 30 | #chunk_idle_period: 15m 31 | 32 | lifecycler: 33 | # The address to advertise for this ingester. Will be autodiscovered by 34 | # looking up address on eth0 or en0; can be specified if this fails. 35 | # address: 127.0.0.1 36 | 37 | # We want to start immediately and flush on shutdown. 38 | join_after: 0 39 | claim_on_rollout: false 40 | final_sleep: 0s 41 | num_tokens: 512 42 | 43 | # Use an in memory ring store, so we don't need to launch a Consul. 44 | ring: 45 | kvstore: 46 | store: inmemory 47 | replication_factor: 1 48 | 49 | # Use local storage - BoltDB for the index, and the filesystem 50 | # for the chunks. 51 | schema: 52 | configs: 53 | - from: 2019-03-25 54 | store: boltdb 55 | object_store: filesystem 56 | schema: v10 57 | index: 58 | prefix: index_ 59 | period: 168h 60 | 61 | storage: 62 | boltdb: 63 | directory: /tmp/cortex/index 64 | 65 | filesystem: 66 | directory: /tmp/cortex/chunks -------------------------------------------------------------------------------- /4.2-remote-write-cortex/etc/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | evaluation_interval: 15s 4 | external_labels: 5 | monitor: 'codely-app' 6 | 7 | scrape_configs: 8 | 9 | - job_name: 'prometheus' 10 | scrape_interval: 5s 11 | static_configs: 12 | - targets: ['localhost:9090'] 13 | 14 | - job_name: 'codely' 15 | scrape_interval: 5s 16 | static_configs: 17 | - targets: ['app:8081'] 18 | 19 | remote_write: 20 | - url: http://cortex:9009/api/prom/push 21 | queue_config: 22 | capacity: 5000 23 | max_shards: 20 24 | min_shards: 5 25 | max_samples_per_send: 1000 26 | -------------------------------------------------------------------------------- /4.3-promql/.gitignore: -------------------------------------------------------------------------------- 1 | var 2 | main 3 | -------------------------------------------------------------------------------- /4.3-promql/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:latest AS builder 2 | ADD ./app /app 3 | WORKDIR /app 4 | RUN go mod download 5 | RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o /main . 6 | 7 | FROM alpine:latest 8 | RUN apk --no-cache add ca-certificates 9 | COPY --from=builder /main ./ 10 | RUN chmod +x ./main 11 | ENTRYPOINT ["./main"] 12 | EXPOSE 80 -------------------------------------------------------------------------------- /4.3-promql/app/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rubencougil/geekshubs/prometheus/app 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 7 | github.com/modern-go/reflect2 v1.0.1 // indirect 8 | github.com/prometheus/client_golang v1.2.1 // indirect 9 | ) 10 | -------------------------------------------------------------------------------- /4.3-promql/app/go.sum: -------------------------------------------------------------------------------- 1 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 2 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 3 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 4 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 5 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 6 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 7 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 8 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 9 | github.com/cespare/xxhash/v2 v2.1.0 h1:yTUvW7Vhb89inJ+8irsUqiWjh8iT6sQPZiQzI6ReGkA= 10 | github.com/cespare/xxhash/v2 v2.1.0/go.mod h1:dgIUBU3pDso/gPgZ1osOZ0iQf77oPR28Tjxl5dIMyVM= 11 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 13 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 14 | github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 15 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 16 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 17 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 18 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 19 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 20 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 21 | github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= 22 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 23 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 24 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 25 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 26 | github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 27 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 28 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 29 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 30 | github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= 31 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 32 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 33 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 34 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 35 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 36 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 37 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 38 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 39 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 40 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 41 | github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= 42 | github.com/prometheus/client_golang v1.2.1 h1:JnMpQc6ppsNgw9QPAGF6Dod479itz7lvlsMzzNayLOI= 43 | github.com/prometheus/client_golang v1.2.1/go.mod h1:XMU6Z2MjaRKVu/dC1qupJI9SiNkDYzz3xecMgSW/F+U= 44 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 45 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 46 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= 47 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 48 | github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 49 | github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY= 50 | github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= 51 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 52 | github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 53 | github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= 54 | github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= 55 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 56 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 57 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 58 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 59 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 60 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 61 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 62 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 63 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 64 | golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 65 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 66 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 67 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 68 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 69 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 70 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 71 | golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 72 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 73 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 74 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 75 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 76 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 77 | -------------------------------------------------------------------------------- /4.3-promql/app/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "github.com/prometheus/client_golang/prometheus" 7 | "github.com/prometheus/client_golang/prometheus/promauto" 8 | "log" 9 | "math/rand" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/prometheus/client_golang/prometheus/promhttp" 14 | ) 15 | 16 | var addr = flag.String("listen-address", ":8081", "The address to listen on for HTTP requests.") 17 | 18 | var ( 19 | c = promauto.NewCounter(prometheus.CounterOpts{ 20 | Name: "codely_app_sample_metric", 21 | Help: "Sample metric for Codely course", 22 | }) 23 | 24 | h = promauto.NewHistogram(prometheus.HistogramOpts{ 25 | Name: "codely_app_sample_histogram", 26 | Help: "Sample histogram for Codely course", 27 | }) 28 | 29 | d = promauto.NewCounterVec(prometheus.CounterOpts{ 30 | Name: "codely_app_sample_devices", 31 | Help: "Sample counter opts devices for Codely course"}, []string{"device"}) 32 | ) 33 | 34 | func main() { 35 | 36 | rand.Seed(time.Now().UnixNano()) 37 | 38 | go func() { 39 | for { 40 | rand.Seed(time.Now().UnixNano()) 41 | h.Observe(float64(rand.Intn(100-0+1) + 0)) 42 | d.With(prometheus.Labels{"device":"/dev/sda"}).Inc() 43 | c.Inc() 44 | fmt.Print(".") 45 | time.Sleep(1 * time.Second) 46 | } 47 | }() 48 | 49 | http.Handle("/metrics", promhttp.Handler()) 50 | log.Fatal(http.ListenAndServe(*addr, nil)) 51 | } 52 | -------------------------------------------------------------------------------- /4.3-promql/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | 4 | prometheus: 5 | image: prom/prometheus:v2.19.0 6 | volumes: 7 | - ./etc/prometheus/:/etc/prometheus/ 8 | - ./var/prometheus/prometheus_data:/prometheus 9 | command: 10 | - '--config.file=/etc/prometheus/prometheus.yml' 11 | - '--storage.tsdb.path=/prometheus' 12 | - '--web.console.libraries=/usr/share/prometheus/console_libraries' 13 | - '--web.console.templates=/usr/share/prometheus/consoles' 14 | ports: 15 | - 9090:9090 16 | 17 | cortex: 18 | image: cortexproject/cortex:v0.1.0 19 | ports: 20 | - "9009:9009" 21 | command: "-config.file=/etc/single-process-config.yaml" 22 | depends_on: 23 | - prometheus 24 | volumes: 25 | - "./etc/cortex/single-process-config.yaml:/etc/single-process-config.yaml" 26 | 27 | grafana: 28 | image: grafana/grafana 29 | ports: 30 | - 3000:3000 31 | volumes: 32 | - "./var/grafana/grafana_data:/var/lib/grafana" 33 | depends_on: 34 | - prometheus 35 | environment: 36 | - GF_SECURITY_ADMIN_PASSWORD=foobar 37 | - GF_USERS_ALLOW_SIGN_UP=false 38 | 39 | app: 40 | build: . 41 | ports: 42 | - 8081:8081 43 | depends_on: 44 | - prometheus 45 | -------------------------------------------------------------------------------- /4.3-promql/etc/cortex/single-process-config.yaml: -------------------------------------------------------------------------------- 1 | # Configuration for running Cortex in single-process mode. 2 | # This should not be used in production. It is only for getting started 3 | # and development. 4 | 5 | # Disable the requirement that every request to Cortex has a 6 | # X-Scope-OrgID header. `fake` will be substituted in instead. 7 | auth_enabled: false 8 | 9 | server: 10 | http_listen_port: 9009 11 | 12 | # Configure the server to allow messages up to 100MB. 13 | grpc_server_max_recv_msg_size: 104857600 14 | grpc_server_max_send_msg_size: 104857600 15 | grpc_server_max_concurrent_streams: 1000 16 | 17 | distributor: 18 | shard_by_all_labels: true 19 | pool: 20 | health_check_ingesters: true 21 | 22 | ingester_client: 23 | grpc_client_config: 24 | # Configure the client to allow messages up to 100MB. 25 | max_recv_msg_size: 104857600 26 | max_send_msg_size: 104857600 27 | use_gzip_compression: true 28 | 29 | ingester: 30 | #chunk_idle_period: 15m 31 | 32 | lifecycler: 33 | # The address to advertise for this ingester. Will be autodiscovered by 34 | # looking up address on eth0 or en0; can be specified if this fails. 35 | # address: 127.0.0.1 36 | 37 | # We want to start immediately and flush on shutdown. 38 | join_after: 0 39 | claim_on_rollout: false 40 | final_sleep: 0s 41 | num_tokens: 512 42 | 43 | # Use an in memory ring store, so we don't need to launch a Consul. 44 | ring: 45 | kvstore: 46 | store: inmemory 47 | replication_factor: 1 48 | 49 | # Use local storage - BoltDB for the index, and the filesystem 50 | # for the chunks. 51 | schema: 52 | configs: 53 | - from: 2019-03-25 54 | store: boltdb 55 | object_store: filesystem 56 | schema: v10 57 | index: 58 | prefix: index_ 59 | period: 168h 60 | 61 | storage: 62 | boltdb: 63 | directory: /tmp/cortex/index 64 | 65 | filesystem: 66 | directory: /tmp/cortex/chunks -------------------------------------------------------------------------------- /4.3-promql/etc/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | evaluation_interval: 15s 4 | external_labels: 5 | monitor: 'codely-app' 6 | 7 | scrape_configs: 8 | 9 | - job_name: 'prometheus' 10 | scrape_interval: 5s 11 | static_configs: 12 | - targets: ['localhost:9090'] 13 | 14 | - job_name: 'codely' 15 | scrape_interval: 5s 16 | static_configs: 17 | - targets: ['app:8081'] 18 | 19 | remote_write: 20 | - url: http://cortex:9009/api/prom/push 21 | queue_config: 22 | capacity: 5000 23 | max_shards: 20 24 | min_shards: 5 25 | max_samples_per_send: 1000 26 | -------------------------------------------------------------------------------- /5.1-grafana/.gitignore: -------------------------------------------------------------------------------- 1 | var 2 | main 3 | -------------------------------------------------------------------------------- /5.1-grafana/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:latest AS builder 2 | ADD ./app /app 3 | WORKDIR /app 4 | RUN go mod download 5 | RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o /main . 6 | 7 | FROM alpine:latest 8 | RUN apk --no-cache add ca-certificates 9 | COPY --from=builder /main ./ 10 | RUN chmod +x ./main 11 | ENTRYPOINT ["./main"] 12 | EXPOSE 80 -------------------------------------------------------------------------------- /5.1-grafana/app/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rubencougil/geekshubs/prometheus/app 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.6.3 // indirect 7 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 8 | github.com/modern-go/reflect2 v1.0.1 // indirect 9 | github.com/prometheus/client_golang v1.2.1 // indirect 10 | github.com/zsais/go-gin-prometheus v0.1.0 // indirect 11 | ) 12 | -------------------------------------------------------------------------------- /5.1-grafana/app/go.sum: -------------------------------------------------------------------------------- 1 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 2 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 3 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 4 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 5 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 6 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 7 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 8 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 9 | github.com/cespare/xxhash/v2 v2.1.0 h1:yTUvW7Vhb89inJ+8irsUqiWjh8iT6sQPZiQzI6ReGkA= 10 | github.com/cespare/xxhash/v2 v2.1.0/go.mod h1:dgIUBU3pDso/gPgZ1osOZ0iQf77oPR28Tjxl5dIMyVM= 11 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 13 | github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= 14 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= 15 | github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= 16 | github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= 17 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 18 | github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 19 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 20 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 21 | github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= 22 | github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= 23 | github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= 24 | github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= 25 | github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= 26 | github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= 27 | github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= 28 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 29 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 30 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 31 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 32 | github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= 33 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 34 | github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= 35 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 36 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 37 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 38 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 39 | github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 40 | github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 41 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 42 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 43 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 44 | github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= 45 | github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= 46 | github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= 47 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 48 | github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= 49 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 50 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 51 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 52 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 53 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 54 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 55 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 56 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 57 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 58 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 59 | github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= 60 | github.com/prometheus/client_golang v1.2.1 h1:JnMpQc6ppsNgw9QPAGF6Dod479itz7lvlsMzzNayLOI= 61 | github.com/prometheus/client_golang v1.2.1/go.mod h1:XMU6Z2MjaRKVu/dC1qupJI9SiNkDYzz3xecMgSW/F+U= 62 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 63 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 64 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= 65 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 66 | github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 67 | github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY= 68 | github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= 69 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 70 | github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 71 | github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= 72 | github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= 73 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 74 | github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= 75 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 76 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 77 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 78 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 79 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 80 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 81 | github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= 82 | github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= 83 | github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= 84 | github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= 85 | github.com/zsais/go-gin-prometheus v0.1.0 h1:bkLv1XCdzqVgQ36ScgRi09MA2UC1t3tAB6nsfErsGO4= 86 | github.com/zsais/go-gin-prometheus v0.1.0/go.mod h1:Slirjzuz8uM8Cw0jmPNqbneoqcUtY2GGjn2bEd4NRLY= 87 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 88 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 89 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 90 | golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 91 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 92 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 93 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 94 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 95 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 96 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 97 | golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 98 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= 99 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 100 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 101 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 102 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 103 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 104 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 105 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 106 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 107 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 108 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 109 | -------------------------------------------------------------------------------- /5.1-grafana/app/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "github.com/gin-gonic/gin" 7 | "github.com/prometheus/client_golang/prometheus" 8 | "github.com/prometheus/client_golang/prometheus/promauto" 9 | ginprometheus "github.com/zsais/go-gin-prometheus" 10 | "log" 11 | "math/rand" 12 | "time" 13 | ) 14 | 15 | var addr = flag.String("listen-address", ":8081", "The address to listen on for HTTP requests.") 16 | 17 | var ( 18 | c = promauto.NewCounter(prometheus.CounterOpts{ 19 | Name: "codely_app_sample_metric", 20 | Help: "Sample metric for Codely course", 21 | }) 22 | 23 | h = promauto.NewHistogram(prometheus.HistogramOpts{ 24 | Name: "codely_app_sample_histogram", 25 | Help: "Sample histogram for Codely course", 26 | }) 27 | 28 | d = promauto.NewCounterVec(prometheus.CounterOpts{ 29 | Name: "codely_app_sample_devices", 30 | Help: "Sample counter opts devices for Codely course"}, []string{"device"}) 31 | ) 32 | 33 | func main() { 34 | 35 | r := gin.New() 36 | 37 | rand.Seed(time.Now().UnixNano()) 38 | 39 | p := ginprometheus.NewPrometheus("http") 40 | p.Use(r) 41 | 42 | r.GET("/", func(c *gin.Context) { 43 | time.Sleep(time.Duration(rand.Intn(500)) * time.Millisecond) 44 | 45 | switch rand.Intn(4) { 46 | case 0: c.JSON(200, "Hello world!") 47 | case 1: c.JSON(404, "Not Found!") 48 | case 2: c.JSON(500, "Oops!") 49 | case 3: c.JSON(401, "Forbidden!") 50 | default: 51 | c.JSON(200, "Hello world!") 52 | } 53 | }) 54 | 55 | go func() { 56 | for { 57 | rand.Seed(time.Now().UnixNano()) 58 | h.Observe(float64(rand.Intn(100-0+1) + 0)) 59 | d.With(prometheus.Labels{"device":"/dev/sda"}).Inc() 60 | c.Inc() 61 | fmt.Print(".") 62 | time.Sleep(1 * time.Second) 63 | } 64 | }() 65 | 66 | log.Fatal(r.Run(*addr)) 67 | } 68 | -------------------------------------------------------------------------------- /5.1-grafana/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | 4 | prometheus: 5 | image: prom/prometheus:v2.19.0 6 | volumes: 7 | - ./etc/prometheus/:/etc/prometheus/ 8 | - ./var/prometheus/prometheus_data:/prometheus 9 | command: 10 | - '--config.file=/etc/prometheus/prometheus.yml' 11 | - '--storage.tsdb.path=/prometheus' 12 | - '--web.console.libraries=/usr/share/prometheus/console_libraries' 13 | - '--web.console.templates=/usr/share/prometheus/consoles' 14 | ports: 15 | - 9090:9090 16 | 17 | app: 18 | build: . 19 | restart: always 20 | ports: 21 | - 8081:8081 22 | depends_on: 23 | - prometheus 24 | 25 | grafana: 26 | image: grafana/grafana 27 | ports: 28 | - 3000:3000 29 | volumes: 30 | - "./var/grafana/grafana_data:/var/lib/grafana" 31 | - "./etc/grafana/provisioning/:/etc/grafana/provisioning/" 32 | environment: 33 | - GF_SECURITY_ADMIN_PASSWORD=foobar 34 | - GF_USERS_ALLOW_SIGN_UP=false -------------------------------------------------------------------------------- /5.1-grafana/etc/grafana/provisioning/datasource.yml: -------------------------------------------------------------------------------- 1 | apiVersion: 1 2 | 3 | datasources: 4 | 5 | - name: Prometheus 6 | type: prometheus 7 | access: proxy 8 | orgId: 1 9 | url: http://prometheus:9090 10 | basicAuth: false 11 | isDefault: true -------------------------------------------------------------------------------- /5.1-grafana/etc/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | evaluation_interval: 15s 4 | external_labels: 5 | monitor: 'codely-app' 6 | 7 | scrape_configs: 8 | 9 | - job_name: 'prometheus' 10 | scrape_interval: 5s 11 | static_configs: 12 | - targets: ['localhost:9090'] 13 | 14 | - job_name: 'codely' 15 | scrape_interval: 5s 16 | static_configs: 17 | - targets: ['app:8081'] 18 | -------------------------------------------------------------------------------- /5.2-grafana-dashboard/.gitignore: -------------------------------------------------------------------------------- 1 | var 2 | main 3 | -------------------------------------------------------------------------------- /5.2-grafana-dashboard/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:latest AS builder 2 | ADD ./app /app 3 | WORKDIR /app 4 | RUN go mod download 5 | RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o /main . 6 | 7 | FROM alpine:latest 8 | RUN apk --no-cache add ca-certificates 9 | COPY --from=builder /main ./ 10 | RUN chmod +x ./main 11 | ENTRYPOINT ["./main"] 12 | EXPOSE 80 -------------------------------------------------------------------------------- /5.2-grafana-dashboard/app/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rubencougil/geekshubs/prometheus/app 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.6.3 // indirect 7 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 8 | github.com/modern-go/reflect2 v1.0.1 // indirect 9 | github.com/prometheus/client_golang v1.2.1 // indirect 10 | github.com/zsais/go-gin-prometheus v0.1.0 // indirect 11 | ) 12 | -------------------------------------------------------------------------------- /5.2-grafana-dashboard/app/go.sum: -------------------------------------------------------------------------------- 1 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 2 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 3 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 4 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 5 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 6 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 7 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 8 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 9 | github.com/cespare/xxhash/v2 v2.1.0 h1:yTUvW7Vhb89inJ+8irsUqiWjh8iT6sQPZiQzI6ReGkA= 10 | github.com/cespare/xxhash/v2 v2.1.0/go.mod h1:dgIUBU3pDso/gPgZ1osOZ0iQf77oPR28Tjxl5dIMyVM= 11 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 13 | github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= 14 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= 15 | github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= 16 | github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= 17 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 18 | github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 19 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 20 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 21 | github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= 22 | github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= 23 | github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= 24 | github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= 25 | github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= 26 | github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= 27 | github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= 28 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 29 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 30 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 31 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 32 | github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= 33 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 34 | github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= 35 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 36 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 37 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 38 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 39 | github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 40 | github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 41 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 42 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 43 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 44 | github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= 45 | github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= 46 | github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= 47 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 48 | github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= 49 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 50 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 51 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 52 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 53 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 54 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 55 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 56 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 57 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 58 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 59 | github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= 60 | github.com/prometheus/client_golang v1.2.1 h1:JnMpQc6ppsNgw9QPAGF6Dod479itz7lvlsMzzNayLOI= 61 | github.com/prometheus/client_golang v1.2.1/go.mod h1:XMU6Z2MjaRKVu/dC1qupJI9SiNkDYzz3xecMgSW/F+U= 62 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 63 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 64 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= 65 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 66 | github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 67 | github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY= 68 | github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= 69 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 70 | github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 71 | github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= 72 | github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= 73 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 74 | github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= 75 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 76 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 77 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 78 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 79 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 80 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 81 | github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= 82 | github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= 83 | github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= 84 | github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= 85 | github.com/zsais/go-gin-prometheus v0.1.0 h1:bkLv1XCdzqVgQ36ScgRi09MA2UC1t3tAB6nsfErsGO4= 86 | github.com/zsais/go-gin-prometheus v0.1.0/go.mod h1:Slirjzuz8uM8Cw0jmPNqbneoqcUtY2GGjn2bEd4NRLY= 87 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 88 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 89 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 90 | golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 91 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 92 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 93 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 94 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 95 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 96 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 97 | golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 98 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= 99 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 100 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 101 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 102 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 103 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 104 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 105 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 106 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 107 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 108 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 109 | -------------------------------------------------------------------------------- /5.2-grafana-dashboard/app/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "github.com/gin-gonic/gin" 7 | "github.com/prometheus/client_golang/prometheus" 8 | "github.com/prometheus/client_golang/prometheus/promauto" 9 | ginprometheus "github.com/zsais/go-gin-prometheus" 10 | "log" 11 | "math/rand" 12 | "time" 13 | ) 14 | 15 | var addr = flag.String("listen-address", ":8081", "The address to listen on for HTTP requests.") 16 | 17 | var ( 18 | c = promauto.NewCounter(prometheus.CounterOpts{ 19 | Name: "codely_app_sample_metric", 20 | Help: "Sample metric for Codely course", 21 | }) 22 | 23 | h = promauto.NewHistogram(prometheus.HistogramOpts{ 24 | Name: "codely_app_sample_histogram", 25 | Help: "Sample histogram for Codely course", 26 | }) 27 | 28 | d = promauto.NewCounterVec(prometheus.CounterOpts{ 29 | Name: "codely_app_sample_devices", 30 | Help: "Sample counter opts devices for Codely course"}, []string{"device"}) 31 | ) 32 | 33 | func main() { 34 | 35 | rand.Seed(time.Now().UnixNano()) 36 | r := gin.New() 37 | 38 | p := ginprometheus.NewPrometheus("http") 39 | p.Use(r) 40 | 41 | r.GET("/", func(c *gin.Context) { 42 | 43 | time.Sleep(time.Duration(rand.Intn(500)) * time.Millisecond) 44 | 45 | switch rand.Intn(6) { 46 | case 0: c.JSON(200, "Hello world!") 47 | case 1: c.JSON(404, "Not Found!") 48 | case 2: c.JSON(500, "Oops!") 49 | case 3: c.JSON(401, "Unauthorized!") 50 | case 4: c.JSON(403, "Forbidden!") 51 | case 5: c.JSON(408, "Timeout!") 52 | default: 53 | c.JSON(200, "Hello world!") 54 | } 55 | }) 56 | 57 | go func() { 58 | for { 59 | rand.Seed(time.Now().UnixNano()) 60 | h.Observe(float64(rand.Intn(100-0+1) + 0)) 61 | d.With(prometheus.Labels{"device":"/dev/sda"}).Inc() 62 | c.Inc() 63 | fmt.Print(".") 64 | time.Sleep(1 * time.Second) 65 | } 66 | }() 67 | 68 | log.Fatal(r.Run(*addr)) 69 | } 70 | -------------------------------------------------------------------------------- /5.2-grafana-dashboard/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | 4 | prometheus: 5 | image: prom/prometheus:v2.19.0 6 | volumes: 7 | - ./etc/prometheus/:/etc/prometheus/ 8 | - ./var/prometheus/prometheus_data:/prometheus 9 | command: 10 | - '--config.file=/etc/prometheus/prometheus.yml' 11 | - '--storage.tsdb.path=/prometheus' 12 | - '--web.console.libraries=/usr/share/prometheus/console_libraries' 13 | - '--web.console.templates=/usr/share/prometheus/consoles' 14 | ports: 15 | - 9090:9090 16 | 17 | app: 18 | build: . 19 | restart: always 20 | ports: 21 | - 8081:8081 22 | depends_on: 23 | - prometheus 24 | 25 | cadvisor: 26 | image: google/cadvisor 27 | volumes: 28 | - /:/rootfs:ro 29 | - /var/run:/var/run:rw 30 | - /sys:/sys:ro 31 | - /var/lib/docker/:/var/lib/docker:ro 32 | ports: 33 | - 8080:8080 34 | 35 | grafana: 36 | image: grafana/grafana 37 | ports: 38 | - 3000:3000 39 | volumes: 40 | - "./var/grafana/grafana_data:/var/lib/grafana" 41 | - "./etc/grafana/provisioning/:/etc/grafana/provisioning/" 42 | environment: 43 | - GF_SECURITY_ADMIN_PASSWORD=foobar 44 | - GF_USERS_ALLOW_SIGN_UP=false -------------------------------------------------------------------------------- /5.2-grafana-dashboard/etc/grafana/provisioning/dashboards/all.yml: -------------------------------------------------------------------------------- 1 | apiVersion: 1 2 | 3 | providers: 4 | - name: "default" 5 | orgId: 1 6 | folder: "" 7 | type: file 8 | disableDeletion: false 9 | updateIntervalSeconds: 10 10 | options: 11 | path: /etc/grafana/provisioning/dashboards -------------------------------------------------------------------------------- /5.2-grafana-dashboard/etc/grafana/provisioning/dashboards/codely.json: -------------------------------------------------------------------------------- 1 | { 2 | "annotations": { 3 | "list": [ 4 | { 5 | "builtIn": 1, 6 | "datasource": "-- Grafana --", 7 | "enable": true, 8 | "hide": true, 9 | "iconColor": "rgba(0, 211, 255, 1)", 10 | "name": "Annotations & Alerts", 11 | "type": "dashboard" 12 | } 13 | ] 14 | }, 15 | "editable": true, 16 | "gnetId": null, 17 | "graphTooltip": 0, 18 | "id": 1, 19 | "links": [], 20 | "panels": [ 21 | { 22 | "aliasColors": { 23 | "{container_label_com_docker_compose_service=\"app\"}": "purple" 24 | }, 25 | "bars": false, 26 | "dashLength": 10, 27 | "dashes": false, 28 | "datasource": null, 29 | "description": "", 30 | "fieldConfig": { 31 | "defaults": { 32 | "custom": {}, 33 | "mappings": [], 34 | "thresholds": { 35 | "mode": "absolute", 36 | "steps": [ 37 | { 38 | "color": "green", 39 | "value": null 40 | }, 41 | { 42 | "color": "red", 43 | "value": 80 44 | } 45 | ] 46 | } 47 | }, 48 | "overrides": [] 49 | }, 50 | "fill": 1, 51 | "fillGradient": 0, 52 | "gridPos": { 53 | "h": 6, 54 | "w": 12, 55 | "x": 0, 56 | "y": 0 57 | }, 58 | "hiddenSeries": false, 59 | "id": 6, 60 | "legend": { 61 | "avg": false, 62 | "current": false, 63 | "max": false, 64 | "min": false, 65 | "show": true, 66 | "total": false, 67 | "values": false 68 | }, 69 | "lines": true, 70 | "linewidth": 1, 71 | "nullPointMode": "null", 72 | "options": { 73 | "dataLinks": [] 74 | }, 75 | "percentage": false, 76 | "pluginVersion": "7.0.3", 77 | "pointradius": 2, 78 | "points": false, 79 | "renderer": "flot", 80 | "seriesOverrides": [], 81 | "spaceLength": 10, 82 | "stack": false, 83 | "steppedLine": false, 84 | "targets": [ 85 | { 86 | "expr": "avg(container_memory_usage_bytes{container_label_com_docker_compose_service=\"app\"} * 1e-6) by (container_label_com_docker_compose_service)", 87 | "format": "time_series", 88 | "instant": false, 89 | "interval": "", 90 | "legendFormat": "Container: {{container_label_com_docker_compose_service}}", 91 | "refId": "A" 92 | } 93 | ], 94 | "thresholds": [ 95 | { 96 | "$$hashKey": "object:176", 97 | "colorMode": "warning", 98 | "fill": true, 99 | "line": true, 100 | "op": "gt", 101 | "value": 10, 102 | "yaxis": "left" 103 | } 104 | ], 105 | "timeFrom": null, 106 | "timeRegions": [], 107 | "timeShift": null, 108 | "title": "App Memory Usage (MB)", 109 | "tooltip": { 110 | "shared": true, 111 | "sort": 0, 112 | "value_type": "individual" 113 | }, 114 | "type": "graph", 115 | "xaxis": { 116 | "buckets": null, 117 | "mode": "time", 118 | "name": null, 119 | "show": true, 120 | "values": [] 121 | }, 122 | "yaxes": [ 123 | { 124 | "$$hashKey": "object:103", 125 | "format": "short", 126 | "label": null, 127 | "logBase": 1, 128 | "max": null, 129 | "min": null, 130 | "show": true 131 | }, 132 | { 133 | "$$hashKey": "object:104", 134 | "format": "short", 135 | "label": null, 136 | "logBase": 1, 137 | "max": null, 138 | "min": null, 139 | "show": true 140 | } 141 | ], 142 | "yaxis": { 143 | "align": false, 144 | "alignLevel": null 145 | } 146 | }, 147 | { 148 | "datasource": null, 149 | "fieldConfig": { 150 | "defaults": { 151 | "custom": {}, 152 | "mappings": [], 153 | "thresholds": { 154 | "mode": "percentage", 155 | "steps": [ 156 | { 157 | "color": "green", 158 | "value": null 159 | }, 160 | { 161 | "color": "#EAB839", 162 | "value": 65 163 | }, 164 | { 165 | "color": "red", 166 | "value": 85 167 | } 168 | ] 169 | } 170 | }, 171 | "overrides": [] 172 | }, 173 | "gridPos": { 174 | "h": 6, 175 | "w": 4, 176 | "x": 12, 177 | "y": 0 178 | }, 179 | "id": 4, 180 | "options": { 181 | "orientation": "auto", 182 | "reduceOptions": { 183 | "calcs": [ 184 | "mean" 185 | ], 186 | "fields": "", 187 | "values": false 188 | }, 189 | "showThresholdLabels": false, 190 | "showThresholdMarkers": true 191 | }, 192 | "pluginVersion": "7.0.3", 193 | "targets": [ 194 | { 195 | "expr": "rate(http_request_duration_seconds_sum[1m]) / rate(http_request_duration_seconds_count[1m])", 196 | "interval": "", 197 | "legendFormat": "", 198 | "refId": "A" 199 | } 200 | ], 201 | "timeFrom": null, 202 | "timeShift": null, 203 | "title": "HTTP Request Duration Seconds", 204 | "type": "gauge" 205 | }, 206 | { 207 | "datasource": null, 208 | "fieldConfig": { 209 | "defaults": { 210 | "custom": {}, 211 | "mappings": [], 212 | "thresholds": { 213 | "mode": "percentage", 214 | "steps": [ 215 | { 216 | "color": "green", 217 | "value": null 218 | }, 219 | { 220 | "color": "#EAB839", 221 | "value": 50 222 | }, 223 | { 224 | "color": "red", 225 | "value": 80 226 | } 227 | ] 228 | } 229 | }, 230 | "overrides": [] 231 | }, 232 | "gridPos": { 233 | "h": 6, 234 | "w": 4, 235 | "x": 16, 236 | "y": 0 237 | }, 238 | "id": 9, 239 | "options": { 240 | "orientation": "auto", 241 | "reduceOptions": { 242 | "calcs": [ 243 | "mean" 244 | ], 245 | "fields": "", 246 | "values": false 247 | }, 248 | "showThresholdLabels": false, 249 | "showThresholdMarkers": true 250 | }, 251 | "pluginVersion": "7.0.3", 252 | "targets": [ 253 | { 254 | "expr": "sum by (container_label_com_docker_compose_service) (rate(container_cpu_usage_seconds_total{container_label_com_docker_compose_service=\"app\"}[1m]) * 1024 * 60) / on (container_label_com_docker_compose_service) (container_spec_cpu_shares{container_label_com_docker_compose_service=\"app\"}) / 60 * 100", 255 | "interval": "", 256 | "legendFormat": "", 257 | "refId": "A" 258 | } 259 | ], 260 | "timeFrom": null, 261 | "timeShift": null, 262 | "title": "App CPU Usage %", 263 | "type": "gauge" 264 | }, 265 | { 266 | "datasource": null, 267 | "fieldConfig": { 268 | "defaults": { 269 | "custom": {}, 270 | "mappings": [], 271 | "thresholds": { 272 | "mode": "percentage", 273 | "steps": [ 274 | { 275 | "color": "green", 276 | "value": null 277 | }, 278 | { 279 | "color": "#EAB839", 280 | "value": 50 281 | }, 282 | { 283 | "color": "red", 284 | "value": 80 285 | } 286 | ] 287 | } 288 | }, 289 | "overrides": [] 290 | }, 291 | "gridPos": { 292 | "h": 6, 293 | "w": 4, 294 | "x": 20, 295 | "y": 0 296 | }, 297 | "id": 11, 298 | "options": { 299 | "displayMode": "lcd", 300 | "orientation": "horizontal", 301 | "reduceOptions": { 302 | "calcs": [ 303 | "mean" 304 | ], 305 | "fields": "", 306 | "values": false 307 | }, 308 | "showUnfilled": true 309 | }, 310 | "pluginVersion": "7.0.3", 311 | "targets": [ 312 | { 313 | "expr": "sum(rate(http_requests_total{job=\"codely\", code!=\"200\"}[5m])) by (code)", 314 | "interval": "", 315 | "legendFormat": "Code: {{code}}", 316 | "refId": "A" 317 | } 318 | ], 319 | "timeFrom": null, 320 | "timeShift": null, 321 | "title": "Error Response Code", 322 | "type": "bargauge" 323 | }, 324 | { 325 | "aliasColors": { 326 | "{code=\"401\"}": "red", 327 | "{code=\"403\"}": "red", 328 | "{code=\"404\"}": "red", 329 | "{code=\"500\"}": "red" 330 | }, 331 | "bars": true, 332 | "dashLength": 10, 333 | "dashes": false, 334 | "datasource": null, 335 | "fieldConfig": { 336 | "defaults": { 337 | "custom": {} 338 | }, 339 | "overrides": [] 340 | }, 341 | "fill": 1, 342 | "fillGradient": 0, 343 | "gridPos": { 344 | "h": 10, 345 | "w": 12, 346 | "x": 0, 347 | "y": 6 348 | }, 349 | "hiddenSeries": false, 350 | "id": 2, 351 | "legend": { 352 | "avg": false, 353 | "current": false, 354 | "max": false, 355 | "min": false, 356 | "show": true, 357 | "total": false, 358 | "values": false 359 | }, 360 | "lines": false, 361 | "linewidth": 1, 362 | "nullPointMode": "null", 363 | "options": { 364 | "dataLinks": [] 365 | }, 366 | "percentage": false, 367 | "pointradius": 2, 368 | "points": false, 369 | "renderer": "flot", 370 | "seriesOverrides": [], 371 | "spaceLength": 10, 372 | "stack": true, 373 | "steppedLine": false, 374 | "targets": [ 375 | { 376 | "expr": "avg(rate(http_requests_total[5m])) by (code)", 377 | "interval": "", 378 | "legendFormat": "", 379 | "refId": "A" 380 | } 381 | ], 382 | "thresholds": [], 383 | "timeFrom": null, 384 | "timeRegions": [], 385 | "timeShift": null, 386 | "title": "HTTP Response Codes", 387 | "tooltip": { 388 | "shared": true, 389 | "sort": 0, 390 | "value_type": "individual" 391 | }, 392 | "type": "graph", 393 | "xaxis": { 394 | "buckets": null, 395 | "mode": "time", 396 | "name": null, 397 | "show": true, 398 | "values": [] 399 | }, 400 | "yaxes": [ 401 | { 402 | "format": "short", 403 | "label": null, 404 | "logBase": 1, 405 | "max": null, 406 | "min": null, 407 | "show": true 408 | }, 409 | { 410 | "format": "short", 411 | "label": null, 412 | "logBase": 1, 413 | "max": null, 414 | "min": null, 415 | "show": true 416 | } 417 | ], 418 | "yaxis": { 419 | "align": false, 420 | "alignLevel": null 421 | } 422 | }, 423 | { 424 | "aliasColors": { 425 | "go_goroutines{instance=\"app:8081\", job=\"codely\"}": "purple" 426 | }, 427 | "bars": false, 428 | "dashLength": 10, 429 | "dashes": false, 430 | "datasource": null, 431 | "fieldConfig": { 432 | "defaults": { 433 | "custom": {} 434 | }, 435 | "overrides": [] 436 | }, 437 | "fill": 1, 438 | "fillGradient": 0, 439 | "gridPos": { 440 | "h": 10, 441 | "w": 12, 442 | "x": 12, 443 | "y": 6 444 | }, 445 | "hiddenSeries": false, 446 | "id": 8, 447 | "legend": { 448 | "avg": false, 449 | "current": false, 450 | "max": false, 451 | "min": false, 452 | "show": true, 453 | "total": false, 454 | "values": false 455 | }, 456 | "lines": true, 457 | "linewidth": 1, 458 | "nullPointMode": "null", 459 | "options": { 460 | "dataLinks": [] 461 | }, 462 | "percentage": false, 463 | "pointradius": 2, 464 | "points": false, 465 | "renderer": "flot", 466 | "seriesOverrides": [], 467 | "spaceLength": 10, 468 | "stack": false, 469 | "steppedLine": false, 470 | "targets": [ 471 | { 472 | "expr": "go_goroutines{job=\"codely\"}", 473 | "interval": "", 474 | "legendFormat": "", 475 | "refId": "A" 476 | } 477 | ], 478 | "thresholds": [], 479 | "timeFrom": null, 480 | "timeRegions": [], 481 | "timeShift": null, 482 | "title": "Go Routines", 483 | "tooltip": { 484 | "shared": true, 485 | "sort": 0, 486 | "value_type": "individual" 487 | }, 488 | "type": "graph", 489 | "xaxis": { 490 | "buckets": null, 491 | "mode": "time", 492 | "name": null, 493 | "show": true, 494 | "values": [] 495 | }, 496 | "yaxes": [ 497 | { 498 | "format": "short", 499 | "label": null, 500 | "logBase": 1, 501 | "max": null, 502 | "min": null, 503 | "show": true 504 | }, 505 | { 506 | "format": "short", 507 | "label": null, 508 | "logBase": 1, 509 | "max": null, 510 | "min": null, 511 | "show": true 512 | } 513 | ], 514 | "yaxis": { 515 | "align": false, 516 | "alignLevel": null 517 | } 518 | } 519 | ], 520 | "refresh": "5s", 521 | "schemaVersion": 25, 522 | "style": "dark", 523 | "tags": [], 524 | "templating": { 525 | "list": [] 526 | }, 527 | "time": { 528 | "from": "now-1h", 529 | "to": "now" 530 | }, 531 | "timepicker": { 532 | "refresh_intervals": [ 533 | "10s", 534 | "30s", 535 | "1m", 536 | "5m", 537 | "15m", 538 | "30m", 539 | "1h", 540 | "2h", 541 | "1d" 542 | ] 543 | }, 544 | "timezone": "", 545 | "title": "Codely Dashboard", 546 | "uid": "_nvdxP7Gz", 547 | "version": 1 548 | } -------------------------------------------------------------------------------- /5.2-grafana-dashboard/etc/grafana/provisioning/datasources/datasource.yml: -------------------------------------------------------------------------------- 1 | apiVersion: 1 2 | 3 | datasources: 4 | 5 | - name: Prometheus 6 | type: prometheus 7 | access: proxy 8 | orgId: 1 9 | url: http://prometheus:9090 10 | basicAuth: false 11 | isDefault: true -------------------------------------------------------------------------------- /5.2-grafana-dashboard/etc/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | evaluation_interval: 15s 4 | external_labels: 5 | monitor: 'codely-app' 6 | 7 | scrape_configs: 8 | 9 | - job_name: 'prometheus' 10 | scrape_interval: 5s 11 | static_configs: 12 | - targets: ['localhost:9090'] 13 | 14 | - job_name: 'codely' 15 | scrape_interval: 5s 16 | static_configs: 17 | - targets: ['app:8081'] 18 | 19 | - job_name: 'cadvisor' 20 | scrape_interval: 5s 21 | static_configs: 22 | - targets: ['cadvisor:8080'] 23 | -------------------------------------------------------------------------------- /6.3-alert-manager/.gitignore: -------------------------------------------------------------------------------- 1 | var 2 | main 3 | -------------------------------------------------------------------------------- /6.3-alert-manager/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:latest AS builder 2 | ADD ./app /app 3 | WORKDIR /app 4 | RUN go mod download 5 | RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o /main . 6 | 7 | FROM alpine:latest 8 | RUN apk --no-cache add ca-certificates 9 | COPY --from=builder /main ./ 10 | RUN chmod +x ./main 11 | ENTRYPOINT ["./main"] 12 | EXPOSE 80 -------------------------------------------------------------------------------- /6.3-alert-manager/app/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rubencougil/geekshubs/prometheus/app 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.6.3 7 | github.com/prometheus/client_golang v1.2.1 8 | github.com/zsais/go-gin-prometheus v0.1.0 9 | ) 10 | -------------------------------------------------------------------------------- /6.3-alert-manager/app/go.sum: -------------------------------------------------------------------------------- 1 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 2 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 3 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 4 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 5 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 6 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 7 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 8 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 9 | github.com/cespare/xxhash/v2 v2.1.0 h1:yTUvW7Vhb89inJ+8irsUqiWjh8iT6sQPZiQzI6ReGkA= 10 | github.com/cespare/xxhash/v2 v2.1.0/go.mod h1:dgIUBU3pDso/gPgZ1osOZ0iQf77oPR28Tjxl5dIMyVM= 11 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 13 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 14 | github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= 15 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= 16 | github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= 17 | github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= 18 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 19 | github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 20 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 21 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 22 | github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= 23 | github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= 24 | github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= 25 | github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= 26 | github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= 27 | github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= 28 | github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= 29 | github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= 30 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 31 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 32 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 33 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 34 | github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= 35 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 36 | github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= 37 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 38 | github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= 39 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 40 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 41 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 42 | github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 43 | github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= 44 | github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 45 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 46 | github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= 47 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 48 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 49 | github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= 50 | github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= 51 | github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= 52 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 53 | github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= 54 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 55 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 56 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= 57 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 58 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 59 | github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= 60 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 61 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 62 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 63 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 64 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 65 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 66 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 67 | github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= 68 | github.com/prometheus/client_golang v1.2.1 h1:JnMpQc6ppsNgw9QPAGF6Dod479itz7lvlsMzzNayLOI= 69 | github.com/prometheus/client_golang v1.2.1/go.mod h1:XMU6Z2MjaRKVu/dC1qupJI9SiNkDYzz3xecMgSW/F+U= 70 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 71 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 72 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= 73 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 74 | github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 75 | github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY= 76 | github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= 77 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 78 | github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 79 | github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= 80 | github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= 81 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 82 | github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= 83 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 84 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 85 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 86 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 87 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 88 | github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= 89 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 90 | github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= 91 | github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= 92 | github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= 93 | github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= 94 | github.com/zsais/go-gin-prometheus v0.1.0 h1:bkLv1XCdzqVgQ36ScgRi09MA2UC1t3tAB6nsfErsGO4= 95 | github.com/zsais/go-gin-prometheus v0.1.0/go.mod h1:Slirjzuz8uM8Cw0jmPNqbneoqcUtY2GGjn2bEd4NRLY= 96 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 97 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 98 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 99 | golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 100 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 101 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 102 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 103 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 104 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 105 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 106 | golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY= 107 | golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 108 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= 109 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 110 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 111 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 112 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 113 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 114 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 115 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 116 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 117 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 118 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 119 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 120 | -------------------------------------------------------------------------------- /6.3-alert-manager/app/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "github.com/gin-gonic/gin" 7 | "github.com/prometheus/client_golang/prometheus" 8 | "github.com/prometheus/client_golang/prometheus/promauto" 9 | ginprometheus "github.com/zsais/go-gin-prometheus" 10 | "log" 11 | "math/rand" 12 | "time" 13 | ) 14 | 15 | var addr = flag.String("listen-address", ":8081", "The address to listen on for HTTP requests.") 16 | 17 | var ( 18 | c = promauto.NewCounter(prometheus.CounterOpts{ 19 | Name: "codely_app_sample_metric", 20 | Help: "Sample metric for Codely course", 21 | }) 22 | 23 | h = promauto.NewHistogram(prometheus.HistogramOpts{ 24 | Name: "codely_app_sample_histogram", 25 | Help: "Sample histogram for Codely course", 26 | }) 27 | 28 | d = promauto.NewCounterVec(prometheus.CounterOpts{ 29 | Name: "codely_app_sample_devices", 30 | Help: "Sample counter opts devices for Codely course"}, []string{"device"}) 31 | ) 32 | 33 | func main() { 34 | 35 | rand.Seed(time.Now().UnixNano()) 36 | r := gin.New() 37 | 38 | p := ginprometheus.NewPrometheus("http") 39 | p.Use(r) 40 | 41 | r.GET("/", func(c *gin.Context) { 42 | 43 | time.Sleep(time.Duration(rand.Intn(500)) * time.Millisecond) 44 | 45 | switch rand.Intn(6) { 46 | case 0: c.JSON(200, "Hello world!") 47 | case 1: c.JSON(404, "Not Found!") 48 | case 2: c.JSON(500, "Oops!") 49 | case 3: c.JSON(401, "Unauthorized!") 50 | case 4: c.JSON(403, "Forbidden!") 51 | case 5: c.JSON(408, "Timeout!") 52 | default: 53 | c.JSON(200, "Hello world!") 54 | } 55 | }) 56 | 57 | go func() { 58 | for { 59 | rand.Seed(time.Now().UnixNano()) 60 | h.Observe(float64(rand.Intn(100-0+1) + 0)) 61 | d.With(prometheus.Labels{"device":"/dev/sda"}).Inc() 62 | c.Inc() 63 | fmt.Print(".") 64 | time.Sleep(1 * time.Second) 65 | } 66 | }() 67 | 68 | log.Fatal(r.Run(*addr)) 69 | } 70 | -------------------------------------------------------------------------------- /6.3-alert-manager/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | services: 3 | 4 | prometheus: 5 | image: prom/prometheus:v2.19.0 6 | volumes: 7 | - "./etc/prometheus/:/etc/prometheus/" 8 | - "./var/prometheus/prometheus_data:/prometheus" 9 | - "./etc/prometheus/alertmanager/:/etc/alertmanager/" 10 | command: 11 | - '--config.file=/etc/prometheus/prometheus.yml' 12 | - '--storage.tsdb.path=/prometheus' 13 | - '--web.console.libraries=/usr/share/prometheus/console_libraries' 14 | - '--web.console.templates=/usr/share/prometheus/consoles' 15 | ports: 16 | - 9090:9090 17 | 18 | app: 19 | build: . 20 | restart: always 21 | ports: 22 | - 8081:8081 23 | depends_on: 24 | - prometheus 25 | 26 | alertmanager: 27 | image: prom/alertmanager 28 | ports: 29 | - 9093:9093 30 | volumes: 31 | - "./etc/prometheus/alertmanager/:/etc/alertmanager/" 32 | command: 33 | - '--config.file=/etc/alertmanager/config.yml' 34 | - '--storage.path=/alertmanager' -------------------------------------------------------------------------------- /6.3-alert-manager/etc/prometheus/alertmanager/config.yml: -------------------------------------------------------------------------------- 1 | route: 2 | receiver: 'pager' 3 | 4 | receivers: 5 | - name: 'pager' 6 | webhook_configs: 7 | - url: https://avisa.me 8 | -------------------------------------------------------------------------------- /6.3-alert-manager/etc/prometheus/alertmanager/rules.yml: -------------------------------------------------------------------------------- 1 | groups: 2 | - name: pager 3 | rules: 4 | 5 | - alert: http_errors_gt_50% 6 | expr: sum(rate(http_requests_total{code!="200"}[1m])) / sum(rate(http_requests_total[1m])) * 100 > 50 7 | for: 1m 8 | labels: 9 | severity: critical 10 | annotations: 11 | summary: "HTTP Status Error Code {{ $labels.code }} for {{ $labels.instance }} is > 50% of total HTTP Responses" 12 | description: "Error Code {{ $labels.code }} at {{ $labels.instance }} of job {{ $labels.job }} is > 50%" -------------------------------------------------------------------------------- /6.3-alert-manager/etc/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | evaluation_interval: 15s 4 | external_labels: 5 | monitor: 'codely-app' 6 | 7 | scrape_configs: 8 | 9 | - job_name: 'prometheus' 10 | scrape_interval: 5s 11 | static_configs: 12 | - targets: ['localhost:9090'] 13 | 14 | - job_name: 'codely' 15 | scrape_interval: 5s 16 | static_configs: 17 | - targets: ['app:8081'] 18 | 19 | - job_name: 'alertmanager' 20 | scrape_interval: 5s 21 | static_configs: 22 | - targets: ['alertmanager:9093'] 23 | 24 | rule_files: 25 | - "/etc/prometheus/alertmanager/rules.yml" 26 | 27 | alerting: 28 | alertmanagers: 29 | - scheme: http 30 | static_configs: 31 | - targets: 32 | - "alertmanager:9093" -------------------------------------------------------------------------------- /7.1-prometheus-k8s/Makefile: -------------------------------------------------------------------------------- 1 | # Usamos Helm para realizar un deploy de Prometheus y Grafana en nuestro cluster K8S local 2 | # Además levantaremos una instancia de la App de ejemplo en Go 3 | install: 4 | @helm install --name prometheus --set-file extraScrapeConfigs=prometheus/extraScrapeConfigs.yaml stable/prometheus 5 | @helm install --name grafana stable/grafana 6 | @helm install --name app app 7 | 8 | # Para publicar el puerto de Prometheus en el Host y poder acceder desde http://localhost:9090 9 | forward-prometheus: 10 | @kubectl port-forward svc/prometheus-server 9090:80 11 | 12 | # Para publicar el puerto de Grafana en el Host y poder acceder desde http://localhost:8080 13 | # Para conseguir las credenciales de usuario `admin` usa `make grafana-get-password` 14 | forward-grafana: 15 | @kubectl port-forward svc/grafana 8080:80 16 | 17 | # Para publicar el puerto de la App en el Host y poder acceder desde http://localhost:8081 18 | # Para publicar el puerto de la App en el Host y poder acceder desde http://localhost:8081 19 | forward-app: 20 | @kubectl port-forward svc/app 8081:8081 21 | 22 | # El password de `admin` se genera de forma aleatoria y se guarda como secret 23 | grafana-get-password: 24 | @kubectl get secret grafana -o jsonpath="{.data.admin-password}" | base64 --decode; echo 25 | 26 | # Para los servicios 27 | stop: 28 | @helm delete --purge prometheus 29 | @helm delete --purge grafana 30 | @helm delete --purge app -------------------------------------------------------------------------------- /7.1-prometheus-k8s/app/.helmignore: -------------------------------------------------------------------------------- 1 | # Patterns to ignore when building packages. 2 | # This supports shell glob matching, relative path matching, and 3 | # negation (prefixed with !). Only one pattern per line. 4 | .DS_Store 5 | # Common VCS dirs 6 | .git/ 7 | .gitignore 8 | .bzr/ 9 | .bzrignore 10 | .hg/ 11 | .hgignore 12 | .svn/ 13 | # Common backup files 14 | *.swp 15 | *.bak 16 | *.tmp 17 | *~ 18 | # Various IDEs 19 | .project 20 | .idea/ 21 | *.tmproj 22 | .vscode/ 23 | -------------------------------------------------------------------------------- /7.1-prometheus-k8s/app/Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | appVersion: "1.0" 3 | description: A Helm chart for Kubernetes 4 | name: app 5 | version: 0.1.0 6 | -------------------------------------------------------------------------------- /7.1-prometheus-k8s/app/templates/NOTES.txt: -------------------------------------------------------------------------------- 1 | 1. Get the application URL by running these commands: 2 | {{- if .Values.ingress.enabled }} 3 | {{- range $host := .Values.ingress.hosts }} 4 | {{- range .paths }} 5 | http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }} 6 | {{- end }} 7 | {{- end }} 8 | {{- else if contains "NodePort" .Values.service.type }} 9 | export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "app.fullname" . }}) 10 | export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") 11 | echo http://$NODE_IP:$NODE_PORT 12 | {{- else if contains "LoadBalancer" .Values.service.type }} 13 | NOTE: It may take a few minutes for the LoadBalancer IP to be available. 14 | You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "app.fullname" . }}' 15 | export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "app.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") 16 | echo http://$SERVICE_IP:{{ .Values.service.port }} 17 | {{- else if contains "ClusterIP" .Values.service.type }} 18 | export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "app.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") 19 | echo "Visit http://127.0.0.1:8080 to use your application" 20 | kubectl port-forward $POD_NAME 8080:80 21 | {{- end }} 22 | -------------------------------------------------------------------------------- /7.1-prometheus-k8s/app/templates/_helpers.tpl: -------------------------------------------------------------------------------- 1 | {{/* vim: set filetype=mustache: */}} 2 | {{/* 3 | Expand the name of the chart. 4 | */}} 5 | {{- define "app.name" -}} 6 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} 7 | {{- end -}} 8 | 9 | {{/* 10 | Create a default fully qualified app name. 11 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). 12 | If release name contains chart name it will be used as a full name. 13 | */}} 14 | {{- define "app.fullname" -}} 15 | {{- if .Values.fullnameOverride -}} 16 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} 17 | {{- else -}} 18 | {{- $name := default .Chart.Name .Values.nameOverride -}} 19 | {{- if contains $name .Release.Name -}} 20 | {{- .Release.Name | trunc 63 | trimSuffix "-" -}} 21 | {{- else -}} 22 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} 23 | {{- end -}} 24 | {{- end -}} 25 | {{- end -}} 26 | 27 | {{/* 28 | Create chart name and version as used by the chart label. 29 | */}} 30 | {{- define "app.chart" -}} 31 | {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} 32 | {{- end -}} 33 | 34 | {{/* 35 | Common labels 36 | */}} 37 | {{- define "app.labels" -}} 38 | app.kubernetes.io/name: {{ include "app.name" . }} 39 | helm.sh/chart: {{ include "app.chart" . }} 40 | app.kubernetes.io/instance: {{ .Release.Name }} 41 | {{- if .Chart.AppVersion }} 42 | app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} 43 | {{- end }} 44 | app.kubernetes.io/managed-by: {{ .Release.Service }} 45 | {{- end -}} 46 | 47 | {{/* 48 | Create the name of the service account to use 49 | */}} 50 | {{- define "app.serviceAccountName" -}} 51 | {{- if .Values.serviceAccount.create -}} 52 | {{ default (include "app.fullname" .) .Values.serviceAccount.name }} 53 | {{- else -}} 54 | {{ default "default" .Values.serviceAccount.name }} 55 | {{- end -}} 56 | {{- end -}} 57 | -------------------------------------------------------------------------------- /7.1-prometheus-k8s/app/templates/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: {{ include "app.fullname" . }} 5 | labels: 6 | {{ include "app.labels" . | indent 4 }} 7 | spec: 8 | replicas: {{ .Values.replicaCount }} 9 | selector: 10 | matchLabels: 11 | app.kubernetes.io/name: {{ include "app.name" . }} 12 | app.kubernetes.io/instance: {{ .Release.Name }} 13 | template: 14 | metadata: 15 | labels: 16 | app.kubernetes.io/name: {{ include "app.name" . }} 17 | app.kubernetes.io/instance: {{ .Release.Name }} 18 | spec: 19 | {{- with .Values.imagePullSecrets }} 20 | imagePullSecrets: 21 | {{- toYaml . | nindent 8 }} 22 | {{- end }} 23 | serviceAccountName: {{ template "app.serviceAccountName" . }} 24 | securityContext: 25 | {{- toYaml .Values.podSecurityContext | nindent 8 }} 26 | containers: 27 | - name: {{ .Chart.Name }} 28 | securityContext: 29 | {{- toYaml .Values.securityContext | nindent 12 }} 30 | image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" 31 | imagePullPolicy: {{ .Values.image.pullPolicy }} 32 | ports: 33 | - name: http 34 | containerPort: 8081 35 | protocol: TCP 36 | resources: 37 | {{- toYaml .Values.resources | nindent 12 }} 38 | {{- with .Values.nodeSelector }} 39 | nodeSelector: 40 | {{- toYaml . | nindent 8 }} 41 | {{- end }} 42 | {{- with .Values.affinity }} 43 | affinity: 44 | {{- toYaml . | nindent 8 }} 45 | {{- end }} 46 | {{- with .Values.tolerations }} 47 | tolerations: 48 | {{- toYaml . | nindent 8 }} 49 | {{- end }} 50 | -------------------------------------------------------------------------------- /7.1-prometheus-k8s/app/templates/ingress.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.ingress.enabled -}} 2 | {{- $fullName := include "app.fullname" . -}} 3 | {{- $svcPort := .Values.service.port -}} 4 | {{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} 5 | apiVersion: networking.k8s.io/v1beta1 6 | {{- else -}} 7 | apiVersion: extensions/v1beta1 8 | {{- end }} 9 | kind: Ingress 10 | metadata: 11 | name: {{ $fullName }} 12 | labels: 13 | {{ include "app.labels" . | indent 4 }} 14 | {{- with .Values.ingress.annotations }} 15 | annotations: 16 | {{- toYaml . | nindent 4 }} 17 | {{- end }} 18 | spec: 19 | {{- if .Values.ingress.tls }} 20 | tls: 21 | {{- range .Values.ingress.tls }} 22 | - hosts: 23 | {{- range .hosts }} 24 | - {{ . | quote }} 25 | {{- end }} 26 | secretName: {{ .secretName }} 27 | {{- end }} 28 | {{- end }} 29 | rules: 30 | {{- range .Values.ingress.hosts }} 31 | - host: {{ .host | quote }} 32 | http: 33 | paths: 34 | {{- range .paths }} 35 | - path: {{ . }} 36 | backend: 37 | serviceName: {{ $fullName }} 38 | servicePort: {{ $svcPort }} 39 | {{- end }} 40 | {{- end }} 41 | {{- end }} 42 | -------------------------------------------------------------------------------- /7.1-prometheus-k8s/app/templates/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: {{ include "app.fullname" . }} 5 | labels: 6 | {{ include "app.labels" . | indent 4 }} 7 | spec: 8 | type: {{ .Values.service.type }} 9 | ports: 10 | - port: {{ .Values.service.port }} 11 | targetPort: http 12 | protocol: TCP 13 | name: http 14 | selector: 15 | app.kubernetes.io/name: {{ include "app.name" . }} 16 | app.kubernetes.io/instance: {{ .Release.Name }} 17 | -------------------------------------------------------------------------------- /7.1-prometheus-k8s/app/templates/serviceaccount.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.serviceAccount.create -}} 2 | apiVersion: v1 3 | kind: ServiceAccount 4 | metadata: 5 | name: {{ template "app.serviceAccountName" . }} 6 | labels: 7 | {{ include "app.labels" . | indent 4 }} 8 | {{- end -}} 9 | -------------------------------------------------------------------------------- /7.1-prometheus-k8s/app/templates/tests/test-connection.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: "{{ include "app.fullname" . }}-test-connection" 5 | labels: 6 | {{ include "app.labels" . | indent 4 }} 7 | annotations: 8 | "helm.sh/hook": test-success 9 | spec: 10 | containers: 11 | - name: wget 12 | image: busybox 13 | command: ['wget'] 14 | args: ['{{ include "app.fullname" . }}:{{ .Values.service.port }}'] 15 | restartPolicy: Never 16 | -------------------------------------------------------------------------------- /7.1-prometheus-k8s/app/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for app. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | replicaCount: 1 6 | 7 | image: 8 | repository: rcougil/prometheus-go-simple-app 9 | tag: latest 10 | pullPolicy: IfNotPresent 11 | 12 | imagePullSecrets: [] 13 | nameOverride: "" 14 | fullnameOverride: "" 15 | 16 | serviceAccount: 17 | # Specifies whether a service account should be created 18 | create: true 19 | # The name of the service account to use. 20 | # If not set and create is true, a name is generated using the fullname template 21 | name: 22 | 23 | podSecurityContext: {} 24 | # fsGroup: 2000 25 | 26 | securityContext: {} 27 | # capabilities: 28 | # drop: 29 | # - ALL 30 | # readOnlyRootFilesystem: true 31 | # runAsNonRoot: true 32 | # runAsUser: 1000 33 | 34 | service: 35 | type: ClusterIP 36 | port: 8081 37 | 38 | ingress: 39 | enabled: false 40 | annotations: {} 41 | # kubernetes.io/ingress.class: nginx 42 | # kubernetes.io/tls-acme: "true" 43 | hosts: 44 | - host: chart-example.local 45 | paths: [] 46 | 47 | tls: [] 48 | # - secretName: chart-example-tls 49 | # hosts: 50 | # - chart-example.local 51 | 52 | resources: {} 53 | # We usually recommend not to specify default resources and to leave this as a conscious 54 | # choice for the user. This also increases chances charts run on environments with little 55 | # resources, such as Minikube. If you do want to specify resources, uncomment the following 56 | # lines, adjust them as necessary, and remove the curly braces after 'resources:'. 57 | # limits: 58 | # cpu: 100m 59 | # memory: 128Mi 60 | # requests: 61 | # cpu: 100m 62 | # memory: 128Mi 63 | 64 | nodeSelector: {} 65 | 66 | tolerations: [] 67 | 68 | affinity: {} 69 | -------------------------------------------------------------------------------- /7.1-prometheus-k8s/prometheus/extraScrapeConfigs.yaml: -------------------------------------------------------------------------------- 1 | - job_name: 'app' 2 | scrape_interval: 5s 3 | static_configs: 4 | - targets: ["app:8081"] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # curso-prometheus 2 | --------------------------------------------------------------------------------