Skip to content

Instantly share code, notes, and snippets.

@Riebart
Last active June 27, 2018 03:44
Show Gist options
  • Save Riebart/cba122e9069a931bcfbf89788300110d to your computer and use it in GitHub Desktop.
Save Riebart/cba122e9069a931bcfbf89788300110d to your computer and use it in GitHub Desktop.
Ad hoc stuffing timeseries into InfluxDB for visualization with Grafana with subsecond resolution timestamps.
#!/bin/bash
influxId=$(docker run --rm -d -p 8086:8086 -p 2003:2003 -e INFLUXDB_GRAPHITE_ENABLED=true influxdb)
grafanaId=$(docker run --rm -d -p 3000:3000 grafana/grafana)
echo "Sleeping while the containers spool up..." >&2
sleep 10
influxIp=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${influxId})
curl -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE db"
dbFile="`uuidgen`"
echo -n '{"dashboard":{"annotations":{"list":[{"$$hashKey":"object:320","builtIn":1,"datasource":"-- Grafana --","enable":true,"hide":true,"iconColor":"rgba(0, 211, 255, 1)","name":"Annotations & Alerts","type":"dashboard"}]},"editable":true,"gnetId":null,"graphTooltip":0,"id":null,"links":[],"panels":[{"aliasColors":{},"bars":false,"dashLength":10,"dashes":false,"datasource":null,"fill":1,"gridPos":{"h":15,"w":24,"x":0,"y":0},"id":2,"legend":{"avg":false,"current":false,"max":false,"min":false,"show":true,"total":false,"values":false},"lines":true,"linewidth":1,"links":[],"nullPointMode":"null","percentage":false,"pointradius":5,"points":false,"renderer":"flot","seriesOverrides":[],"spaceLength":10,"stack":false,"steppedLine":false,"targets":[{"$$hashKey":"object:386","groupBy":[{"params":["series"],"type":"tag"}],"measurement":"metric","orderByTime":"ASC","policy":"default","refId":"A","resultFormat":"time_series","select":[[{"params":["value"],"type":"field"}]],"tags":[]}],"thresholds":[],"timeFrom":null,"timeShift":null,"title":"Data series","tooltip":{"shared":true,"sort":0,"value_type":"individual"},"type":"graph","xaxis":{"buckets":null,"mode":"time","name":null,"show":true,"values":[]},"yaxes":[{"format":"short","label":null,"logBase":1,"max":null,"min":null,"show":true},{"format":"short","label":null,"logBase":1,"max":null,"min":null,"show":true}],"yaxis":{"align":false,"alignLevel":null}}],"refresh":"5s","schemaVersion":16,"style":"dark","tags":[],"templating":{"list":[]},"time":{"from":"now-1m","to":"now"},"timepicker":{"refresh_intervals":["0.1s","1s","5s","10s","30s","1m"],"time_options":["5m","15m","1h","6h","12h","24h","2d","7d","30d"]},"timezone":"","title":"Data Viewport","uid":null,"version":3}}' > ${dbFile}.json
while [ true ]
do
curl -XPOST --data-binary @${dbFile}.json --header "Content-Type: applcation/json" http://admin:admin@localhost:3000/api/dashboards/db && break
sleep 1
done
rm ${dbFile}.json
dsFile="`uuidgen`"
echo -n '{
"orgId": 1,
"name": "Influx Contianer",
"type": "influxdb",
"typeLogoUrl": "",
"access": "proxy",
"url": "http://XXX.XXX.XXX.XXX:8086",
"password": "",
"user": "",
"database": "db",
"basicAuth": false,
"basicAuthUser": "",
"basicAuthPassword": "",
"withCredentials": false,
"isDefault": true,
"jsonData": {
"keepCookies": [],
"timeInterval": "0.0001s"
},
"secureJsonFields": {},
"version": 3,
"readOnly": false
}' | sed "s/XXX.XXX.XXX.XXX/${influxIp}/" > ${dsFile}.json
while [ true ]
do
curl -XPOST --data-binary @${dsFile}.json --header "Content-Type: applcation/json" http://admin:admin@localhost:3000/api/datasources && break
done
rm ${dsFile}.json
tag_key="series"
tag_value=1
cat - | while read line
do
echo "$line" | tr ',' '\n' | while read value
do
curl -XPOST 'http://localhost:8086/write?db=db' \
--data-binary "metric,${tag_key}=${tag_value} value=$value"
tag_value=$[tag_value+1]
done
done
# while [ true ]; do echo 1,2,3,4,5,10,0.`head -c 8 /dev/urandom | xxd -po | tr -dc '0-9' | head -c3`; sleep 0.5; done | bash do.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment