Last active
July 20, 2022 10:07
-
-
Save vfarcic/838a3a716cd9eb3c1a539a8d404d2077 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: https://gist.github.com/838a3a716cd9eb3c1a539a8d404d2077 | |
###################################### | |
# Using Loki To Store And Query Logs # | |
###################################### | |
########################################################## | |
# Installing Loki, Grafana, Prometheus, And The Demo App # | |
########################################################## | |
# Docker Desktop (docker-3gb-2cpu.sh): https://gist.github.com/0fff4fe977b194f4e9208cde54c1aa3c | |
# Minikube (minikube.sh): https://gist.github.com/2a6e5ad588509f43baa94cbdf40d0d16 | |
# GKE (gke-simple-ingress.sh): https://gist.github.com/925653c9fbf8cce23c35eedcd57de86e | |
# EKS (eks-simple-ingress.sh): https://gist.github.com/2fc8fa1b7c6ca6b3fefafe78078b6006 | |
# AKS (aks-simple-ingress.sh): https://gist.github.com/e24b00a29c66d5478b4054065d9ea156 | |
git clone \ | |
https://github.com/vfarcic/devops-catalog-code.git | |
cd devops-catalog-code | |
git pull | |
cd monitoring | |
helm repo add loki \ | |
https://grafana.github.io/loki/charts | |
helm repo update | |
helm upgrade --install \ | |
loki loki/loki-stack \ | |
--namespace monitoring \ | |
--create-namespace \ | |
--version 2.1.1 \ | |
--wait | |
cat grafana-loki.yaml | |
helm repo add grafana \ | |
https://grafana.github.io/helm-charts | |
helm repo update | |
helm upgrade --install \ | |
grafana grafana/grafana \ | |
--namespace monitoring \ | |
--create-namespace \ | |
--version 6.21.2 \ | |
--values grafana-loki.yaml \ | |
--set ingress.hosts="{grafana.$INGRESS_HOST.nip.io}" \ | |
--wait | |
helm repo add prometheus \ | |
https://prometheus-community.github.io/helm-charts | |
helm repo update | |
helm upgrade --install \ | |
prometheus prometheus/prometheus \ | |
--namespace monitoring \ | |
--create-namespace \ | |
--version 15.1.2 \ | |
--wait | |
kubectl --namespace monitoring get pods | |
cd ../helm | |
helm repo add bitnami \ | |
https://charts.bitnami.com/bitnami | |
helm dependency update go-demo-9 | |
kubectl create namespace production | |
helm upgrade --install \ | |
go-demo-9 go-demo-9 \ | |
--namespace production \ | |
--wait \ | |
--timeout 10m | |
curl -H "Host: go-demo-9.acme.com" \ | |
"http://$INGRESS_HOST" | |
############################### | |
# Playing With The Loki Stack # | |
############################### | |
open http://grafana.$INGRESS_HOST.nip.io/explore | |
kubectl --namespace monitoring \ | |
get secret grafana \ | |
--output jsonpath="{.data.admin-password}" \ | |
| base64 --decode ; echo | |
# Query (uncomment) | |
# {job="production/go-demo-9-go-demo-9"} | |
# Query (uncomment) | |
# {job="production/go-demo-9-go-demo-9"} != "GET request to /" | |
############################### | |
# Exploring Loki Query Syntax # | |
############################### | |
# Query (uncomment) | |
# {job="production/go-demo-9-go-demo-9"} != "GET request to /" | |
# Query (uncomment) | |
# {job="kube-system/nginx-ingress-controller"} |= "example.com" != "200" | |
open http://grafana.$INGRESS_HOST.nip.io/dashboard/new | |
# Query (uncomment) | |
# topk(10, sum(rate({job=~".+"}[5m])) by (job)) | |
# Query (uncomment) | |
# topk(10, sum(rate({namespace!="kube-system"}[5m])) by (job)) | |
# Query (uncomment) | |
# topk(10, sum(rate(({namespace!="kube-system"} |= "error")[5m])) by (job)) | |
open http://grafana.$INGRESS_HOST.nip.io/explore | |
# Query (uncomment) | |
# {job="production/go-demo-9-go-demo-9"} |= "ERROR" | |
# Query (uncomment) | |
# sum(rate(http_server_resp_time_count[2m])) by(path) | |
export ADDR=http://go-demo-9-go-demo-9.production/demo/hello | |
kubectl run siege \ | |
--image yokogawa/siege \ | |
-it --rm \ | |
-- --concurrent 10 --time 30S "$ADDR" | |
export ADDR=http://go-demo-9-go-demo-9.production/demo/random-error | |
kubectl run siege \ | |
--image yokogawa/siege \ | |
-it --rm \ | |
-- --concurrent 10 --time 30S "$ADDR" | |
############################ | |
# Destroying The Resources # | |
############################ | |
helm --namespace monitoring \ | |
delete grafana loki prometheus | |
helm --namespace production \ | |
delete go-demo-9 | |
kubectl delete namespace monitoring | |
kubectl delete namespace production | |
cd ../../ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment