summaryrefslogtreecommitdiffstats
path: root/src/go/plugin/go.d/modules/icecast
diff options
context:
space:
mode:
Diffstat (limited to '')
l---------src/go/plugin/go.d/modules/icecast/README.md (renamed from collectors/python.d.plugin/icecast/README.md)0
-rw-r--r--src/go/plugin/go.d/modules/icecast/charts.go65
-rw-r--r--src/go/plugin/go.d/modules/icecast/collect.go107
-rw-r--r--src/go/plugin/go.d/modules/icecast/config_schema.json177
-rw-r--r--src/go/plugin/go.d/modules/icecast/icecast.go118
-rw-r--r--src/go/plugin/go.d/modules/icecast/icecast_test.go285
-rw-r--r--src/go/plugin/go.d/modules/icecast/integrations/icecast.md226
-rw-r--r--src/go/plugin/go.d/modules/icecast/metadata.yaml169
-rw-r--r--src/go/plugin/go.d/modules/icecast/server_stats.go45
-rw-r--r--src/go/plugin/go.d/modules/icecast/testdata/config.json20
-rw-r--r--src/go/plugin/go.d/modules/icecast/testdata/config.yaml17
-rw-r--r--src/go/plugin/go.d/modules/icecast/testdata/stats_multi_source.json46
-rw-r--r--src/go/plugin/go.d/modules/icecast/testdata/stats_no_sources.json11
-rw-r--r--src/go/plugin/go.d/modules/icecast/testdata/stats_single_source.json27
14 files changed, 1313 insertions, 0 deletions
diff --git a/collectors/python.d.plugin/icecast/README.md b/src/go/plugin/go.d/modules/icecast/README.md
index db3c1b572..db3c1b572 120000
--- a/collectors/python.d.plugin/icecast/README.md
+++ b/src/go/plugin/go.d/modules/icecast/README.md
diff --git a/src/go/plugin/go.d/modules/icecast/charts.go b/src/go/plugin/go.d/modules/icecast/charts.go
new file mode 100644
index 000000000..26d3fe100
--- /dev/null
+++ b/src/go/plugin/go.d/modules/icecast/charts.go
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package icecast
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
+)
+
+const (
+ prioSourceListeners = module.Priority + iota
+)
+
+var sourceChartsTmpl = module.Charts{
+ sourceListenersChartTmpl.Copy(),
+}
+
+var (
+ sourceListenersChartTmpl = module.Chart{
+ ID: "icecast_%s_listeners",
+ Title: "Icecast Listeners",
+ Units: "listeners",
+ Fam: "listeners",
+ Ctx: "icecast.listeners",
+ Type: module.Line,
+ Priority: prioSourceListeners,
+ Dims: module.Dims{
+ {ID: "source_%s_listeners", Name: "listeners"},
+ },
+ }
+)
+
+func (ic *Icecast) addSourceCharts(name string) {
+ chart := sourceListenersChartTmpl.Copy()
+
+ chart.ID = fmt.Sprintf(chart.ID, cleanSource(name))
+ chart.Labels = []module.Label{
+ {Key: "source", Value: name},
+ }
+ for _, dim := range chart.Dims {
+ dim.ID = fmt.Sprintf(dim.ID, name)
+ }
+
+ if err := ic.Charts().Add(chart); err != nil {
+ ic.Warning(err)
+ }
+
+}
+
+func (ic *Icecast) removeSourceCharts(name string) {
+ px := fmt.Sprintf("icecast_%s_", cleanSource(name))
+ for _, chart := range *ic.Charts() {
+ if strings.HasPrefix(chart.ID, px) {
+ chart.MarkRemove()
+ chart.MarkNotCreated()
+ }
+ }
+}
+
+func cleanSource(name string) string {
+ r := strings.NewReplacer(" ", "_", ".", "_", ",", "_")
+ return r.Replace(name)
+}
diff --git a/src/go/plugin/go.d/modules/icecast/collect.go b/src/go/plugin/go.d/modules/icecast/collect.go
new file mode 100644
index 000000000..102ad31e5
--- /dev/null
+++ b/src/go/plugin/go.d/modules/icecast/collect.go
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package icecast
+
+import (
+ "encoding/json"
+ "fmt"
+ "io"
+ "net/http"
+
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
+)
+
+const (
+ urlPathServerStats = "/status-json.xsl" // https://icecast.org/docs/icecast-trunk/server_stats/
+)
+
+func (ic *Icecast) collect() (map[string]int64, error) {
+ mx := make(map[string]int64)
+
+ if err := ic.collectServerStats(mx); err != nil {
+ return nil, err
+ }
+
+ return mx, nil
+}
+
+func (ic *Icecast) collectServerStats(mx map[string]int64) error {
+ stats, err := ic.queryServerStats()
+ if err != nil {
+ return err
+ }
+ if stats.IceStats == nil {
+ return fmt.Errorf("unexpected response: no icestats found")
+ }
+ if len(stats.IceStats.Source) == 0 {
+ return fmt.Errorf("no icecast sources found")
+ }
+
+ seen := make(map[string]bool)
+
+ for _, src := range stats.IceStats.Source {
+ name := src.ServerName
+ if name == "" {
+ continue
+ }
+
+ seen[name] = true
+
+ if !ic.seenSources[name] {
+ ic.seenSources[name] = true
+ ic.addSourceCharts(name)
+ }
+
+ px := fmt.Sprintf("source_%s_", name)
+
+ mx[px+"listeners"] = src.Listeners
+ }
+
+ for name := range ic.seenSources {
+ if !seen[name] {
+ delete(ic.seenSources, name)
+ ic.removeSourceCharts(name)
+ }
+ }
+
+ return nil
+}
+
+func (ic *Icecast) queryServerStats() (*serverStats, error) {
+ req, err := web.NewHTTPRequestWithPath(ic.Request, urlPathServerStats)
+ if err != nil {
+ return nil, err
+ }
+
+ var stats serverStats
+
+ if err := ic.doOKDecode(req, &stats); err != nil {
+ return nil, err
+ }
+
+ return &stats, nil
+}
+
+func (ic *Icecast) doOKDecode(req *http.Request, in interface{}) error {
+ resp, err := ic.httpClient.Do(req)
+ if err != nil {
+ return fmt.Errorf("error on HTTP request '%s': %v", req.URL, err)
+ }
+ defer closeBody(resp)
+
+ if resp.StatusCode != http.StatusOK {
+ return fmt.Errorf("'%s' returned HTTP status code: %d", req.URL, resp.StatusCode)
+ }
+
+ if err := json.NewDecoder(resp.Body).Decode(in); err != nil {
+ return fmt.Errorf("error on decoding response from '%s': %v", req.URL, err)
+ }
+ return nil
+}
+
+func closeBody(resp *http.Response) {
+ if resp != nil && resp.Body != nil {
+ _, _ = io.Copy(io.Discard, resp.Body)
+ _ = resp.Body.Close()
+ }
+}
diff --git a/src/go/plugin/go.d/modules/icecast/config_schema.json b/src/go/plugin/go.d/modules/icecast/config_schema.json
new file mode 100644
index 000000000..3abda6e75
--- /dev/null
+++ b/src/go/plugin/go.d/modules/icecast/config_schema.json
@@ -0,0 +1,177 @@
+{
+ "jsonSchema": {
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "title": "Icecast collector configuration.",
+ "type": "object",
+ "properties": {
+ "update_every": {
+ "title": "Update every",
+ "description": "Data collection interval, measured in seconds.",
+ "type": "integer",
+ "minimum": 1,
+ "default": 1
+ },
+ "url": {
+ "title": "URL",
+ "description": "The base URL where the Icecast API can be accessed.",
+ "type": "string",
+ "default": "http://127.0.0.1:8000",
+ "format": "uri"
+ },
+ "timeout": {
+ "title": "Timeout",
+ "description": "The timeout in seconds for the HTTP request.",
+ "type": "number",
+ "minimum": 0.5,
+ "default": 1
+ },
+ "not_follow_redirects": {
+ "title": "Not follow redirects",
+ "description": "If set, the client will not follow HTTP redirects automatically.",
+ "type": "boolean"
+ },
+ "username": {
+ "title": "Username",
+ "description": "The username for basic authentication.",
+ "type": "string",
+ "sensitive": true
+ },
+ "password": {
+ "title": "Password",
+ "description": "The password for basic authentication.",
+ "type": "string",
+ "sensitive": true
+ },
+ "proxy_url": {
+ "title": "Proxy URL",
+ "description": "The URL of the proxy server.",
+ "type": "string"
+ },
+ "proxy_username": {
+ "title": "Proxy username",
+ "description": "The username for proxy authentication.",
+ "type": "string",
+ "sensitive": true
+ },
+ "proxy_password": {
+ "title": "Proxy password",
+ "description": "The password for proxy authentication.",
+ "type": "string",
+ "sensitive": true
+ },
+ "headers": {
+ "title": "Headers",
+ "description": "Additional HTTP headers to include in the request.",
+ "type": [
+ "object",
+ "null"
+ ],
+ "additionalProperties": {
+ "type": "string"
+ }
+ },
+ "tls_skip_verify": {
+ "title": "Skip TLS verification",
+ "description": "If set, TLS certificate verification will be skipped.",
+ "type": "boolean"
+ },
+ "tls_ca": {
+ "title": "TLS CA",
+ "description": "The path to the CA certificate file for TLS verification.",
+ "type": "string",
+ "pattern": "^$|^/"
+ },
+ "tls_cert": {
+ "title": "TLS certificate",
+ "description": "The path to the client certificate file for TLS authentication.",
+ "type": "string",
+ "pattern": "^$|^/"
+ },
+ "tls_key": {
+ "title": "TLS key",
+ "description": "The path to the client key file for TLS authentication.",
+ "type": "string",
+ "pattern": "^$|^/"
+ },
+ "body": {
+ "title": "Body",
+ "type": "string"
+ },
+ "method": {
+ "title": "Method",
+ "type": "string"
+ }
+ },
+ "required": [
+ "url"
+ ],
+ "additionalProperties": false,
+ "patternProperties": {
+ "^name$": {}
+ }
+ },
+ "uiSchema": {
+ "uiOptions": {
+ "fullPage": true
+ },
+ "body": {
+ "ui:widget": "hidden"
+ },
+ "method": {
+ "ui:widget": "hidden"
+ },
+ "timeout": {
+ "ui:help": "Accepts decimals for precise control (e.g., type 1.5 for 1.5 seconds)."
+ },
+ "password": {
+ "ui:widget": "password"
+ },
+ "proxy_password": {
+ "ui:widget": "password"
+ },
+ "ui:flavour": "tabs",
+ "ui:options": {
+ "tabs": [
+ {
+ "title": "Base",
+ "fields": [
+ "update_every",
+ "url",
+ "timeout",
+ "not_follow_redirects"
+ ]
+ },
+ {
+ "title": "Auth",
+ "fields": [
+ "username",
+ "password"
+ ]
+ },
+ {
+ "title": "TLS",
+ "fields": [
+ "tls_skip_verify",
+ "tls_ca",
+ "tls_cert",
+ "tls_key"
+ ]
+ },
+ {
+ "title": "Proxy",
+ "fields": [
+ "proxy_url",
+ "proxy_username",
+ "proxy_password"
+ ]
+ },
+ {
+ "title": "Headers",
+ "fields": [
+ "headers"
+ ]
+ }
+ ]
+ }
+ }
+}
diff --git a/src/go/plugin/go.d/modules/icecast/icecast.go b/src/go/plugin/go.d/modules/icecast/icecast.go
new file mode 100644
index 000000000..e999421f7
--- /dev/null
+++ b/src/go/plugin/go.d/modules/icecast/icecast.go
@@ -0,0 +1,118 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package icecast
+
+import (
+ _ "embed"
+ "errors"
+ "net/http"
+ "time"
+
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
+)
+
+//go:embed "config_schema.json"
+var configSchema string
+
+func init() {
+ module.Register("icecast", module.Creator{
+ JobConfigSchema: configSchema,
+ Create: func() module.Module { return New() },
+ Config: func() any { return &Config{} },
+ })
+}
+
+func New() *Icecast {
+ return &Icecast{
+ Config: Config{
+ HTTP: web.HTTP{
+ Request: web.Request{
+ URL: "http://127.0.0.1:8000",
+ },
+ Client: web.Client{
+ Timeout: web.Duration(time.Second * 1),
+ },
+ },
+ },
+ charts: &module.Charts{},
+
+ seenSources: make(map[string]bool),
+ }
+}
+
+type Config struct {
+ UpdateEvery int `yaml:"update_every,omitempty" json:"update_every"`
+ web.HTTP `yaml:",inline" json:""`
+}
+
+type Icecast struct {
+ module.Base
+ Config `yaml:",inline" json:""`
+
+ charts *module.Charts
+
+ seenSources map[string]bool
+
+ httpClient *http.Client
+}
+
+func (ic *Icecast) Configuration() any {
+ return ic.Config
+}
+
+func (ic *Icecast) Init() error {
+ if ic.URL == "" {
+ ic.Error("URL not set")
+ return errors.New("url not set")
+ }
+
+ client, err := web.NewHTTPClient(ic.Client)
+ if err != nil {
+ ic.Error(err)
+ return err
+ }
+ ic.httpClient = client
+
+ ic.Debugf("using URL %s", ic.URL)
+ ic.Debugf("using timeout: %s", ic.Timeout)
+
+ return nil
+}
+
+func (ic *Icecast) Check() error {
+ mx, err := ic.collect()
+ if err != nil {
+ ic.Error(err)
+ return err
+ }
+
+ if len(mx) == 0 {
+ return errors.New("no metrics collected")
+ }
+
+ return nil
+}
+
+func (ic *Icecast) Charts() *module.Charts {
+ return ic.charts
+}
+
+func (ic *Icecast) Collect() map[string]int64 {
+ mx, err := ic.collect()
+ if err != nil {
+ ic.Error(err)
+ }
+
+ if len(mx) == 0 {
+ return nil
+ }
+
+ return mx
+}
+
+func (ic *Icecast) Cleanup() {
+ if ic.httpClient != nil {
+ ic.httpClient.CloseIdleConnections()
+ }
+}
diff --git a/src/go/plugin/go.d/modules/icecast/icecast_test.go b/src/go/plugin/go.d/modules/icecast/icecast_test.go
new file mode 100644
index 000000000..40132986d
--- /dev/null
+++ b/src/go/plugin/go.d/modules/icecast/icecast_test.go
@@ -0,0 +1,285 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package icecast
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "testing"
+
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+var (
+ dataConfigJSON, _ = os.ReadFile("testdata/config.json")
+ dataConfigYAML, _ = os.ReadFile("testdata/config.yaml")
+
+ dataServerStatsMultiSource, _ = os.ReadFile("testdata/stats_multi_source.json")
+ dataServerStatsSingleSource, _ = os.ReadFile("testdata/stats_single_source.json")
+ dataServerStatsNoSources, _ = os.ReadFile("testdata/stats_no_sources.json")
+)
+
+func Test_testDataIsValid(t *testing.T) {
+ for name, data := range map[string][]byte{
+ "dataConfigJSON": dataConfigJSON,
+ "dataConfigYAML": dataConfigYAML,
+ "dataServerStats": dataServerStatsMultiSource,
+ "dataServerStatsSingleSource": dataServerStatsSingleSource,
+ "dataServerStatsNoSources": dataServerStatsNoSources,
+ } {
+ require.NotNil(t, data, name)
+ }
+}
+
+func TestIcecast_ConfigurationSerialize(t *testing.T) {
+ module.TestConfigurationSerialize(t, &Icecast{}, dataConfigJSON, dataConfigYAML)
+}
+
+func TestIcecast_Init(t *testing.T) {
+ tests := map[string]struct {
+ wantFail bool
+ config Config
+ }{
+ "success with default": {
+ wantFail: false,
+ config: New().Config,
+ },
+ "fail when URL not set": {
+ wantFail: true,
+ config: Config{
+ HTTP: web.HTTP{
+ Request: web.Request{URL: ""},
+ },
+ },
+ },
+ }
+
+ for name, test := range tests {
+ t.Run(name, func(t *testing.T) {
+ icecast := New()
+ icecast.Config = test.config
+
+ if test.wantFail {
+ assert.Error(t, icecast.Init())
+ } else {
+ assert.NoError(t, icecast.Init())
+ }
+ })
+ }
+}
+
+func TestIcecast_Charts(t *testing.T) {
+ assert.NotNil(t, New().Charts())
+}
+
+func TestIcecast_Check(t *testing.T) {
+ tests := map[string]struct {
+ wantFail bool
+ prepare func(t *testing.T) (*Icecast, func())
+ }{
+ "success multiple sources": {
+ wantFail: false,
+ prepare: prepareCaseMultipleSources,
+ },
+ "success single source": {
+ wantFail: false,
+ prepare: prepareCaseMultipleSources,
+ },
+ "fails on no sources": {
+ wantFail: true,
+ prepare: prepareCaseNoSources,
+ },
+ "fails on unexpected json response": {
+ wantFail: true,
+ prepare: prepareCaseUnexpectedJsonResponse,
+ },
+ "fails on invalid format response": {
+ wantFail: true,
+ prepare: prepareCaseInvalidFormatResponse,
+ },
+ "fails on connection refused": {
+ wantFail: true,
+ prepare: prepareCaseConnectionRefused,
+ },
+ }
+
+ for name, test := range tests {
+ t.Run(name, func(t *testing.T) {
+ icecast, cleanup := test.prepare(t)
+ defer cleanup()
+
+ if test.wantFail {
+ assert.Error(t, icecast.Check())
+ } else {
+ assert.NoError(t, icecast.Check())
+ }
+ })
+ }
+}
+
+func TestIcecast_Collect(t *testing.T) {
+ tests := map[string]struct {
+ prepare func(t *testing.T) (*Icecast, func())
+ wantMetrics map[string]int64
+ wantCharts int
+ }{
+ "success multiple sources": {
+ prepare: prepareCaseMultipleSources,
+ wantCharts: len(sourceChartsTmpl) * 2,
+ wantMetrics: map[string]int64{
+ "source_abc_listeners": 1,
+ "source_efg_listeners": 10,
+ },
+ },
+ "success single source": {
+ prepare: prepareCaseSingleSource,
+ wantCharts: len(sourceChartsTmpl) * 1,
+ wantMetrics: map[string]int64{
+ "source_abc_listeners": 1,
+ },
+ },
+ "fails on no sources": {
+ prepare: prepareCaseNoSources,
+ },
+ "fails on unexpected json response": {
+ prepare: prepareCaseUnexpectedJsonResponse,
+ },
+ "fails on invalid format response": {
+ prepare: prepareCaseInvalidFormatResponse,
+ },
+ "fails on connection refused": {
+ prepare: prepareCaseConnectionRefused,
+ },
+ }
+
+ for name, test := range tests {
+ t.Run(name, func(t *testing.T) {
+ icecast, cleanup := test.prepare(t)
+ defer cleanup()
+
+ mx := icecast.Collect()
+
+ require.Equal(t, test.wantMetrics, mx)
+ if len(test.wantMetrics) > 0 {
+ assert.Equal(t, test.wantCharts, len(*icecast.Charts()))
+ module.TestMetricsHasAllChartsDims(t, icecast.Charts(), mx)
+ }
+ })
+ }
+}
+
+func prepareCaseMultipleSources(t *testing.T) (*Icecast, func()) {
+ t.Helper()
+ srv := httptest.NewServer(http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ switch r.URL.Path {
+ case urlPathServerStats:
+ _, _ = w.Write(dataServerStatsMultiSource)
+ default:
+ w.WriteHeader(http.StatusNotFound)
+ }
+ }))
+
+ icecast := New()
+ icecast.URL = srv.URL
+ require.NoError(t, icecast.Init())
+
+ return icecast, srv.Close
+}
+
+func prepareCaseSingleSource(t *testing.T) (*Icecast, func()) {
+ t.Helper()
+ srv := httptest.NewServer(http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ switch r.URL.Path {
+ case urlPathServerStats:
+ _, _ = w.Write(dataServerStatsSingleSource)
+ default:
+ w.WriteHeader(http.StatusNotFound)
+ }
+ }))
+
+ icecast := New()
+ icecast.URL = srv.URL
+ require.NoError(t, icecast.Init())
+
+ return icecast, srv.Close
+}
+
+func prepareCaseNoSources(t *testing.T) (*Icecast, func()) {
+ t.Helper()
+ srv := httptest.NewServer(http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ switch r.URL.Path {
+ case urlPathServerStats:
+ _, _ = w.Write(dataServerStatsNoSources)
+ default:
+ w.WriteHeader(http.StatusNotFound)
+ }
+ }))
+
+ icecast := New()
+ icecast.URL = srv.URL
+ require.NoError(t, icecast.Init())
+
+ return icecast, srv.Close
+}
+
+func prepareCaseUnexpectedJsonResponse(t *testing.T) (*Icecast, func()) {
+ t.Helper()
+ resp := `
+{
+ "elephant": {
+ "burn": false,
+ "mountain": true,
+ "fog": false,
+ "skin": -1561907625,
+ "burst": "anyway",
+ "shadow": 1558616893
+ },
+ "start": "ever",
+ "base": 2093056027,
+ "mission": -2007590351,
+ "victory": 999053756,
+ "die": false
+}
+`
+ srv := httptest.NewServer(http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ _, _ = w.Write([]byte(resp))
+ }))
+
+ icecast := New()
+ icecast.URL = srv.URL
+ require.NoError(t, icecast.Init())
+
+ return icecast, srv.Close
+}
+
+func prepareCaseInvalidFormatResponse(t *testing.T) (*Icecast, func()) {
+ t.Helper()
+ srv := httptest.NewServer(http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ _, _ = w.Write([]byte("hello and\n goodbye"))
+ }))
+
+ icecast := New()
+ icecast.URL = srv.URL
+ require.NoError(t, icecast.Init())
+
+ return icecast, srv.Close
+}
+
+func prepareCaseConnectionRefused(t *testing.T) (*Icecast, func()) {
+ t.Helper()
+ icecast := New()
+ icecast.URL = "http://127.0.0.1:65001"
+ require.NoError(t, icecast.Init())
+
+ return icecast, func() {}
+}
diff --git a/src/go/plugin/go.d/modules/icecast/integrations/icecast.md b/src/go/plugin/go.d/modules/icecast/integrations/icecast.md
new file mode 100644
index 000000000..9ff06a4dd
--- /dev/null
+++ b/src/go/plugin/go.d/modules/icecast/integrations/icecast.md
@@ -0,0 +1,226 @@
+<!--startmeta
+custom_edit_url: "https://github.com/netdata/netdata/edit/master/src/go/plugin/go.d/modules/icecast/README.md"
+meta_yaml: "https://github.com/netdata/netdata/edit/master/src/go/plugin/go.d/modules/icecast/metadata.yaml"
+sidebar_label: "Icecast"
+learn_status: "Published"
+learn_rel_path: "Collecting Metrics/Media Services"
+most_popular: False
+message: "DO NOT EDIT THIS FILE DIRECTLY, IT IS GENERATED BY THE COLLECTOR'S metadata.yaml FILE"
+endmeta-->
+
+# Icecast
+
+
+<img src="https://netdata.cloud/img/icecast.svg" width="150"/>
+
+
+Plugin: go.d.plugin
+Module: icecast
+
+<img src="https://img.shields.io/badge/maintained%20by-Netdata-%2300ab44" />
+
+## Overview
+
+This collector monitors Icecast listener counts.
+
+It uses the Icecast server statistics `status-json.xsl` endpoint to retrieve the metrics.
+
+This collector is supported on all platforms.
+
+This collector supports collecting metrics from multiple instances of this integration, including remote instances.
+
+
+### Default Behavior
+
+#### Auto-Detection
+
+By default, it detects Icecast instances running on localhost that are listening on port 8000.
+
+#### Limits
+
+The default configuration for this integration does not impose any limits on data collection.
+
+#### Performance Impact
+
+The default configuration for this integration is not expected to impose a significant performance impact on the system.
+
+
+## Metrics
+
+Metrics grouped by *scope*.
+
+The scope defines the instance that the metric belongs to. An instance is uniquely identified by a set of labels.
+
+
+
+### Per Icecast source
+
+These metrics refer to an icecast source.
+
+Labels:
+
+| Label | Description |
+|:-----------|:----------------|
+| source | Source name. |
+
+Metrics:
+
+| Metric | Dimensions | Unit |
+|:------|:----------|:----|
+| icecast.listeners | listeners | listeners |
+
+
+
+## Alerts
+
+There are no alerts configured by default for this integration.
+
+
+## Setup
+
+### Prerequisites
+
+#### Icecast minimum version
+
+Needs at least Icecast version >= 2.4.0
+
+
+### Configuration
+
+#### File
+
+The configuration file name for this integration is `go.d/icecast.conf`.
+
+
+You can edit the configuration file using the `edit-config` script from the
+Netdata [config directory](/docs/netdata-agent/configuration/README.md#the-netdata-config-directory).
+
+```bash
+cd /etc/netdata 2>/dev/null || cd /opt/netdata/etc/netdata
+sudo ./edit-config go.d/icecast.conf
+```
+#### Options
+
+The following options can be defined globally: update_every, autodetection_retry.
+
+
+<details open><summary>Config options</summary>
+
+| Name | Description | Default | Required |
+|:----|:-----------|:-------|:--------:|
+| update_every | Data collection frequency. | 1 | no |
+| autodetection_retry | Recheck interval in seconds. Zero means no recheck will be scheduled. | 0 | no |
+| url | Server URL. | http://127.0.0.1:8000 | yes |
+| timeout | HTTP request timeout. | 1 | no |
+| username | Username for basic HTTP authentication. | | no |
+| password | Password for basic HTTP authentication. | | no |
+| proxy_url | Proxy URL. | | no |
+| proxy_username | Username for proxy basic HTTP authentication. | | no |
+| proxy_password | Password for proxy basic HTTP authentication. | | no |
+| method | HTTP request method. | POST | no |
+| body | HTTP request body. | | no |
+| headers | HTTP request headers. | | no |
+| not_follow_redirects | Redirect handling policy. Controls whether the client follows redirects. | no | no |
+| tls_skip_verify | Server certificate chain and hostname validation policy. Controls whether the client performs this check. | no | no |
+| tls_ca | Certification authority that the client uses when verifying the server's certificates. | | no |
+| tls_cert | Client TLS certificate. | | no |
+| tls_key | Client TLS key. | | no |
+
+</details>
+
+#### Examples
+
+##### Basic
+
+A basic example configuration.
+
+```yaml
+jobs:
+ - name: local
+ url: http://127.0.0.1:8000
+
+```
+##### Multi-instance
+
+> **Note**: When you define multiple jobs, their names must be unique.
+
+Collecting metrics from local and remote instances.
+
+
+<details open><summary>Config</summary>
+
+```yaml
+jobs:
+ - name: local
+ url: http://127.0.0.1:8000
+
+ - name: remote
+ url: http://192.0.2.1:8000
+
+```
+</details>
+
+
+
+## Troubleshooting
+
+### Debug Mode
+
+**Important**: Debug mode is not supported for data collection jobs created via the UI using the Dyncfg feature.
+
+To troubleshoot issues with the `icecast` collector, run the `go.d.plugin` with the debug option enabled. The output
+should give you clues as to why the collector isn't working.
+
+- Navigate to the `plugins.d` directory, usually at `/usr/libexec/netdata/plugins.d/`. If that's not the case on
+ your system, open `netdata.conf` and look for the `plugins` setting under `[directories]`.
+
+ ```bash
+ cd /usr/libexec/netdata/plugins.d/
+ ```
+
+- Switch to the `netdata` user.
+
+ ```bash
+ sudo -u netdata -s
+ ```
+
+- Run the `go.d.plugin` to debug the collector:
+
+ ```bash
+ ./go.d.plugin -d -m icecast
+ ```
+
+### Getting Logs
+
+If you're encountering problems with the `icecast` collector, follow these steps to retrieve logs and identify potential issues:
+
+- **Run the command** specific to your system (systemd, non-systemd, or Docker container).
+- **Examine the output** for any warnings or error messages that might indicate issues. These messages should provide clues about the root cause of the problem.
+
+#### System with systemd
+
+Use the following command to view logs generated since the last Netdata service restart:
+
+```bash
+journalctl _SYSTEMD_INVOCATION_ID="$(systemctl show --value --property=InvocationID netdata)" --namespace=netdata --grep icecast
+```
+
+#### System without systemd
+
+Locate the collector log file, typically at `/var/log/netdata/collector.log`, and use `grep` to filter for collector's name:
+
+```bash
+grep icecast /var/log/netdata/collector.log
+```
+
+**Note**: This method shows logs from all restarts. Focus on the **latest entries** for troubleshooting current issues.
+
+#### Docker Container
+
+If your Netdata runs in a Docker container named "netdata" (replace if different), use this command:
+
+```bash
+docker logs netdata 2>&1 | grep icecast
+```
+
+
diff --git a/src/go/plugin/go.d/modules/icecast/metadata.yaml b/src/go/plugin/go.d/modules/icecast/metadata.yaml
new file mode 100644
index 000000000..bcaa4b07c
--- /dev/null
+++ b/src/go/plugin/go.d/modules/icecast/metadata.yaml
@@ -0,0 +1,169 @@
+plugin_name: go.d.plugin
+modules:
+ - meta:
+ plugin_name: go.d.plugin
+ module_name: icecast
+ monitored_instance:
+ name: Icecast
+ link: "https://icecast.org/"
+ categories:
+ - data-collection.media-streaming-servers
+ icon_filename: "icecast.svg"
+ related_resources:
+ integrations:
+ list: []
+ info_provided_to_referring_integrations:
+ description: ""
+ keywords:
+ - icecast
+ - streaming
+ - media
+ most_popular: false
+ overview:
+ data_collection:
+ metrics_description: "This collector monitors Icecast listener counts."
+ method_description: "It uses the Icecast server statistics `status-json.xsl` endpoint to retrieve the metrics."
+ supported_platforms:
+ include: []
+ exclude: []
+ multi_instance: true
+ additional_permissions:
+ description: ""
+ default_behavior:
+ auto_detection:
+ description: By default, it detects Icecast instances running on localhost that are listening on port 8000.
+ limits:
+ description: ""
+ performance_impact:
+ description: ""
+ setup:
+ prerequisites:
+ list:
+ - title: "Icecast minimum version"
+ description: "Needs at least Icecast version >= 2.4.0"
+ configuration:
+ file:
+ name: go.d/icecast.conf
+ options:
+ description: |
+ The following options can be defined globally: update_every, autodetection_retry.
+ folding:
+ title: "Config options"
+ enabled: true
+ list:
+ - name: update_every
+ description: Data collection frequency.
+ default_value: 1
+ required: false
+ - name: autodetection_retry
+ description: Recheck interval in seconds. Zero means no recheck will be scheduled.
+ default_value: 0
+ required: false
+ - name: url
+ description: Server URL.
+ default_value: http://127.0.0.1:8000
+ required: true
+ - name: timeout
+ description: HTTP request timeout.
+ default_value: 1
+ required: false
+ - name: username
+ description: Username for basic HTTP authentication.
+ default_value: ""
+ required: false
+ - name: password
+ description: Password for basic HTTP authentication.
+ default_value: ""
+ required: false
+ - name: proxy_url
+ description: Proxy URL.
+ default_value: ""
+ required: false
+ - name: proxy_username
+ description: Username for proxy basic HTTP authentication.
+ default_value: ""
+ required: false
+ - name: proxy_password
+ description: Password for proxy basic HTTP authentication.
+ default_value: ""
+ required: false
+ - name: method
+ description: HTTP request method.
+ default_value: POST
+ required: false
+ - name: body
+ description: HTTP request body.
+ default_value: ""
+ required: false
+ - name: headers
+ description: HTTP request headers.
+ default_value: ""
+ required: false
+ - name: not_follow_redirects
+ description: Redirect handling policy. Controls whether the client follows redirects.
+ default_value: false
+ required: false
+ - name: tls_skip_verify
+ description: Server certificate chain and hostname validation policy. Controls whether the client performs this check.
+ default_value: false
+ required: false
+ - name: tls_ca
+ description: Certification authority that the client uses when verifying the server's certificates.
+ default_value: ""
+ required: false
+ - name: tls_cert
+ description: Client TLS certificate.
+ default_value: ""
+ required: false
+ - name: tls_key
+ description: Client TLS key.
+ default_value: ""
+ required: false
+ examples:
+ folding:
+ enabled: true
+ title: Config
+ list:
+ - name: Basic
+ description: A basic example configuration.
+ folding:
+ enabled: false
+ config: |
+ jobs:
+ - name: local
+ url: http://127.0.0.1:8000
+ - name: Multi-instance
+ description: |
+ > **Note**: When you define multiple jobs, their names must be unique.
+
+ Collecting metrics from local and remote instances.
+ config: |
+ jobs:
+ - name: local
+ url: http://127.0.0.1:8000
+
+ - name: remote
+ url: http://192.0.2.1:8000
+ troubleshooting:
+ problems:
+ list: []
+ alerts: []
+ metrics:
+ folding:
+ title: Metrics
+ enabled: false
+ description: ""
+ availability: []
+ scopes:
+ - name: Icecast source
+ description: "These metrics refer to an icecast source."
+ labels:
+ - name: source
+ description: Source name.
+ metrics:
+ - name: icecast.listeners
+ description: Icecast Listeners
+ unit: "listeners"
+ chart_type: line
+ dimensions:
+ - name: listeners
diff --git a/src/go/plugin/go.d/modules/icecast/server_stats.go b/src/go/plugin/go.d/modules/icecast/server_stats.go
new file mode 100644
index 000000000..404d12555
--- /dev/null
+++ b/src/go/plugin/go.d/modules/icecast/server_stats.go
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package icecast
+
+import (
+ "encoding/json"
+ "fmt"
+)
+
+type (
+ serverStats struct {
+ IceStats *struct {
+ Source iceSource `json:"source"`
+ } `json:"icestats"`
+ }
+ iceSource []sourceStats
+ sourceStats struct {
+ ServerName string `json:"server_name"`
+ StreamStart string `json:"stream_start"`
+ Listeners int64 `json:"listeners"`
+ }
+)
+
+func (i *iceSource) UnmarshalJSON(data []byte) error {
+ var v any
+ if err := json.Unmarshal(data, &v); err != nil {
+ return err
+ }
+
+ switch v.(type) {
+ case []any:
+ type plain iceSource
+ return json.Unmarshal(data, (*plain)(i))
+ case map[string]any:
+ var s sourceStats
+ if err := json.Unmarshal(data, &s); err != nil {
+ return err
+ }
+ *i = []sourceStats{s}
+ default:
+ return fmt.Errorf("invalid source data type: expected array or object")
+ }
+
+ return nil
+}
diff --git a/src/go/plugin/go.d/modules/icecast/testdata/config.json b/src/go/plugin/go.d/modules/icecast/testdata/config.json
new file mode 100644
index 000000000..984c3ed6e
--- /dev/null
+++ b/src/go/plugin/go.d/modules/icecast/testdata/config.json
@@ -0,0 +1,20 @@
+{
+ "update_every": 123,
+ "url": "ok",
+ "body": "ok",
+ "method": "ok",
+ "headers": {
+ "ok": "ok"
+ },
+ "username": "ok",
+ "password": "ok",
+ "proxy_url": "ok",
+ "proxy_username": "ok",
+ "proxy_password": "ok",
+ "timeout": 123.123,
+ "not_follow_redirects": true,
+ "tls_ca": "ok",
+ "tls_cert": "ok",
+ "tls_key": "ok",
+ "tls_skip_verify": true
+}
diff --git a/src/go/plugin/go.d/modules/icecast/testdata/config.yaml b/src/go/plugin/go.d/modules/icecast/testdata/config.yaml
new file mode 100644
index 000000000..8558b61cc
--- /dev/null
+++ b/src/go/plugin/go.d/modules/icecast/testdata/config.yaml
@@ -0,0 +1,17 @@
+update_every: 123
+url: "ok"
+body: "ok"
+method: "ok"
+headers:
+ ok: "ok"
+username: "ok"
+password: "ok"
+proxy_url: "ok"
+proxy_username: "ok"
+proxy_password: "ok"
+timeout: 123.123
+not_follow_redirects: yes
+tls_ca: "ok"
+tls_cert: "ok"
+tls_key: "ok"
+tls_skip_verify: yes
diff --git a/src/go/plugin/go.d/modules/icecast/testdata/stats_multi_source.json b/src/go/plugin/go.d/modules/icecast/testdata/stats_multi_source.json
new file mode 100644
index 000000000..0a9c45151
--- /dev/null
+++ b/src/go/plugin/go.d/modules/icecast/testdata/stats_multi_source.json
@@ -0,0 +1,46 @@
+{
+ "icestats": {
+ "admin": "icemaster@localhost",
+ "host": "localhost",
+ "location": "Earth",
+ "server_id": "Icecast 2.4.4",
+ "server_start": "Wed, 17 Jul 2024 11:27:40 +0300",
+ "server_start_iso8601": "2024-07-17T11:27:40+0300",
+ "source": [
+ {
+ "audio_info": "ice-bitrate=128;ice-channels=2;ice-samplerate=44100",
+ "genre": "(null)",
+ "ice-bitrate": 128,
+ "ice-channels": 2,
+ "ice-samplerate": 44100,
+ "listener_peak": 2,
+ "listeners": 1,
+ "listenurl": "http://localhost:8000/line.nsv",
+ "server_description": "(null)",
+ "server_name": "abc",
+ "server_type": "audio/mpeg",
+ "server_url": "(null)",
+ "stream_start": "Wed, 17 Jul 2024 12:10:20 +0300",
+ "stream_start_iso8601": "2024-07-17T12:10:20+0300",
+ "dummy": null
+ },
+ {
+ "audio_info": "ice-bitrate=128;ice-channels=2;ice-samplerate=44100",
+ "genre": "(null)",
+ "ice-bitrate": 128,
+ "ice-channels": 2,
+ "ice-samplerate": 44100,
+ "listener_peak": 10,
+ "listeners": 10,
+ "listenurl": "http://localhost:8000/lineb.nsv",
+ "server_description": "(null)",
+ "server_name": "efg",
+ "server_type": "audio/mpeg",
+ "server_url": "(null)",
+ "stream_start": "Wed, 17 Jul 2024 12:10:20 +0300",
+ "stream_start_iso8601": "2024-07-17T12:10:20+0300",
+ "dummy": null
+ }
+ ]
+ }
+}
diff --git a/src/go/plugin/go.d/modules/icecast/testdata/stats_no_sources.json b/src/go/plugin/go.d/modules/icecast/testdata/stats_no_sources.json
new file mode 100644
index 000000000..3af4fbe37
--- /dev/null
+++ b/src/go/plugin/go.d/modules/icecast/testdata/stats_no_sources.json
@@ -0,0 +1,11 @@
+{
+ "icestats": {
+ "admin": "icemaster@localhost",
+ "host": "localhost",
+ "location": "Earth",
+ "server_id": "Icecast 2.4.4",
+ "server_start": "Wed, 17 Jul 2024 11:27:40 +0300",
+ "server_start_iso8601": "2024-07-17T11:27:40+0300",
+ "dummy": null
+ }
+} \ No newline at end of file
diff --git a/src/go/plugin/go.d/modules/icecast/testdata/stats_single_source.json b/src/go/plugin/go.d/modules/icecast/testdata/stats_single_source.json
new file mode 100644
index 000000000..9d14e7d64
--- /dev/null
+++ b/src/go/plugin/go.d/modules/icecast/testdata/stats_single_source.json
@@ -0,0 +1,27 @@
+{
+ "icestats": {
+ "admin": "icemaster@localhost",
+ "host": "localhost",
+ "location": "Earth",
+ "server_id": "Icecast 2.4.4",
+ "server_start": "Wed, 17 Jul 2024 11:27:40 +0300",
+ "server_start_iso8601": "2024-07-17T11:27:40+0300",
+ "source": {
+ "audio_info": "ice-bitrate=128;ice-channels=2;ice-samplerate=44100",
+ "genre": "(null)",
+ "ice-bitrate": 128,
+ "ice-channels": 2,
+ "ice-samplerate": 44100,
+ "listener_peak": 2,
+ "listeners": 1,
+ "listenurl": "http://localhost:8000/line.nsv",
+ "server_description": "(null)",
+ "server_name": "abc",
+ "server_type": "audio/mpeg",
+ "server_url": "(null)",
+ "stream_start": "Wed, 17 Jul 2024 12:10:20 +0300",
+ "stream_start_iso8601": "2024-07-17T12:10:20+0300",
+ "dummy": null
+ }
+ }
+}