|
@@ -123,10 +123,57 @@ size_t pyfcgi_stats_format()
|
123
|
123
|
|
124
|
124
|
int pyfcgi_stats_avg(const int data[PYFCGI_STATS_SZ], int *idx_nxt, int *last,
|
125
|
125
|
double avgs[4])
|
|
126
|
+{
|
|
127
|
+ double r15, r10, r5, r1, rtmp;
|
|
128
|
+ unsigned long stmp; // stores a 60s req sum
|
|
129
|
+ int i, cur, idx, first;
|
|
130
|
+
|
|
131
|
+ r15 = r10 = r5 = r1 = stmp = 0;
|
|
132
|
+ first = *idx_nxt;
|
|
133
|
+
|
|
134
|
+ //Block interrupt/ALARM ??
|
|
135
|
+ for(i=0; i<PYFCGI_STATS_SZ; i++)
|
|
136
|
+ {
|
|
137
|
+ if(first != *idx_nxt)
|
|
138
|
+ {
|
|
139
|
+ errno = EINTR;
|
|
140
|
+ return -1;
|
|
141
|
+ }
|
|
142
|
+ idx = (*idx_nxt- i - 1);
|
|
143
|
+ idx = (idx<0)?PYFCGI_STATS_SZ + idx:idx;
|
|
144
|
+ idx %= PYFCGI_STATS_SZ;
|
|
145
|
+ cur = data[idx];
|
|
146
|
+ if(!i || i%60)
|
|
147
|
+ {
|
|
148
|
+ stmp += cur;
|
|
149
|
+ continue;
|
|
150
|
+ }
|
|
151
|
+ rtmp = (long double)stmp / 60;
|
|
152
|
+ if(i==60) { r1 = rtmp; }
|
|
153
|
+ if(i<5*60) { r5 += rtmp; }
|
|
154
|
+ if(i<10*60) { r10 += rtmp; }
|
|
155
|
+ if(i<15*60) { r15 += rtmp; }
|
|
156
|
+ stmp = cur;
|
|
157
|
+ }
|
|
158
|
+ //Restore interrupt/ALARM ??
|
|
159
|
+ r5 /= 5;
|
|
160
|
+ r10 /= 10;
|
|
161
|
+ r15 /= 15;
|
|
162
|
+ *last = data[*idx_nxt-1];
|
|
163
|
+ avgs[0] = r1;
|
|
164
|
+ avgs[1] = r5;
|
|
165
|
+ avgs[2] = r10;
|
|
166
|
+ avgs[3] = r15;
|
|
167
|
+
|
|
168
|
+ return 0;
|
|
169
|
+}
|
|
170
|
+
|
|
171
|
+int pyfcgi_stats_avg_const(const int data[PYFCGI_STATS_SZ], int *idx_nxt, int *last,
|
|
172
|
+ double avgs[4])
|
126
|
173
|
{
|
127
|
174
|
double r15, r10, r5, r1, rtmp, dmax;
|
128
|
175
|
unsigned long stmp; // stores a 60s req sum
|
129
|
|
- int i, cur, idx, first, idiv;
|
|
176
|
+ int i, cur, idx, first;
|
130
|
177
|
int uptime, max;
|
131
|
178
|
|
132
|
179
|
uptime = time(NULL) - PyFCGI_conf.context.uptime;
|