Skip to content

Instantly share code, notes, and snippets.

View jiang-wei's full-sized avatar
🏠
Working from home

Jiang Wei jiang-wei

🏠
Working from home
  • Toronto, Canada
View GitHub Profile
@jiang-wei
jiang-wei / decode-secret-yaml
Created June 2, 2020 13:33
Decode k8s secret yaml
#!/usr/bin/env python3
#############
# save to ~/bin/decode-secret-yaml
# chmod +x ~/bin/decode-secret-yaml
#
# usage:
# ~/bin/decode-secret-yaml foo.yaml
# kubectl get secret foo -o yaml | ~/bin/decode-secret-yaml
#################
@jiang-wei
jiang-wei / jslog
Last active March 20, 2020 15:12
decode json log of kubernetes log
#!/usr/bin/env python
#
# save to $PATH as "jslog"
# and use as:
# kubectl logs xxx | jslog
#
import sys
@jiang-wei
jiang-wei / Prometheus config for GKE
Last active October 22, 2019 18:24
Prometheus config for GKE
# cat prometheus.yaml
"alerting":
"alertmanagers":
- "kubernetes_sd_configs": # discovery of alert manager from EP in namespace monitoring
- "namespaces":
"names":
- "monitoring"
"role": "endpoints"
"path_prefix": "/"
"relabel_configs":
@jiang-wei
jiang-wei / Prometheus alert rules for GKE
Last active October 22, 2019 18:25
Prometheus alert rules for GKE
$ cat alerts.yaml
"groups":
- "name": "kubernetes-absent"
"rules":
- "alert": "AlertmanagerDown"
"annotations":
"message": "Alertmanager has disappeared from Prometheus target discovery."
"runbook_url": "https://github.com/kubernetes-monitoring/kubernetes-mixin/tree/master/runbook.md#alert-name-alertmanagerdown"
"expr": |
absent(up{job="alertmanager"} == 1)
@jiang-wei
jiang-wei / Prometheus Record Rules
Last active March 28, 2022 08:36
PromQL examples & explanation
这是从 GKE market place 里安装的Prometheus server 的 rules 配置
当做 rules 样例学习
$ cat rules.yaml
"groups":
- "name": "k8s.rules"
"rules":
- "expr": |
sum(rate(container_cpu_usage_seconds_total{job="cadvisor", image!=""}[5m])) by (namespace)
"record": "namespace:container_cpu_usage_seconds_total:sum_rate"
@jiang-wei
jiang-wei / keybase.md
Last active October 22, 2019 18:25
keybase identity

Keybase proof

I hereby claim:

  • I am jiang-wei on github.
  • I am wei_jiang (https://keybase.io/wei_jiang) on keybase.
  • I have a public key ASDqhgP4u5dw0bBrDACNgK9079KhOj7WTWN0eR3sf4Fw4go

To claim this, I am signing this object:

@jiang-wei
jiang-wei / Grafana Import Dashboard.py
Last active February 13, 2019 15:24
create Grafana dashboards by API
Don't use the API as described in http://docs.grafana.org/http_api/dashboard/
Use the undocumented `import` interface
* remove .dashboard.id
-----------------------
data = getDashboard(DA_API_URL, uid, daAuthHeader)
def createDashboard(apiUrl, uid, authHeader, data):
del data['meta']
data['overwrite'] = True
@jiang-wei
jiang-wei / deployment.yml
Last active February 11, 2019 20:17
K8S kill sidecar containers deployment args
containers:
- name: main
image: gcr.io/some/image:latest
command: ["/bin/bash", "-c"]
args:
- |
trap "touch /tmp/pod/main-terminated" EXIT
/my-batch-job/bin/main --config=/config/my-job-config.yaml
volumeMounts:
- mountPath: /tmp/pod
@jiang-wei
jiang-wei / selenium-example.side
Created August 17, 2018 16:37
selenium example
{
"id": "f0310b9c-3ed2-4b43-88f2-cf7fa1f6867a",
"name": "open google.ca",
"url": "https://www.google.ca",
"tests": [{
"id": "e9662b73-483b-4db9-9b84-b9a9652145b2",
"name": "Untitled",
"commands": [{
"id": "a2fffec4-2464-4d1b-a767-595da262e200",
"comment": "",
@jiang-wei
jiang-wei / WebDriverJs-example.js
Created August 17, 2018 15:45
WebDriverJs example
const {Builder, By, until} = require('selenium-webdriver');
let driver = new Builder()
.forBrowser('firefox')
.build();
driver.get('http://www.google.com/ncr');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnK')).click();
driver.wait(until.titleIs('webdriver - Google Search'), 1000);