]> git.sesse.net Git - vlc/commitdiff
RRD output (Refs:#473)
authorClément Stenac <zorglub@videolan.org>
Sat, 28 Jan 2006 10:56:47 +0000 (10:56 +0000)
committerClément Stenac <zorglub@videolan.org>
Sat, 28 Jan 2006 10:56:47 +0000 (10:56 +0000)
This is a quick hack, which should in the end be merged in a way to expose stats

doc/rrd-howto.txt [new file with mode: 0644]
modules/misc/logger.c

diff --git a/doc/rrd-howto.txt b/doc/rrd-howto.txt
new file mode 100644 (file)
index 0000000..b8c3cc8
--- /dev/null
@@ -0,0 +1,12 @@
+
+# First, create the RRD file
+rrdtool create vlc.rrd --step 1 "DS:in:GAUGE:10:0:30000" "DS:demux:GAUGE:10:0:30000" "DS:out:GAUGE:10:0:30000" "RRA:AVERAGE:0,5:1:86400"
+
+# Start "listening" the RRD file
+tail -f rrd |while read in;do;echo $in;rrdtool update vlc.rrd `echo $in`;done
+
+# Start vlc
+vlc normal_vlc_stuff --extraintf logger --rrd-file rrd
+
+# Graph the last 5 minutes (300 seconds)
+rrdtool graph vlc.png --start -300 "DEF:inp=vlc.rrd:in:AVERAGE" "DEF:dem=vlc.rrd:demux:AVERAGE" "DEF:out=vlc.rrd:out:AVERAGE" "LINE2:dem#00FF00:Demux bitrate" "LINE2:inp#0000FF:Input bitrate" "LINE2:out#FF0000:Output bitrate"
index 585b78dbd817ac1d1928962ae5db3aa6bb212e18..ccdeefccaa8e2de938846cae531d107d2e42205e 100644 (file)
@@ -77,6 +77,8 @@
 struct intf_sys_t
 {
     int i_mode;
+    FILE *p_rrd;
+    mtime_t last_update;
 
     FILE *    p_file; /* The log file */
     msg_subscription_t *p_sub;
@@ -96,6 +98,8 @@ static void HtmlPrint         ( const msg_item_t *, FILE * );
 static void SyslogPrint       ( const msg_item_t *);
 #endif
 
+static void DoRRD( intf_thread_t *p_intf );
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -127,6 +131,9 @@ vlc_module_begin();
                 VLC_FALSE );
         change_string_list( mode_list, mode_list_text, 0 );
 
+    add_string( "rrd-file", NULL, NULL, N_("RRD output file") ,
+                    N_("Output data for RRDTool in this file" ), VLC_TRUE );
+
     set_capability( "interface", 0 );
     set_callbacks( Open, Close );
 vlc_module_end();
@@ -137,7 +144,7 @@ vlc_module_end();
 static int Open( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
-    char *psz_mode, *psz_file;
+    char *psz_mode, *psz_file, *psz_rrd_file;
 
     CONSOLE_INTRO_MSG;
     msg_Info( p_intf, "Using logger..." );
@@ -261,6 +268,15 @@ static int Open( vlc_object_t *p_this )
 #endif
     }
 
+    p_intf->p_sys->last_update = 0;
+    p_intf->p_sys->p_rrd = NULL;
+
+    psz_rrd_file = config_GetPsz( p_intf, "rrd-file" );
+    if( psz_rrd_file && *psz_rrd_file )
+    {
+        p_intf->p_sys->p_rrd = fopen( psz_rrd_file, "w" );
+    }
+
     p_intf->p_sys->p_sub = msg_Subscribe( p_intf , MSG_QUEUE_NORMAL );
     p_intf->pf_run = Run;
 
@@ -316,6 +332,9 @@ static void Run( intf_thread_t *p_intf )
         FlushQueue( p_intf->p_sys->p_sub, p_intf->p_sys->p_file,
                     p_intf->p_sys->i_mode );
 
+        if( p_intf->p_sys->p_rrd )
+            DoRRD( p_intf );
+
         msleep( INTF_IDLE_SLEEP );
     }
 }
@@ -400,3 +419,24 @@ static void HtmlPrint( const msg_item_t *p_msg, FILE *p_file )
     LOG_STRING( "</font>\n", p_file );
 }
 
+static void DoRRD( intf_thread_t *p_intf )
+{
+    playlist_t *p_playlist;
+    float f_input_bitrate;
+    if( mdate() - p_intf->p_sys->last_update < 1000000 )
+        return;
+    p_intf->p_sys->last_update = mdate();
+
+    p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+                                                FIND_ANYWHERE );
+    if( p_playlist && p_playlist->p_stats )
+    {
+        fprintf( p_intf->p_sys->p_rrd, I64Fi":%f:%f:%f\n",
+                   p_intf->p_sys->last_update/1000000,
+                   (float)(p_playlist->p_stats->f_input_bitrate)*1000,
+                   (float)(p_playlist->p_stats->f_demux_bitrate)*1000,
+                   (float)(p_playlist->p_stats->f_output_bitrate)*1000 );
+        fflush( p_intf->p_sys->p_rrd );
+        vlc_object_release( p_playlist );
+    }
+}