From f633b6c67e83c5ba0e03df9bfd1fd6c93d4f786d Mon Sep 17 00:00:00 2001 From: itec Date: Fri, 10 Apr 2020 21:15:58 +0200 Subject: [PATCH] first commit --- README.md | 1 + icecast2influx.py | 38 ++++++++++++++++++++++++++++++++++++++ icecast2influx.sh | 11 +++++++++++ 3 files changed, 50 insertions(+) create mode 100755 icecast2influx.py create mode 100755 icecast2influx.sh diff --git a/README.md b/README.md index e69de29..8f47add 100644 --- a/README.md +++ b/README.md @@ -0,0 +1 @@ +Script per caricare le stat di icecast2 su influxdb diff --git a/icecast2influx.py b/icecast2influx.py new file mode 100755 index 0000000..6a88652 --- /dev/null +++ b/icecast2influx.py @@ -0,0 +1,38 @@ +#!/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 new file mode 100755 index 0000000..7eec4ac --- /dev/null +++ b/icecast2influx.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +sta=$(curl "http://stream.radiospore.oziosi.org:8000/status-json.xsl" | jq -r '.icestats.source[]') + +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') + + curl -XPOST 'http://localhost:8086/write?db=icestat' --data-binary "listeners,listenurl=$listenurl,title=$title value=$listeners" +done