|
@@ -128,10 +128,17 @@ int pyfcgi_stats_avg(const int data[], int *idx_first, int len,
|
128
|
128
|
double r15, r10, r5, r1, rtmp;
|
129
|
129
|
unsigned long stmp; // stores a 60s req sum
|
130
|
130
|
int i, cur, idx, first;
|
|
131
|
+ int uptime, max;
|
|
132
|
+
|
|
133
|
+ uptime = time(NULL) - PyFCGI_conf.context.uptime;
|
|
134
|
+ max = (uptime > len) ? len:uptime;
|
|
135
|
+
|
131
|
136
|
r15 = r10 = r5 = r1 = stmp = 0;
|
132
|
137
|
first = *idx_first;
|
|
138
|
+
|
133
|
139
|
//Block interrupt/ALARM ??
|
134
|
|
- for(i=0; i<len; i++)
|
|
140
|
+ i = 0;
|
|
141
|
+ do
|
135
|
142
|
{
|
136
|
143
|
if(first != *idx_first)
|
137
|
144
|
{
|
|
@@ -142,23 +149,27 @@ int pyfcgi_stats_avg(const int data[], int *idx_first, int len,
|
142
|
149
|
idx = (idx<0)?len + idx:idx;
|
143
|
150
|
idx %= len;
|
144
|
151
|
cur = data[idx];
|
145
|
|
- if(!i || i%60)
|
|
152
|
+ if((!i || i%60) && i < max-1)
|
146
|
153
|
{
|
147
|
154
|
stmp += cur;
|
|
155
|
+ i++;
|
148
|
156
|
continue;
|
149
|
157
|
}
|
150
|
|
- rtmp = (long double)stmp / 60;
|
|
158
|
+ rtmp = (long double)stmp / ((max < 60)?max:60);
|
151
|
159
|
if(i==60) { r1 = rtmp; }
|
152
|
160
|
if(i<5*60) { r5 += rtmp; }
|
153
|
161
|
if(i<10*60) { r10 += rtmp; }
|
154
|
162
|
if(i<15*60) { r15 += rtmp; }
|
155
|
163
|
stmp = cur;
|
156
|
|
- }
|
|
164
|
+ i++;
|
|
165
|
+ }while(i<max);
|
157
|
166
|
//Restore interrupt/ALARM ??
|
|
167
|
+ *last = data[*idx_first-1];
|
|
168
|
+ rtmp = max?rtmp:((double)*last);
|
|
169
|
+ r1 = (uptime <= 60)?rtmp:r1;
|
158
|
170
|
r5 /= 5;
|
159
|
171
|
r10 /= 10;
|
160
|
172
|
r15 /= 15;
|
161
|
|
- *last = data[*idx_first];
|
162
|
173
|
avgs[0] = r1;
|
163
|
174
|
avgs[1] = r5;
|
164
|
175
|
avgs[2] = r10;
|