We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Display additional information in passenger-status: the number of requests 
processed by an application instance so far, and its uptime.
Hongli Lai (Phusion) (author)
Sat Aug 02 06:39:27 -0700 2008
commit  eb65c910a9be2da6c6402a2e76188117b116eb58
tree    c408f9eac734e5cb4778b74a2b5b9af448e2300c
parent  b0424844cd6ab03591b26f5c89291fafd26aed77
...
69
70
71
 
 
 
 
72
73
74
...
300
301
302
 
303
304
305
...
69
70
71
72
73
74
75
76
77
78
...
304
305
306
307
308
309
310
0
@@ -69,6 +69,10 @@ explicitly define some special types:
0
   
0
   An AppContainer has the following members:
0
   * app - An Application object, representing an application instance.
0
+ * start_time (time) - The time at which this application instance was
0
+ started. It's set to the current time by AppContainer's constructor.
0
+ * processed_requests (integer) - The number of requests processed by this
0
+ application instance so far.
0
   * last_used (time) - The last time a session for this application instance
0
     was opened or closed.
0
   * sessions (integer) - The number of open sessions for this application
0
@@ -300,6 +304,7 @@ function session_has_been_closed(container):
0
     if domain != nil:
0
       container.last_used = current_time()
0
       container.sessions--
0
+ container.processed++
0
       if container.sessions == 0:
0
         domain.instances.move_to_front(container.iterator)
0
         container.ia_iterator = inactive_apps.add_to_back(container.app)
...
117
118
119
 
120
121
 
122
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
125
126
...
139
140
141
 
 
 
142
143
144
...
163
164
165
 
166
167
168
...
272
273
274
275
 
276
277
 
 
 
278
279
280
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
168
169
170
171
172
173
174
175
176
...
195
196
197
198
199
200
201
...
305
306
307
 
308
309
 
310
311
312
313
314
315
0
@@ -117,10 +117,39 @@ private:
0
   
0
   struct AppContainer {
0
     ApplicationPtr app;
0
+ time_t startTime;
0
     time_t lastUsed;
0
     unsigned int sessions;
0
+ unsigned int processed;
0
     AppContainerList::iterator iterator;
0
     AppContainerList::iterator ia_iterator;
0
+
0
+ AppContainer() {
0
+ startTime = time(NULL);
0
+ processed = 0;
0
+ }
0
+
0
+ /**
0
+ * Returns the uptime of this AppContainer so far, as a string.
0
+ */
0
+ string uptime() const {
0
+ time_t seconds = time(NULL) - startTime;
0
+ stringstream result;
0
+
0
+ if (seconds >= 60) {
0
+ time_t minutes = seconds / 60;
0
+ if (minutes >= 60) {
0
+ time_t hours = minutes / 60;
0
+ minutes = minutes % 60;
0
+ result << hours << "h ";
0
+ }
0
+
0
+ seconds = seconds % 60;
0
+ result << minutes << "m ";
0
+ }
0
+ result << seconds << "s";
0
+ return result.str();
0
+ }
0
   };
0
   
0
   struct SharedData {
0
@@ -139,6 +168,9 @@ private:
0
   
0
   typedef shared_ptr<SharedData> SharedDataPtr;
0
   
0
+ /**
0
+ * Function object which will be called when a session has been closed.
0
+ */
0
   struct SessionCloseCallback {
0
     SharedDataPtr data;
0
     weak_ptr<AppContainer> container;
0
@@ -163,6 +195,7 @@ private:
0
         AppContainerList *instances = &it->second->instances;
0
         container->lastUsed = time(NULL);
0
         container->sessions--;
0
+ container->processed++;
0
         if (container->sessions == 0) {
0
           instances->erase(container->iterator);
0
           instances->push_front(container);
0
@@ -272,9 +305,11 @@ private:
0
         char buf[128];
0
         
0
         snprintf(buf, sizeof(buf),
0
- "PID: %-8lu Sessions: %d",
0
+ "PID: %-5lu Sessions: %-2u Processed: %-5u Uptime: %s",
0
             (unsigned long) container->app->getPid(),
0
- container->sessions);
0
+ container->sessions,
0
+ container->processed,
0
+ container->uptime().c_str());
0
         result << " " << buf << endl;
0
       }
0
       result << endl;

Comments

    No one has commented yet.