init commit
This commit is contained in:
		
							parent
							
								
									6cb7354007
								
							
						
					
					
						commit
						8ced474edb
					
				
							
								
								
									
										12
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								README.md
									
									
									
									
									
								
							| @ -1,2 +1,14 @@ | ||||
| # speedtest2influx | ||||
| 
 | ||||
| 
 | ||||
| This requires jq, curl, and speedtest-cli | ||||
| 
 | ||||
| ```apt install -y jq curl speedtest-cli``` | ||||
| 
 | ||||
| --- | ||||
| 
 | ||||
| Update the influx creds in the script then import the speedtest2influx.json into your dashboard. Make sure your data source is name Speedtest for this to work | ||||
| 
 | ||||
| --- | ||||
| 
 | ||||
| add ```0 * * * *       root    /path/to/speedtest2influx.sh``` to ```/etc/crontab``` | ||||
|  | ||||
							
								
								
									
										542
									
								
								speedtest2influx.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										542
									
								
								speedtest2influx.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,542 @@ | ||||
| { | ||||
|   "annotations": { | ||||
|     "list": [ | ||||
|       { | ||||
|         "builtIn": 1, | ||||
|         "datasource": "-- Grafana --", | ||||
|         "enable": true, | ||||
|         "hide": true, | ||||
|         "iconColor": "rgba(0, 211, 255, 1)", | ||||
|         "name": "Annotations & Alerts", | ||||
|         "target": { | ||||
|           "limit": 100, | ||||
|           "matchAny": false, | ||||
|           "tags": [], | ||||
|           "type": "dashboard" | ||||
|         }, | ||||
|         "type": "dashboard" | ||||
|       } | ||||
|     ] | ||||
|   }, | ||||
|   "editable": true, | ||||
|   "gnetId": null, | ||||
|   "graphTooltip": 0, | ||||
|   "id": 77, | ||||
|   "iteration": 1631825305930, | ||||
|   "links": [], | ||||
|   "panels": [ | ||||
|     { | ||||
|       "datasource": "Speedtest", | ||||
|       "fieldConfig": { | ||||
|         "defaults": { | ||||
|           "color": { | ||||
|             "mode": "palette-classic" | ||||
|           }, | ||||
|           "custom": { | ||||
|             "axisLabel": "", | ||||
|             "axisPlacement": "auto", | ||||
|             "barAlignment": 0, | ||||
|             "drawStyle": "line", | ||||
|             "fillOpacity": 0, | ||||
|             "gradientMode": "none", | ||||
|             "hideFrom": { | ||||
|               "legend": false, | ||||
|               "tooltip": false, | ||||
|               "viz": false | ||||
|             }, | ||||
|             "lineInterpolation": "linear", | ||||
|             "lineWidth": 1, | ||||
|             "pointSize": 5, | ||||
|             "scaleDistribution": { | ||||
|               "type": "linear" | ||||
|             }, | ||||
|             "showPoints": "always", | ||||
|             "spanNulls": true, | ||||
|             "stacking": { | ||||
|               "group": "A", | ||||
|               "mode": "none" | ||||
|             }, | ||||
|             "thresholdsStyle": { | ||||
|               "mode": "off" | ||||
|             } | ||||
|           }, | ||||
|           "mappings": [], | ||||
|           "thresholds": { | ||||
|             "mode": "absolute", | ||||
|             "steps": [ | ||||
|               { | ||||
|                 "color": "green", | ||||
|                 "value": null | ||||
|               }, | ||||
|               { | ||||
|                 "color": "red", | ||||
|                 "value": 80 | ||||
|               } | ||||
|             ] | ||||
|           }, | ||||
|           "unit": "binbps" | ||||
|         }, | ||||
|         "overrides": [] | ||||
|       }, | ||||
|       "gridPos": { | ||||
|         "h": 8, | ||||
|         "w": 12, | ||||
|         "x": 0, | ||||
|         "y": 0 | ||||
|       }, | ||||
|       "id": 2, | ||||
|       "options": { | ||||
|         "legend": { | ||||
|           "calcs": [], | ||||
|           "displayMode": "list", | ||||
|           "placement": "bottom" | ||||
|         }, | ||||
|         "tooltip": { | ||||
|           "mode": "single" | ||||
|         } | ||||
|       }, | ||||
|       "targets": [ | ||||
|         { | ||||
|           "groupBy": [ | ||||
|             { | ||||
|               "params": [ | ||||
|                 "$__interval" | ||||
|               ], | ||||
|               "type": "time" | ||||
|             }, | ||||
|             { | ||||
|               "params": [ | ||||
|                 "null" | ||||
|               ], | ||||
|               "type": "fill" | ||||
|             } | ||||
|           ], | ||||
|           "measurement": "download", | ||||
|           "orderByTime": "ASC", | ||||
|           "policy": "default", | ||||
|           "query": "SELECT mean(\"value\") FROM \"download\" WHERE (\"host\" =~ /^$server$/) AND $timeFilter GROUP BY time($__interval) fill(null)", | ||||
|           "rawQuery": false, | ||||
|           "refId": "A", | ||||
|           "resultFormat": "time_series", | ||||
|           "select": [ | ||||
|             [ | ||||
|               { | ||||
|                 "params": [ | ||||
|                   "value" | ||||
|                 ], | ||||
|                 "type": "field" | ||||
|               }, | ||||
|               { | ||||
|                 "params": [], | ||||
|                 "type": "mean" | ||||
|               } | ||||
|             ] | ||||
|           ], | ||||
|           "tags": [ | ||||
|             { | ||||
|               "key": "host", | ||||
|               "operator": "=~", | ||||
|               "value": "/^$server$/" | ||||
|             } | ||||
|           ] | ||||
|         } | ||||
|       ], | ||||
|       "title": "Download", | ||||
|       "type": "timeseries" | ||||
|     }, | ||||
|     { | ||||
|       "datasource": "Speedtest", | ||||
|       "fieldConfig": { | ||||
|         "defaults": { | ||||
|           "color": { | ||||
|             "mode": "palette-classic" | ||||
|           }, | ||||
|           "custom": { | ||||
|             "axisLabel": "", | ||||
|             "axisPlacement": "auto", | ||||
|             "barAlignment": 0, | ||||
|             "drawStyle": "line", | ||||
|             "fillOpacity": 0, | ||||
|             "gradientMode": "none", | ||||
|             "hideFrom": { | ||||
|               "legend": false, | ||||
|               "tooltip": false, | ||||
|               "viz": false | ||||
|             }, | ||||
|             "lineInterpolation": "linear", | ||||
|             "lineWidth": 1, | ||||
|             "pointSize": 5, | ||||
|             "scaleDistribution": { | ||||
|               "type": "linear" | ||||
|             }, | ||||
|             "showPoints": "always", | ||||
|             "spanNulls": true, | ||||
|             "stacking": { | ||||
|               "group": "A", | ||||
|               "mode": "none" | ||||
|             }, | ||||
|             "thresholdsStyle": { | ||||
|               "mode": "off" | ||||
|             } | ||||
|           }, | ||||
|           "mappings": [], | ||||
|           "thresholds": { | ||||
|             "mode": "absolute", | ||||
|             "steps": [ | ||||
|               { | ||||
|                 "color": "green", | ||||
|                 "value": null | ||||
|               }, | ||||
|               { | ||||
|                 "color": "red", | ||||
|                 "value": 80 | ||||
|               } | ||||
|             ] | ||||
|           }, | ||||
|           "unit": "binbps" | ||||
|         }, | ||||
|         "overrides": [] | ||||
|       }, | ||||
|       "gridPos": { | ||||
|         "h": 8, | ||||
|         "w": 12, | ||||
|         "x": 12, | ||||
|         "y": 0 | ||||
|       }, | ||||
|       "id": 3, | ||||
|       "options": { | ||||
|         "legend": { | ||||
|           "calcs": [], | ||||
|           "displayMode": "list", | ||||
|           "placement": "bottom" | ||||
|         }, | ||||
|         "tooltip": { | ||||
|           "mode": "single" | ||||
|         } | ||||
|       }, | ||||
|       "targets": [ | ||||
|         { | ||||
|           "groupBy": [ | ||||
|             { | ||||
|               "params": [ | ||||
|                 "$__interval" | ||||
|               ], | ||||
|               "type": "time" | ||||
|             }, | ||||
|             { | ||||
|               "params": [ | ||||
|                 "null" | ||||
|               ], | ||||
|               "type": "fill" | ||||
|             } | ||||
|           ], | ||||
|           "measurement": "upload", | ||||
|           "orderByTime": "ASC", | ||||
|           "policy": "default", | ||||
|           "query": "SELECT mean(\"value\") FROM \"download\" WHERE (\"host\" =~ /^$server$/) AND $timeFilter GROUP BY time($__interval) fill(null)", | ||||
|           "rawQuery": false, | ||||
|           "refId": "A", | ||||
|           "resultFormat": "time_series", | ||||
|           "select": [ | ||||
|             [ | ||||
|               { | ||||
|                 "params": [ | ||||
|                   "value" | ||||
|                 ], | ||||
|                 "type": "field" | ||||
|               }, | ||||
|               { | ||||
|                 "params": [], | ||||
|                 "type": "mean" | ||||
|               } | ||||
|             ] | ||||
|           ], | ||||
|           "tags": [ | ||||
|             { | ||||
|               "key": "host", | ||||
|               "operator": "=~", | ||||
|               "value": "/^$server$/" | ||||
|             } | ||||
|           ] | ||||
|         } | ||||
|       ], | ||||
|       "title": "Upload", | ||||
|       "type": "timeseries" | ||||
|     }, | ||||
|     { | ||||
|       "datasource": "Speedtest", | ||||
|       "fieldConfig": { | ||||
|         "defaults": { | ||||
|           "color": { | ||||
|             "mode": "palette-classic" | ||||
|           }, | ||||
|           "custom": { | ||||
|             "axisLabel": "", | ||||
|             "axisPlacement": "auto", | ||||
|             "barAlignment": 0, | ||||
|             "drawStyle": "line", | ||||
|             "fillOpacity": 0, | ||||
|             "gradientMode": "none", | ||||
|             "hideFrom": { | ||||
|               "legend": false, | ||||
|               "tooltip": false, | ||||
|               "viz": false | ||||
|             }, | ||||
|             "lineInterpolation": "linear", | ||||
|             "lineWidth": 1, | ||||
|             "pointSize": 5, | ||||
|             "scaleDistribution": { | ||||
|               "type": "linear" | ||||
|             }, | ||||
|             "showPoints": "always", | ||||
|             "spanNulls": true, | ||||
|             "stacking": { | ||||
|               "group": "A", | ||||
|               "mode": "none" | ||||
|             }, | ||||
|             "thresholdsStyle": { | ||||
|               "mode": "off" | ||||
|             } | ||||
|           }, | ||||
|           "mappings": [], | ||||
|           "thresholds": { | ||||
|             "mode": "absolute", | ||||
|             "steps": [ | ||||
|               { | ||||
|                 "color": "green", | ||||
|                 "value": null | ||||
|               }, | ||||
|               { | ||||
|                 "color": "red", | ||||
|                 "value": 80 | ||||
|               } | ||||
|             ] | ||||
|           }, | ||||
|           "unit": "ms" | ||||
|         }, | ||||
|         "overrides": [] | ||||
|       }, | ||||
|       "gridPos": { | ||||
|         "h": 8, | ||||
|         "w": 12, | ||||
|         "x": 0, | ||||
|         "y": 8 | ||||
|       }, | ||||
|       "id": 4, | ||||
|       "options": { | ||||
|         "legend": { | ||||
|           "calcs": [], | ||||
|           "displayMode": "list", | ||||
|           "placement": "bottom" | ||||
|         }, | ||||
|         "tooltip": { | ||||
|           "mode": "single" | ||||
|         } | ||||
|       }, | ||||
|       "targets": [ | ||||
|         { | ||||
|           "groupBy": [ | ||||
|             { | ||||
|               "params": [ | ||||
|                 "$__interval" | ||||
|               ], | ||||
|               "type": "time" | ||||
|             }, | ||||
|             { | ||||
|               "params": [ | ||||
|                 "null" | ||||
|               ], | ||||
|               "type": "fill" | ||||
|             } | ||||
|           ], | ||||
|           "measurement": "ping", | ||||
|           "orderByTime": "ASC", | ||||
|           "policy": "default", | ||||
|           "query": "SELECT mean(\"value\") FROM \"download\" WHERE (\"host\" =~ /^$server$/) AND $timeFilter GROUP BY time($__interval) fill(null)", | ||||
|           "rawQuery": false, | ||||
|           "refId": "A", | ||||
|           "resultFormat": "time_series", | ||||
|           "select": [ | ||||
|             [ | ||||
|               { | ||||
|                 "params": [ | ||||
|                   "value" | ||||
|                 ], | ||||
|                 "type": "field" | ||||
|               }, | ||||
|               { | ||||
|                 "params": [], | ||||
|                 "type": "mean" | ||||
|               } | ||||
|             ] | ||||
|           ], | ||||
|           "tags": [ | ||||
|             { | ||||
|               "key": "host", | ||||
|               "operator": "=~", | ||||
|               "value": "/^$server$/" | ||||
|             } | ||||
|           ] | ||||
|         } | ||||
|       ], | ||||
|       "title": "Ping", | ||||
|       "type": "timeseries" | ||||
|     }, | ||||
|     { | ||||
|       "datasource": "Speedtest", | ||||
|       "fieldConfig": { | ||||
|         "defaults": { | ||||
|           "color": { | ||||
|             "mode": "palette-classic" | ||||
|           }, | ||||
|           "custom": { | ||||
|             "axisLabel": "", | ||||
|             "axisPlacement": "auto", | ||||
|             "barAlignment": 0, | ||||
|             "drawStyle": "line", | ||||
|             "fillOpacity": 0, | ||||
|             "gradientMode": "none", | ||||
|             "hideFrom": { | ||||
|               "legend": false, | ||||
|               "tooltip": false, | ||||
|               "viz": false | ||||
|             }, | ||||
|             "lineInterpolation": "linear", | ||||
|             "lineWidth": 1, | ||||
|             "pointSize": 5, | ||||
|             "scaleDistribution": { | ||||
|               "type": "linear" | ||||
|             }, | ||||
|             "showPoints": "always", | ||||
|             "spanNulls": true, | ||||
|             "stacking": { | ||||
|               "group": "A", | ||||
|               "mode": "none" | ||||
|             }, | ||||
|             "thresholdsStyle": { | ||||
|               "mode": "off" | ||||
|             } | ||||
|           }, | ||||
|           "mappings": [], | ||||
|           "thresholds": { | ||||
|             "mode": "absolute", | ||||
|             "steps": [ | ||||
|               { | ||||
|                 "color": "green", | ||||
|                 "value": null | ||||
|               }, | ||||
|               { | ||||
|                 "color": "red", | ||||
|                 "value": 80 | ||||
|               } | ||||
|             ] | ||||
|           } | ||||
|         }, | ||||
|         "overrides": [] | ||||
|       }, | ||||
|       "gridPos": { | ||||
|         "h": 8, | ||||
|         "w": 12, | ||||
|         "x": 12, | ||||
|         "y": 8 | ||||
|       }, | ||||
|       "id": 6, | ||||
|       "options": { | ||||
|         "legend": { | ||||
|           "calcs": [], | ||||
|           "displayMode": "list", | ||||
|           "placement": "bottom" | ||||
|         }, | ||||
|         "tooltip": { | ||||
|           "mode": "single" | ||||
|         } | ||||
|       }, | ||||
|       "targets": [ | ||||
|         { | ||||
|           "groupBy": [ | ||||
|             { | ||||
|               "params": [ | ||||
|                 "$__interval" | ||||
|               ], | ||||
|               "type": "time" | ||||
|             }, | ||||
|             { | ||||
|               "params": [ | ||||
|                 "null" | ||||
|               ], | ||||
|               "type": "fill" | ||||
|             } | ||||
|           ], | ||||
|           "measurement": "server_distance", | ||||
|           "orderByTime": "ASC", | ||||
|           "policy": "default", | ||||
|           "refId": "A", | ||||
|           "resultFormat": "time_series", | ||||
|           "select": [ | ||||
|             [ | ||||
|               { | ||||
|                 "params": [ | ||||
|                   "value" | ||||
|                 ], | ||||
|                 "type": "field" | ||||
|               }, | ||||
|               { | ||||
|                 "params": [], | ||||
|                 "type": "mean" | ||||
|               } | ||||
|             ] | ||||
|           ], | ||||
|           "tags": [ | ||||
|             { | ||||
|               "key": "host", | ||||
|               "operator": "=~", | ||||
|               "value": "/^$server$/" | ||||
|             } | ||||
|           ] | ||||
|         } | ||||
|       ], | ||||
|       "title": "Server Distance", | ||||
|       "type": "timeseries" | ||||
|     } | ||||
|   ], | ||||
|   "schemaVersion": 30, | ||||
|   "style": "dark", | ||||
|   "tags": [], | ||||
|   "templating": { | ||||
|     "list": [ | ||||
|       { | ||||
|         "allValue": null, | ||||
|         "current": { | ||||
|           "selected": false, | ||||
|           "text": "pi02.homenet.leffler.me", | ||||
|           "value": "pi02.homenet.leffler.me" | ||||
|         }, | ||||
|         "datasource": "Speedtest", | ||||
|         "definition": "SHOW TAG VALUES WITH KEY=host", | ||||
|         "description": null, | ||||
|         "error": null, | ||||
|         "hide": 0, | ||||
|         "includeAll": false, | ||||
|         "label": null, | ||||
|         "multi": false, | ||||
|         "name": "server", | ||||
|         "options": [], | ||||
|         "query": "SHOW TAG VALUES WITH KEY=host", | ||||
|         "refresh": 1, | ||||
|         "regex": "", | ||||
|         "skipUrlSync": false, | ||||
|         "sort": 0, | ||||
|         "type": "query" | ||||
|       } | ||||
|     ] | ||||
|   }, | ||||
|   "time": { | ||||
|     "from": "now-6h", | ||||
|     "to": "now" | ||||
|   }, | ||||
|   "timepicker": {}, | ||||
|   "timezone": "", | ||||
|   "title": "Speedtest", | ||||
|   "uid": "ICgsxYS7z", | ||||
|   "version": 5 | ||||
| } | ||||
							
								
								
									
										63
									
								
								speedtest2influx.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								speedtest2influx.sh
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,63 @@ | ||||
| #!/bin/bash | ||||
| 
 | ||||
