This file contains hidden or 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
| #!/bin/bash | |
| { | |
| echo -e "NAMESPACE\tPOD\tCPU_REQ(m)\tCPU_USAGE(m)\tMEM_REQ(Mi)\tMEM_USAGE(Mi)" | |
| for ns in <NAMESPACE1> <NAMESPACE2>; do | |
| kubectl top pods -n "$ns" --no-headers | while read pod cpu_usage mem_usage; do | |
| cpu_req=$(kubectl get pod "$pod" -n "$ns" -o jsonpath='{.spec.containers[*].resources.requests.cpu}' | \ | |
| awk '{sum=0; for(i=1;i<=NF;i++) { val=$i; if(val ~ /m$/) {val=val+0} else {val=val*1000} sum+=val;} print sum}') | |
| mem_req=$(kubectl get pod "$pod" -n "$ns" -o jsonpath='{.spec.containers[*].resources.requests.memory}' | \ | |
| awk '{sum=0; for(i=1;i<=NF;i++) { val=$i; if(val ~ /Mi$/) {val=val+0} else if(val ~ /Ki$/) {val=val/1024} else if(val ~ /Gi$/) {val=val*1024} sum+=val;} print sum}') |
This file contains hidden or 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
| #!/bin/sh | |
| export IMAGE=<YOUR CONTAINER IMAGE> | |
| echo $(docker inspect --format '{{range $key,$value := .Config.Labels}}{{$key}}={{$value}}\n{{end}}' ${IMAGE}) | |
| ##alternative using jq | |
| docker inspect ${IMAGE}) |jq -r '.[0].Config.Labels' |
This file contains hidden or 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
| Doc. https://repost.aws/knowledge-center/eks-get-control-plane-logs | |
| ## get all events related with a specific object | |
| fields @timestamp, user.username as user,userAgent, verb as action, objectRef.namespace as namespace, objectRef.resource as kind , objectRef.name as name, responseStatus.code as exit_code, responseObject.status as exit_status, responseObject.message as exit_message | |
| | filter @logStream like /^kube-apiserver-audit/ | |
| | filter strcontains(objectRef.name,"coredns") | |
| | filter strcontains(objectRef.resource,"pod") | |
| | sort @timestamp desc | |
| ## get events kubectl update resource |
This file contains hidden or 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
| #Doc. https://repost.aws/knowledge-center/vpc-flow-logs-and-cloudwatch-logs-insights | |
| fields @timestamp, srcAddr, dstAddr, dstPort, action | |
| | sort @timestamp desc | |
| | filter srcAddr="10.89.6.237" | |
| | filter dstPort="443" |
This file contains hidden or 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
| #!/bin/sh | |
| ACCOUNT_ID=<AWS ACCOUNT ID> | |
| REGION=eu-west-1 | |
| REGISTRY=${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com | |
| aws ecr get-login-password| jq -n --arg token "$(</dev/stdin)" --arg repo "$REPO" '{"auths":{($repo):{"auth":$token}}}' > ~/.docker/config.json |
This file contains hidden or 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
| #!/bin/ssh | |
| # doc. https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28 | |
| GITHUB_TOKEN=<YOUR GITHUB TOKEN> | |
| OWNER=<GITHUB REPO OWNER> | |
| REPO=<GITHUB REPO NAME> | |
| for CACHE_ID in $(curl -L -X GET -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "X-GitHub-Api-Version: 2022-11-28" "https://api.github.com/repos/${OWNER}/${REPO}/actions/caches?per_page=100" |jq '.actions_caches[].id');do curl -I -X DELETE -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "X-GitHub-Api-Version: 2022-11-28" "https://api.github.com/repos/${OWNER}/${REPO}/actions/caches/$CACHE_ID";done |
This file contains hidden or 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
| #!/bin/sh | |
| # doc. https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#get-a-release-asset | |
| GITHUB_TOKEN=<YOUR GITHUB TOKEN> | |
| OWNER=<GITHUB REPO OWNER> | |
| REPO=<GITHUB REPO NAME> | |
| VERSION=<GITHUB RELEASE VERSION> | |
| ASSET_URL=$(wget --quiet -O - \ | |
| --header="Accept: application/vnd.github+json" \ |
This file contains hidden or 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
| #!/bin/sh | |
| #Doc. https://helm.sh/docs/topics/registries/#using-an-oci-based-registry | |
| CHART_REPO=<HELM CHART REPO NAME> | |
| ACCOUNT_ID=<AWS ACCOUNT ID> | |
| REGION=eu-west-1 | |
| REGISTRY=${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com | |
| #helm login | |
| aws ecr get-login-password | helm registry login --username AWS --password-stdin ${REGISTRY} |
This file contains hidden or 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
| #!/bin/sh | |
| COMMIT_1=$1 | |
| COMMIT_2=$2 | |
| count_lines () { | |
| git checkout $1 2>/dev/null && git ls-files | xargs wc -l |tail -1 |awk '{print $1}' | |
| } | |
| LINES_1=$(count_lines ${COMMIT_1}) | |
| LINES_2=$(count_lines ${COMMIT_2}) |
This file contains hidden or 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
| ## get targets from API | |
| # https://prometheus.io/docs/prometheus/latest/querying/api/#targets | |
| wget -qO- http://127.0.0.1:9090/api/v1/targets |jq -r '.data.activeTargets[].discoveredLabels.instance' | |
| ## get metrics | |
| # https://prometheus.io/docs/prometheus/latest/querying/api/#querying-label-values | |
| wget -qO- http://127.0.0.1:9090/api/v1/label/__name__/values | jq -r ".data[]" | sort | |
| ## get metric data. | |
| # https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries | |
| wget -qO- http://127.0.0.1:9090/api/v1/query --data-urlencode 'query=<METRIC NAME>' |jq |
NewerOlder