diff --git a/icecast2influx.py b/icecast2influx.py deleted file mode 100755 index 6a88652..0000000 --- a/icecast2influx.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/python3 -# preso in parte da qui https://raw.githubusercontent.com/munin-monitoring/contrib/master/plugins/icecast/icecast2_stats_ - -import datetime -import json -import os -import urllib.request - - -status_url = "http://stream.radiospore.oziosi.org:8000/status-json.xsl" - -def _get_json_statistics(): - with urllib.request.urlopen(status_url) as conn: - json_body = conn.read() - return json.loads(json_body.decode("utf-8")) - - -def get_sources(): - sources = [] - for source in _get_json_statistics()["icestats"]["source"]: - path_name = source["listenurl"].split("/")[-1] - sources.append({"name": path_name,"listeners": source["listeners"]}) - try: - source.append({"title": source["title"]}) - except: - pass - #"duration_days": get_iso8601_age_days(source["stream_start_iso8601"]) - - sources.sort(key=lambda item: item["name"]) - return sources - - -def get_server_uptime_days(): - return get_iso8601_age_days(_get_json_statistics()["icestats"]["server_start_iso8601"]) - - -if __name__ == "__main__": - print(get_sources()) \ No newline at end of file diff --git a/icecast2influx.sh b/icecast2influx.sh index 7eec4ac..a25dc88 100755 --- a/icecast2influx.sh +++ b/icecast2influx.sh @@ -1,11 +1,31 @@ #!/bin/bash -sta=$(curl "http://stream.radiospore.oziosi.org:8000/status-json.xsl" | jq -r '.icestats.source[]') +influxurl="http://localhost:8086/write?db=icestat&precision=s" -echo $sta | jq -c '.' | while read i; do - listeners=$(echo $i | jq '.listeners') - listenurl=$(basename $(echo $i | jq '.listenurl'| tr -d '"')) - title=$(echo $i | jq '.title' | tr -d '"' | sed 's/ /\\ /g') +timenow=$(date +%s) - curl -XPOST 'http://localhost:8086/write?db=icestat' --data-binary "listeners,listenurl=$listenurl,title=$title value=$listeners" + +icecasturl="http://stream1.esiliati.org:8000" + +icecastsrv=$(echo "${icecasturl##*/}") +sta=$(curl "${icecasturl}/status-json.xsl" | jq '.icestats.source[]') +echo $sta | jq -c '.' | while read -r i; do + listeners=$(echo $i | jq -r '.listeners') + listenurl=$(basename $(echo $i | jq -r '.listenurl')) + title=$(echo $i | jq -r '.title' | sed 's/ /\\ /g' | sed 's/\"//g') + curl -XPOST $influxurl --data-binary "listeners,icecastsrv=$icecastsrv,listenurl=$listenurl,title=$title value=$listeners $timenow" done + + + +icecasturl="http://stream2.esiliati.org:8000" + +icecastsrv=$(echo "${icecasturl##*/}") +sta=$(curl "${icecasturl}/status-json.xsl" | jq '.icestats.source[]') +echo $sta | jq -c '.' | while read -r i; do + listeners=$(echo $i | jq -r '.listeners') + listenurl=$(basename $(echo $i | jq -r '.listenurl')) + title=$(echo $i | jq -r '.title' | sed 's/ /\\ /g' | sed 's/\"//g') + curl -XPOST $influxurl --data-binary "listeners,icecastsrv=$icecastsrv,listenurl=$listenurl,title=$title value=$listeners $timenow" +done +