added getStats endpoint to api gateway
This commit is contained in:
parent
891e565117
commit
ac64ab54d4
@ -32,7 +32,31 @@ func getSchema(w http.ResponseWriter, r *http.Request){
|
|||||||
for _, container := range Containers {
|
for _, container := range Containers {
|
||||||
if container.Id == key {
|
if container.Id == key {
|
||||||
requestURL := fmt.Sprintf("http://%s:%s/schema", container.Name, container.port)
|
requestURL := fmt.Sprintf("http://%s:%s/schema", container.Name, container.port)
|
||||||
fmt.Fprintf(w, requestURL)
|
resp, err := http.Get(requestURL)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Request to container failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failed to print Body: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(w,string(body))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func getStats(w http.ResponseWriter, r *http.Request){
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
key := vars["container"]
|
||||||
|
|
||||||
|
for _, container := range Containers {
|
||||||
|
if container.Id == key {
|
||||||
|
requestURL := fmt.Sprintf("http://%s:%s/stats", container.Name, container.port)
|
||||||
resp, err := http.Get(requestURL)
|
resp, err := http.Get(requestURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Request to container failed: %v", err)
|
log.Fatal("Request to container failed: %v", err)
|
||||||
@ -55,6 +79,7 @@ func handleRequests() {
|
|||||||
myRouter := mux.NewRouter().StrictSlash(true)
|
myRouter := mux.NewRouter().StrictSlash(true)
|
||||||
myRouter.HandleFunc("/", homePage)
|
myRouter.HandleFunc("/", homePage)
|
||||||
myRouter.HandleFunc("/{container}/schema", getSchema)
|
myRouter.HandleFunc("/{container}/schema", getSchema)
|
||||||
|
myRouter.HandleFunc("/{container}/stats", getStats)
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(":10000", myRouter))
|
log.Fatal(http.ListenAndServe(":10000", myRouter))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user