Browse Source

first commit

itec 4 years ago
parent
commit
f633b6c67e
3 changed files with 50 additions and 0 deletions
  1. 1 0
      README.md
  2. 38 0
      icecast2influx.py
  3. 11 0
      icecast2influx.sh

+ 1 - 0
README.md

@@ -0,0 +1 @@
+Script per caricare le stat di icecast2 su influxdb

+ 38 - 0
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())

+ 11 - 0
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