| 
 | ||||
| # provisioned in mbps | ||||
| provisioned_upload=200 | ||||
| provisioned_download=10 | ||||
| 
 | ||||
| influx_url="https://influx.domain.com" # without trailing slash and with proto (http/s) | ||||
| influx_db="speedtest_db" | ||||
| influx_user="speedtest_user" | ||||
| influx_pass="speedtest_password" | ||||
| 
 | ||||
| #### Starts here #### | ||||
| 
 | ||||
| host=$(hostname --fqdn) | ||||
| 
 | ||||
| 
 | ||||
| #if ! command -v bc &> /dev/null | ||||
| #then | ||||
| #    echo "bc could not be found" | ||||
| #    exit 1 | ||||
| #fi | ||||
| 
 | ||||
| if ! command -v jq &> /dev/null | ||||
| then | ||||
|     echo "jq could not be found" | ||||
|     exit 1 | ||||
| fi | ||||
| 
 | ||||
| 
 | ||||
| if ! command -v curl &> /dev/null | ||||
| then | ||||
|     echo "curl could not be found" | ||||
|     exit | ||||
| fi | ||||
| 
 | ||||
| 
 | ||||
| if ! command -v speedtest-cli &> /dev/null | ||||
| then | ||||
|     echo "speedtest-cli could not be found" | ||||
|     exit | ||||
| fi | ||||
| 
 | ||||
| data=$(speedtest-cli --json) | ||||
| 
 | ||||
| ping=$(jq .ping <<< "${data}") | ||||
| upload=$(jq .upload <<< "${data}") | ||||
| download=$(jq .download <<< "${data}") | ||||
| server_name=$(jq .server.name <<< "${data}") | ||||
| server_sponsor=$(jq .server.sponsor <<< "${data}") | ||||
| server_id=$(jq .server.id <<< "${data}") | ||||
| server_distance=$(jq .server.d <<< "${data}") | ||||
| 
 | ||||
| curl -XPOST "${influx_url}/write?db=${influx_db}" \ | ||||
|   -u "${influx_user}:${influx_pass}" \ | ||||
|   --data-binary \ | ||||
| "upload,host=${host} value=${upload} | ||||
| download,host=${host} value=${download} | ||||
| ping,host=${host} value=${ping} | ||||
| server_name,host=${host} value=${server_name} | ||||
| server_sponsor,host=${host} value=${server_sponsor} | ||||
| server_id,host=${host} value=${server_id} | ||||
| server_distance,host=${host} value=${server_distance}" | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user