Wowza Streaming Server XML parser

Hello, I want to properly transfer the data in the following XML structure obtained from Wowza Streaming Engine (http://localhost:8080/connectioncounts.xml) to InfluxDB using Telegraf, Golang, or any other method and visualize it in Grafana. However, I have not been successful in any way. I don’t have any knowledge of Golang like the article Monitor Icecast and Wowza listeners with dockerized InfluxDB, Grafana and Go | by Peter | Medium, which was prepared 8 years ago.

Is there anyone who can help?"

[The provided XML data is below.]

<WowzaStreamingEngine>
 <ConnectionsCurrent>0</ConnectionsCurrent>
 <ConnectionsTotal>0</ConnectionsTotal>
 <ConnectionsTotalAccepted>0</ConnectionsTotalAccepted>
 <ConnectionsTotalRejected>0</ConnectionsTotalRejected>
<MessagesInBytesRate>158255.0</MessagesInBytesRate>
<MessagesOutBytesRate>0.0</MessagesOutBytesRate>
<VHost>
<Name>_defaultVHost_</Name>
 <TimeRunning>58836.737</TimeRunning>
 <ConnectionsLimit>0</ConnectionsLimit>
 <ConnectionsCurrent>0</ConnectionsCurrent>
 <ConnectionsTotal>0</ConnectionsTotal>
 <ConnectionsTotalAccepted>0</ConnectionsTotalAccepted>
 <ConnectionsTotalRejected>0</ConnectionsTotalRejected>
 <MessagesInBytesRate>158165.0</MessagesInBytesRate>
 <MessagesOutBytesRate>0.0</MessagesOutBytesRate>
<Application>
<Name>live</Name>
<Status>loaded</Status>
<TimeRunning>58835.252</TimeRunning>
 <ConnectionsCurrent>0</ConnectionsCurrent>
 <ConnectionsTotal>0</ConnectionsTotal>
 <ConnectionsTotalAccepted>0</ConnectionsTotalAccepted>
 <ConnectionsTotalRejected>0</ConnectionsTotalRejected>
<MessagesInBytesRate>171547.0</MessagesInBytesRate>
<MessagesOutBytesRate>0.0</MessagesOutBytesRate>
 <ApplicationInstance>
 <Name>_definst_</Name>
 <TimeRunning>58835.194</TimeRunning>
 <ConnectionsCurrent>0</ConnectionsCurrent>
 <ConnectionsTotal>0</ConnectionsTotal>
 <ConnectionsTotalAccepted>0</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>0</ConnectionsTotalRejected>
<MessagesInBytesRate>170777.0</MessagesInBytesRate>
<MessagesOutBytesRate>0.0</MessagesOutBytesRate>
<Stream>
  <Name>KafaRadyo.stream</Name>
  <SessionsFlash>0</SessionsFlash>
  <SessionsCupertino>0</SessionsCupertino>
  <SessionsSanJose>0</SessionsSanJose>
  <SessionsSmooth>0</SessionsSmooth>
  <SessionsRTSP>0</SessionsRTSP>
  <SessionsWebRTC>0</SessionsWebRTC>
  <SessionsMPEGDash>0</SessionsMPEGDash>
  <SessionsTotal>0</SessionsTotal>
</Stream>
<Stream>
<Name>PowerFM.stream</Name>
  <SessionsFlash>0</SessionsFlash>
  <SessionsCupertino>0</SessionsCupertino>
  <SessionsSanJose>0</SessionsSanJose>
  <SessionsSmooth>0</SessionsSmooth>
  <SessionsRTSP>0</SessionsRTSP>
  <SessionsWebRTC>0</SessionsWebRTC>
  <SessionsMPEGDash>0</SessionsMPEGDash>
  <SessionsTotal>0</SessionsTotal>
</Stream>
<Stream>
</ApplicationInstance>
</Application>
</VHost>
</WowzaStreamingEngine>

Hello @aydinyildirim73,
Have you taken a look at this tutorial?

I think its a great place to start.
Parsing it depends on what you want the output to be.

Also @jpowers might be able to help you here.
Thank you!!

Agreed with @Anaisdg. Take a look at that tutorial around the use of the xml parser. The big question to ask is what tags and fields you want to capture from that xml and then develop the parser settings to pull those out!

If you gave an example of the output you are trying to achieve that might help and what you have tried so far, we could possible provide some guidance.

Finally, I found solution. Thanks to ChatGPT :slight_smile: Here my golang solution, I hope It helps someone

package main

import (
	"encoding/xml"
	"fmt"
	"io/ioutil"
	"net/http"
	"strings"
	"time"
)

type Stream struct {
	Name         string `xml:"Name"`
	SessionsTotal int    `xml:"SessionsTotal"`
}

type ApplicationInstance struct {
	Streams []Stream `xml:"Stream"`
}

type Application struct {
	Name               string               `xml:"Name"`
	ApplicationInstance ApplicationInstance `xml:"ApplicationInstance"`
}

type VHost struct {
	Name        string       `xml:"Name"`
	ConnectionsCurrent int    `xml:"ConnectionsCurrent"`
	ConnectionsTotal int    `xml:"ConnectionsTotal"`
	Application []Application `xml:"Application"`
}

type WowzaData struct {
	ConnectionsCurrent int    `xml:"ConnectionsCurrent"`
	ConnectionsTotal int    `xml:"ConnectionsTotal"`
	VHost VHost `xml:"VHost"`
}

func main() {
    // my wowza server ip 
	url := "http://10.35.224.39:8086/connectioncounts"   
	resp, err := http.Get(url)
	if err != nil {
		fmt.Println("HTTP request error:", err)
		return
	}
	defer resp.Body.Close()

	xmlData, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("XML read error:", err)
		return
	}

	var result WowzaData
	err = xml.Unmarshal(xmlData, &result)
	if err != nil {
		fmt.Println("XML error:", err)
		return
	}

	// InfluxDB database
	org := "myOrganization"
	bucket := "wowzatest"
	token := "VYOPqXrLtd5CqrvLXNVv9XUaKeMH4IphjdSFFi_6BffslQuu2JpSr94SlA4JZJCGDPq4ibH7IyG3IORq03bThQ=x"

        //my local server ip
	influxURL := "http://10.35.224.39:9086"

	influxEndpoint := fmt.Sprintf("%s/api/v2/write?org=%s&bucket=%s&precision=ns", influxURL, org, bucket)
	req, err := http.NewRequest("POST", influxEndpoint, nil)
	if err != nil {
		fmt.Println("HTTP request error:", err)
		return
	}
	req.Header.Set("Authorization", "Token "+token)
	req.Header.Set("Content-Type", "text/plain")

vhost := result.VHost

	client := &http.Client{Timeout: 10 * time.Second}

	for _, app := range vhost.Application {
		instance := app.ApplicationInstance

		for _, stream := range instance.Streams {
			dataStream := fmt.Sprintf("wowza_stream_stats,stream_name=%s SessionsTotal=%d", stream.Name, stream.SessionsTotal)
			reqStream := ioutil.NopCloser(strings.NewReader(dataStream))
			req.Body = reqStream
			resp, err = client.Do(req)
			if err != nil {
				fmt.Println("Error to send  InfluxDB:", err)
				return
			}
			defer resp.Body.Close()
		}
	}

	fmt.Println("Successfully send to InfluxDB")
}

