-
Notifications
You must be signed in to change notification settings - Fork 132
OneBusAway Watchdog
OneBusAway Watchdog is a simple framework for retrieving metrics about schedule and realtime data. When hosting OneBusAway, it is convenient to know information about the realtime data, and perhaps to even set alarms should the data fall outside what is expected.
The idea is simple, for each metric of concern a webservice is created that exposes that data in a readily queryable format. Take for example a common issue with realtime feeds, counting the number of tripIds that were received but not matched to the current transit data bundle. By making a GET request on the webservice below:
onebusaway-watchdog-webapp/api/metric/realtime/trip/{agencyId}/unmatched
Returns:
{
"currentTimestamp":1402402125238,
"metricName":"unmatched-trips",
"metricValue":1,
"response":"SUCCESS",
"errorMessage":null
}
Here, the agencyId is what is configured in the transit data bundle (e.g., 1). The metricValue property contains the response, indicating that for the last update from the realtime feed, we received one tripId that did not match to the bundle. The metricValue property should only be considered when the response property is populated with SUCCESS. Should the response not be a SUCCESS, the errorMessage property may be populated with a descriptive reason of the failure.
Below is a table of webservices that have been implemented. Adding another metric is trivial, it simply requires extending MetricResource.
Create a data-sources.xml and place it in WEB-INF/classes (as is the OneBusAway convention). Here is an example.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<!-- define your data source here if required -->
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"
value="java:comp/env/jdbc/appDB"/>
<property name="lookupOnStartup"
value="true"/>
<property name="cache"
value="true"/>
<property name="proxyInterface"
value="javax.sql.DataSource"/>
<property name="resourceRef"
value="true" />
</bean>
<!-- for each realtime feed define a realtime source with a unique id -->
<bean id="feed1_avl" class="org.onebusaway.transit_data_federation.impl.realtime.gtfs_realtime.GtfsRealtimeSource">
<property name="tripUpdatesUrl" value="http://localhost:7171/feed1/trip-updates" />
<property name="vehiclePositionsUrl" value="http://localhost:7171/feed1/vehicle-positions" />
<property name="refreshInterval" value="30"/>
<!-- if you need to map this data source to a specific agency_id in your bundle use this -->
<property name="agencyIds">
<list>
<value>1</value>
</list>
</property>
<!-- a friendly name for the feed in logging -->
<property name="feedId" value="feed1"/>
</bean>
<bean id="feed2_avl" class="org.onebusaway.transit_data_federation.impl.realtime.gtfs_realtime.GtfsRealtimeSource">
<property name="tripUpdatesUrl" value="http://localhost:7272/feed2/trip-updates" />
<property name="vehiclePositionsUrl" value="http://localhost:7272/feed2/vehicle-positions" />
<property name="refreshInterval" value="30"/>
<!-- if you need to map this data source to a specific agency_id in your bundle use this -->
<property name="agencyIds">
<list>
<value>2</value>
</list>
</property>
<!-- a friendly name for the feed in logging -->
<property name="feedId" value="feed2"/>
</bean>
<!-- configure where to store bundles -->
<bean class="org.onebusaway.container.spring.SystemPropertyOverrideConfigurer">
<property name="order" value="-2" />
<property name="properties">
<props>
<prop key="bundlePath">/var/lib/oba/oba-watchodg-bundle</prop>
</props>
</property>
</bean>
<!-- now define the metrics from the realtime sources defined above -->
<bean id="metricConfiguration" class="org.onebusaway.watchdog.model.MetricConfiguration">
<property name="transitDataService" ref="transitDataServiceImpl"/>
<property name="monitoredDataSources">
<list>
<ref bean="feed1_avl" />
<ref bean="feed2_avl" />
</list>
</property>
</bean>
<!-- if you are running an admin server, configure the watchdog to retrieve bundles from it -->
<!--
<bean id="httpServiceClient" class="org.onebusaway.transit_data_federation.util.HttpServiceClientImpl" >
<constructor-arg type="java.lang.String" value="127.0.0.1"/>
<constructor-arg type="java.lang.Integer" value="8080" />
<constructor-arg type="java.lang.String" value="/api/" />
</bean>
<bean id="bundleManagementService" class="org.onebusaway.transit_data_federation.impl.bundle.BundleManagementServiceImpl">
<property name="bundleStoreRoot" value="/var/lib/oba/oba-watchdog-bundle" />
<property name="standaloneMode" value="false" />
</bean>
-->
<!-- if you are manually deploying bundles follow this configuration -->
<!-- NOTE: YOU CANNOT SHARE THE SAME BUNDLE BETWEEN OBA INSTANCES -->
<!-- YOU NEED TO COPY THE BUNDLE TO A NEW DIRECTORY -->
<bean id="bundleManagementService" class="org.onebusaway.transit_data_federation.impl.bundle.BundleManagementServiceImpl">
<property name="bundleStoreRoot" value="/var/lib/oba/oba-watchdog-bundle" />
<property name="standaloneMode" value="true" />
</bean>
</beans>