Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
denise 2013-01-08 17:51:58 -05:00
commit 03da2aee80
9 changed files with 63 additions and 11 deletions

View File

@ -42,6 +42,7 @@ class ApiController extends Zend_Controller_Action
->addActionContext('notify-webstream-data' , 'json')
->addActionContext('get-stream-parameters' , 'json')
->addActionContext('push-stream-stats' , 'json')
->addActionContext('update-stream-setting-table' , 'json')
->initContext();
}
@ -979,5 +980,14 @@ class ApiController extends Zend_Controller_Action
Application_Model_ListenerStat::insertDataPoints($data);
$this->view->data = $data;
}
public function updateStreamSettingTableAction() {
$request = $this->getRequest();
$data = json_decode($request->getParam("data"), true);
foreach ($data as $k=>$v) {
Application_Model_StreamSetting::SetListenerStatError($k, $v);
}
}
}

View File

@ -47,6 +47,15 @@ class ListenerstatController extends Zend_Controller_Action
'his_time_end' => $end->format("H:i")
));
$errorStatus = Application_Model_StreamSetting::GetAllListenerStatErrors();
Logging::info($errorStatus);
$out = array();
foreach ($errorStatus as $v) {
$key = explode('_listener_stat_error', $v['keyname']);
$out[$key[0]] = $v['value'];
}
$this->view->errorStatus = $out;
$this->view->date_form = $form;
}

View File

@ -457,4 +457,13 @@ class Application_Model_StreamSetting
public static function setOffAirMeta($offAirMeta){
self::setValue("off_air_meta", $offAirMeta, "string");
}
public static function GetAllListenerStatErrors(){
$sql = "SELECT * FROM cc_stream_setting WHERE keyname like :p1";
return Application_Common_Database::prepareAndExecute($sql, array(':p1'=>'%_listener_stat_error'));
}
public static function SetListenerStatError($key, $v) {
self::setValue($key, $v, 'string');
}
}

View File

@ -2,5 +2,13 @@
<?php echo _("Listener Count Over Time")?><br>
<div id="flot_placeholder" style="width:600px;height:300px;margin:0px 50px 0px 50px"></div>
<div id="legend" style="width:600px;height:70px;margin:0px 50px 0px 50px"></div>
<div id="date_form" style="margin:0px 50px 0px 50px"><?php echo $this->date_form; ?></div>
<div id="date_form" style="float:left; margin:0px 50px 0px 50px"><?php echo $this->date_form; ?></div>
<div id="errorStatus" style="float:right; width: 400px">
<fieldset class="padded stream-setting-global">
<legend>Status</legend>
<?php foreach ($this->errorStatus as $k=>$v) {?>
<div class='stream-status <?php echo ($v == 'OK')? 'status-good' : 'status-error' ?>'><h3><?php echo $k?>: <?php echo $v?></h3></div>
<?php }?>
</fieldset>
</div>
</div>

View File

@ -1,9 +1,6 @@
INSERT INTO cc_subjs ("login", "type", "pass") VALUES ('admin', 'A', md5('admin'));
-- added in 2.3
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('off_air_meta', 'Airtime - offline', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_listener_stat_error', '', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_listener_stat_error', '', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s3_listener_stat_error', '', 'string');
-- end of added in 2.3
-- added in 2.1

View File

@ -124,3 +124,5 @@ notify_liquidsoap_started = 'rabbitmq-do-push/api_key/%%api_key%%/format/json'
get_stream_parameters = 'get-stream-parameters/api_key/%%api_key%%/format/json'
push_stream_stats = 'push-stream-stats/api_key/%%api_key%%/format/json'
update_stream_setting_table = 'update-stream-setting-table/api_key/%%api_key%%/format/json'

View File

@ -383,3 +383,7 @@ class AirtimeApiClient(object):
# TODO : users of this method should do their own error handling
response = self.services.push_stream_stats(_post_data={'data': json.dumps(data)})
return response
def update_stream_setting_table(self, data):
response = self.services.update_stream_setting_table(_post_data={'data': json.dumps(data)})
return response

View File

@ -407,7 +407,7 @@ end
# fade using both cross() and switch().
def input.http_restart(~id,~initial_url="http://dummy/url")
source = input.http(buffer=5.,max=15.,id=id,autostart=false,initial_url)
source = audio_to_stereo(input.http(buffer=5.,max=15.,id=id,autostart=false,initial_url))
def stopped()
"stopped" == list.hd(server.execute("#{id}.status"))

View File

@ -95,15 +95,25 @@ class ListenerStat(Thread):
#connections
for k, v in stream_parameters.items():
if v["enable"] == 'true':
if v["output"] == "icecast":
stats.append(self.get_icecast_stats(v))
else:
stats.append(self.get_shoutcast_stats(v))
try:
if v["output"] == "icecast":
stats.append(self.get_icecast_stats(v))
else:
stats.append(self.get_shoutcast_stats(v))
self.update_listener_stat_error(v["mount"], 'OK')
except Exception, e:
self.logger.error('Exception: %s', e)
self.update_listener_stat_error(v["mount"], str(e))
return stats
def push_stream_stats(self, stats):
self.api_client.push_stream_stats(stats)
def update_listener_stat_error(self, stream_id, error):
keyname = '%s_listener_stat_error' % stream_id
data = {keyname: error}
self.api_client.update_stream_setting_table(data)
def run(self):
#Wake up every 120 seconds and gather icecast statistics. Note that we
@ -116,8 +126,11 @@ class ListenerStat(Thread):
stats = self.get_stream_stats(stream_parameters["stream_params"])
self.logger.debug(stats)
self.push_stream_stats(stats)
if not stats:
self.logger.error("Not able to get listener stats")
else:
self.push_stream_stats(stats)
except Exception, e:
self.logger.error('Exception: %s', e)