[banshee] [Hyena.Metrics] Fix HttpPoster, and add server script



commit 35281884546517fb896d66210d1bf123a8e18454
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Fri Feb 12 19:35:21 2010 -0800

    [Hyena.Metrics] Fix HttpPoster, and add server script

 extras/metrics.py                               |   49 +++++++++++++++++++++++
 src/Libraries/Hyena/Hyena.Metrics/HttpPoster.cs |   13 +++---
 2 files changed, 56 insertions(+), 6 deletions(-)
---
diff --git a/extras/metrics.py b/extras/metrics.py
new file mode 100755
index 0000000..6083876
--- /dev/null
+++ b/extras/metrics.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python
+
+import cgi
+import os
+
+# INITIAL SETUP:
+# 1. mkdir data
+# 2. chmod o-xr data
+# 3. echo 0 > data/count
+# 4. change data_dir below
+data_dir = '/home/bansheeweb/download.banshee-project.org/metrics/data/';
+
+uploaded = False
+form = cgi.FieldStorage()
+
+if form.file:
+    # Read the current count
+    f = open(data_dir + 'count', 'r')
+    count = f.read ()
+    count = int(count)
+    f.close ()
+
+    # Increment it and write it out
+    f = open(data_dir + 'count', 'w')
+    count = count + 1
+    f.write (str(count));
+    f.close ();
+
+    # Save the POSTed file
+    filename = data_dir + str(count) + '.json'
+    f = open(filename, 'w')
+
+    while 1:
+        line = form.file.readline()
+        if not line: break
+        f.write (line)
+    
+    f.close ();
+
+    # gzip it
+    os.system ('gzip ' + filename)
+    uploaded = True
+
+if uploaded:
+    print "Status-Code: 200"
+    print "Content-type: text/html"
+    print
+else:
+    print "Status-Code: 500"
diff --git a/src/Libraries/Hyena/Hyena.Metrics/HttpPoster.cs b/src/Libraries/Hyena/Hyena.Metrics/HttpPoster.cs
index 1a37613..1a81480 100644
--- a/src/Libraries/Hyena/Hyena.Metrics/HttpPoster.cs
+++ b/src/Libraries/Hyena/Hyena.Metrics/HttpPoster.cs
@@ -28,14 +28,14 @@ using System;
 using System.IO;
 using System.Net;
 
-/*namespace Hyena.Metrics
+namespace Hyena.Metrics
 {
     public class HttpPoster
     {
         private string url;
         private MetricsCollection metrics;
 
-        public void HttpPoster (string url, MetricsCollection metrics)
+        public HttpPoster (string url, MetricsCollection metrics)
         {
             this.url = url;
             this.metrics = metrics;
@@ -53,13 +53,14 @@ using System.Net;
             try {
                 using (var stream = request.GetRequestStream ()) {
                     using (var writer = new StreamWriter (stream)) {
-                        foreach (var metric in metrics.Metrics) {
-                            writer.Write (metric.ToString ());
-                        }
+                        writer.Write (metrics.ToJsonString ());
                     }
                 }
 
                 var response = (HttpWebResponse) request.GetResponse ();
+                using (var strm = new StreamReader (response.GetResponseStream ())) {
+                    Console.WriteLine (strm.ReadToEnd ());
+                }
                 return response.StatusCode == HttpStatusCode.OK;
             } catch (Exception e) {
                 Log.Exception ("Error posting metrics", e);
@@ -68,4 +69,4 @@ using System.Net;
             return false;
         }
     }
-}*/
+}
\ No newline at end of file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]