Added icecastsrv + fixes

This commit is contained in:
itec 2020-04-20 16:22:02 +02:00
parent f633b6c67e
commit d80a24882e
2 changed files with 26 additions and 44 deletions

View file

@ -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())

View file

@ -1,11 +1,31 @@
#!/bin/bash #!/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 timenow=$(date +%s)
listeners=$(echo $i | jq '.listeners')
listenurl=$(basename $(echo $i | jq '.listenurl'| tr -d '"'))
title=$(echo $i | jq '.title' | tr -d '"' | sed 's/ /\\ /g')
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 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