|
@@ -108,26 +108,43 @@ size_t pyfcgi_stats_format()
|
108
|
108
|
PACKAGE_STRING, uptime, since);
|
109
|
109
|
|
110
|
110
|
// Request counter stats formating
|
|
111
|
+ double avgs[4];
|
|
112
|
+ int last_rs, ret;
|
|
113
|
+
|
|
114
|
+ do
|
|
115
|
+ {
|
|
116
|
+ ret = pyfcgi_stats_avg(pyfcgi_stats.reqs,
|
|
117
|
+ &(pyfcgi_stats.cur_req), PYFCGI_STATS_REQS_SAMPLES,
|
|
118
|
+ &last_rs, avgs);
|
|
119
|
+ } while(ret < 0 && errno == EINTR);
|
|
120
|
+ pyfcgi_stats_buffprintf("Requests stats :\n1s:%dr/s 1m:%.2fr/s 5m:%.2fr/s 10m:%.2fr/s 15m:%.2fr/s\n",
|
|
121
|
+ last_rs, avgs[0], avgs[1], avgs[2], avgs[3]);
|
|
122
|
+ return pyfcgi_stats.buff_ptr;
|
|
123
|
+}
|
|
124
|
+
|
|
125
|
+int pyfcgi_stats_avg(const int data[], int *idx_first, int len,
|
|
126
|
+ int *last, double avgs[4])
|
|
127
|
+{
|
111
|
128
|
double r15, r10, r5, r1, rtmp;
|
112
|
129
|
unsigned long stmp; // stores a 60s req sum
|
113
|
|
- int i, cur_req, cur_rs, idx;
|
|
130
|
+ int i, cur, idx, first;
|
114
|
131
|
r15 = r10 = r5 = r1 = stmp = 0;
|
115
|
|
- cur_req = pyfcgi_stats.cur_req;
|
|
132
|
+ first = *idx_first;
|
116
|
133
|
//Block interrupt/ALARM ??
|
117
|
|
- for(i=0; i<PYFCGI_STATS_REQS_SAMPLES; i++)
|
|
134
|
+ for(i=0; i<len; i++)
|
118
|
135
|
{
|
119
|
|
- if(cur_req != pyfcgi_stats.cur_req)
|
|
136
|
+ if(first != *idx_first)
|
120
|
137
|
{
|
121
|
138
|
errno = EINTR;
|
122
|
|
- return 0;
|
|
139
|
+ return -1;
|
123
|
140
|
}
|
124
|
|
- idx = (pyfcgi_stats.cur_req - i - 1);
|
125
|
|
- idx = (idx<0)?PYFCGI_STATS_REQS_SAMPLES + idx:idx;
|
126
|
|
- idx %= PYFCGI_STATS_REQS_SAMPLES;
|
127
|
|
- cur_rs = pyfcgi_stats.reqs[idx];
|
|
141
|
+ idx = (*idx_first- i - 1);
|
|
142
|
+ idx = (idx<0)?len + idx:idx;
|
|
143
|
+ idx %= len;
|
|
144
|
+ cur = data[idx];
|
128
|
145
|
if(!i || i%60)
|
129
|
146
|
{
|
130
|
|
- stmp += cur_rs;
|
|
147
|
+ stmp += cur;
|
131
|
148
|
continue;
|
132
|
149
|
}
|
133
|
150
|
rtmp = (long double)stmp / 60;
|
|
@@ -135,15 +152,19 @@ size_t pyfcgi_stats_format()
|
135
|
152
|
if(i<5*60) { r5 += rtmp; }
|
136
|
153
|
if(i<10*60) { r10 += rtmp; }
|
137
|
154
|
if(i<15*60) { r15 += rtmp; }
|
138
|
|
- stmp = cur_rs;
|
|
155
|
+ stmp = cur;
|
139
|
156
|
}
|
140
|
157
|
//Restore interrupt/ALARM ??
|
141
|
158
|
r5 /= 5;
|
142
|
159
|
r10 /= 10;
|
143
|
160
|
r15 /= 15;
|
144
|
|
- pyfcgi_stats_buffprintf("Requests stats :\n1s:%dr/s 1m:%.2fr/s 5m:%.2fr/s 10m:%.2fr/s 15m:%.2fr/s\n",
|
145
|
|
- pyfcgi_stats.reqs[pyfcgi_stats.cur_req-1], r1, r5, r10, r15);
|
146
|
|
- return pyfcgi_stats.buff_ptr;
|
|
161
|
+ *last = data[*idx_first];
|
|
162
|
+ avgs[0] = r1;
|
|
163
|
+ avgs[1] = r5;
|
|
164
|
+ avgs[2] = r10;
|
|
165
|
+ avgs[3] = r15;
|
|
166
|
+
|
|
167
|
+ return 0;
|
147
|
168
|
}
|
148
|
169
|
|
149
|
170
|
void pyfcgi_stats_buffprintf(const char *fmt, ...)
|