Last active
August 7, 2018 08:35
-
-
Save p4tin/ab1c7b610f3c4a4b87226f5cf1e0b58c to your computer and use it in GitHub Desktop.
Influx Play
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
package main | |
import ( | |
"strings" | |
"net/http" | |
"fmt" | |
"time" | |
"io/ioutil" | |
"net/url" | |
) | |
func sendEventToInflux(severity string, cartId string, sterlingOrderId string, retries int) { | |
body := strings.NewReader(fmt.Sprintf(`orderfulfillment,host=server01,severity=%s,cartId=%s,sterling_order_number=%s retries=%d %d`, | |
severity, | |
cartId, | |
sterlingOrderId, | |
retries, | |
time.Now().UTC().UnixNano())) | |
req, err := http.NewRequest("POST", "http://localhost:8086/write?db=mydb", body) | |
if err != nil { | |
fmt.Println(err.Error()) | |
} | |
req.Header.Set("Content-Type", "application/x-www-form-urlencoded") | |
resp, err := http.DefaultClient.Do(req) | |
if err != nil { | |
fmt.Println(err.Error()) | |
} | |
var msg []byte | |
x, y := resp.Body.Read(msg) | |
fmt.Println(string(msg), x, y) | |
defer resp.Body.Close() | |
} | |
func queryDataForCartID(cartId string) { | |
queryStr := fmt.Sprintf("db=mydb&q=SELECT * FROM orderfulfillment where cart_id='%s'", cartId) | |
t := &url.URL{Path: queryStr} | |
queryUrl := "http://localhost:8086/query?pretty=true&" + t.String() | |
resp, err := http.Get(queryUrl) | |
if err != nil { | |
fmt.Println(err.Error()) | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
fmt.Println(err.Error()) | |
} else { | |
fmt.Println(string(body)) | |
} | |
} | |
func main() { | |
//sendEventToInflux("INFO", "abc124", "FB1233456", 1) | |
queryDataForCartID("abc124") | |
} |
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
brew install influxdb | |
docker run -p 8086:8086 -v influxdb:/var/lib/influxdb influxdb:alpine | |
curl -XPOST "http://localhost:8086/query" --data-urlencode "q=CREATE DATABASE mydb" | |
curl -XPOST "http://localhost:8086/write?db=mydb" -d 'cpu,host=server01,region=uswest load=42 1434055562000000000' | |
curl -XPOST "http://localhost:8086/write?db=mydb" -d 'cpu,host=server02,region=uswest load=78 1434055562000000000' | |
curl -XPOST "http://localhost:8086/write?db=mydb" -d 'cpu,host=server03,region=useast load=15.4 1434055562000000000' | |
curl -G "http://localhost:8086/query?pretty=true" --data-urlencode "db=mydb" --data-urlencode "q=SELECT mean(load) FROM cpu WHERE region='uswest'" | |
curl -G "http://localhost:8086/query?pretty=true" --data-urlencode "db=mydb" --data-urlencode "q=SELECT * FROM orderfulfillment WHERE cart_id='abc123'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
docker run -p 3000:3000 --name=grafana -e "GF_SERVER_ROOT_URL=http://localhost:3000" -e "GF_SECURITY_ADMIN_PASSWORD=admin" grafana/grafana