Here, my sample XML output from wowza server

<WowzaStreamingEngine>
<ConnectionsCurrent>1</ConnectionsCurrent>
<ConnectionsTotal>1</ConnectionsTotal>
<ConnectionsTotalAccepted>1</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>0</ConnectionsTotalRejected>
<MessagesInBytesRate>258767.0</MessagesInBytesRate>
<MessagesOutBytesRate>16651.0</MessagesOutBytesRate>
<VHost>
  <Name>_defaultVHost_</Name>
     <TimeRunning>430507.262</TimeRunning>
     <ConnectionsLimit>0</ConnectionsLimit>
    <ConnectionsCurrent>1</ConnectionsCurrent>
    <ConnectionsTotal>1</ConnectionsTotal>
    <ConnectionsTotalAccepted>1</ConnectionsTotalAccepted>
    <ConnectionsTotalRejected>0</ConnectionsTotalRejected>
    <MessagesInBytesRate>258767.0</MessagesInBytesRate>
    <MessagesOutBytesRate>16651.0</MessagesOutBytesRate>
  <Application>
<Name>live</Name>
<Status>loaded</Status>
<TimeRunning>430506.524</TimeRunning>
<ConnectionsCurrent>1</ConnectionsCurrent>
<ConnectionsTotal>1</ConnectionsTotal>
<ConnectionsTotalAccepted>1</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>0</ConnectionsTotalRejected>
<MessagesInBytesRate>259457.0</MessagesInBytesRate>
<MessagesOutBytesRate>16651.0</MessagesOutBytesRate>
<ApplicationInstance>
<Name>_definst_</Name>
<TimeRunning>430506.492</TimeRunning>
<ConnectionsCurrent>1</ConnectionsCurrent>
<ConnectionsTotal>1</ConnectionsTotal>
<ConnectionsTotalAccepted>1</ConnectionsTotalAccepted>
<ConnectionsTotalRejected>0</ConnectionsTotalRejected>
<MessagesInBytesRate>253438.0</MessagesInBytesRate>
<MessagesOutBytesRate>16654.0</MessagesOutBytesRate>

<Stream>
    <Name>PowerFM.stream</Name>
    <SessionsFlash>0</SessionsFlash>
    <SessionsCupertino>0</SessionsCupertino>
    <SessionsSanJose>0</SessionsSanJose>
    <SessionsSmooth>0</SessionsSmooth>
    <SessionsRTSP>0</SessionsRTSP>
    <SessionsWebRTC>0</SessionsWebRTC>
    <SessionsMPEGDash>0</SessionsMPEGDash>
    <SessionsTotal>3</SessionsTotal>
</Stream>

<Stream>
    <Name>RadyoNostalji.stream</Name>
    <SessionsFlash>0</SessionsFlash>
    <SessionsCupertino>0</SessionsCupertino>
    <SessionsSanJose>0</SessionsSanJose>
   <SessionsSmooth>0</SessionsSmooth>
   <SessionsRTSP>0</SessionsRTSP>
   <SessionsWebRTC>0</SessionsWebRTC>
   <SessionsMPEGDash>0</SessionsMPEGDash>
   <SessionsTotal>2</SessionsTotal>
</Stream>
</ApplicationInstance>
</Application>
</VHost>
</WowzaStreamingEngine>