go control docker
https://blog.kowalczyk.info/article/w4re/using-mysql-in-docker-for-local-testing-in-go.html
https://github.com/kjk/go-cookbook/tree/master/start-mysql-in-docker-go
https://github.com/kjk/go-cookbook/tree/master/start-mysql-in-docker-go
[轉]谁吃了我的Linux内存?
http://colobu.com/2017/03/07/what-is-in-linux-cached/#more
slabtop -s c
pcstat
slabtop -s c
======================
https://github.com/tobert/pcstat
#!/bin/bash#you have to install pcstatif [ ! -f /data0/brokerproxy/pcstat ]thenecho "You haven't installed pcstat yet"echo "run \"go get github.com/tobert/pcstat\" to install"exitfi#find the top 10 processs' cache fileps -e -o pid,rss|sort -nk2 -r|head -10 |awk '{print $1}'>/tmp/cache.pids#find all the processs' cache file#ps -e -o pid>/tmp/cache.pidsif [ -f /tmp/cache.files ]thenecho "the cache.files is exist, removing now "rm -f /tmp/cache.filesfiwhile read linedolsof -p $line 2>/dev/null|awk '{print $9}' >>/tmp/cache.filesdone</tmp/cache.pidsif [ -f /tmp/cache.pcstat ]thenecho "the cache.pcstat is exist, removing now"rm -f /tmp/cache.pcstatfifor i in `cat /tmp/cache.files`doif [ -f $i ]thenecho $i >>/tmp/cache.pcstatfidone/data0/brokerproxy/pcstat `cat /tmp/cache.pcstat`rm -f /tmp/cache.{pids,files,pcstat}
go aws ec2 control
package main
import (
"fmt"
"log"
"net/http"
"io/ioutil"
"github.com/gorilla/mux"
"github.com/smartystreets/go-aws-auth"
)
func stopEC2InstanceHandler(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
w.Write([]byte(fmt.Sprintf("stopEC2InstanceHandler: %v \n\n", vars["id"])))
var Action = "StopInstances" //check aws website
var Version = "2016-11-15" //need to check api version from aws website
//regoin need to check url from aws website. ex: ap-northeast-2
//some region no support some action
apiUrl := "https://ec2.ap-northeast-2.amazonaws.com/?Action=" + Action + "&Version=" + Version + "&InstanceId.1=" + vars["id"]
client := new(http.Client)
req, err := http.NewRequest("GET", apiUrl, nil)
aws_secret_access_key := "ooooooxxxxxxx"
aws_access_key_id := "ooooooxxxxxxx"
awsauth.Sign(req, awsauth.Credentials{
AccessKeyID: aws_access_key_id,
SecretAccessKey: aws_secret_access_key,
//SecurityToken: "", // STS (optional)
})
//awsauth.Sign(req) // Automatically chooses the best signing mechanism for the service
resp, err := client.Do(req)
fmt.Printf("\n\nGet = |%#v|, |%v|\n\n", resp, err)
if err != nil {
fmt.Println(err)
}
if resp == nil {
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(body))
w.Write([]byte(body))
}
func main() {
r := mux.NewRouter()
r.HandleFunc("/stopEC2InstanceHandler/{id}", stopEC2InstanceHandler).Methods("GET")
fmt.Println("Endpoint Hit: ./")
log.Fatal(http.ListenAndServe(":8080", r))
}
======================Then========================
github.com/smartystreets/go-aws-auth HAVE bug for regoin, auto regoin can't v4
some just change source code
go\src\github.com\smartystreets\go-aws-auth\awsauth.go
func Sign
signVersion := awsSignVersion[service]
signVersion=4 //add this line in here. let api just use v4
Now ok to use this code.
訂閱:
文章 (Atom)