corrade-lsl-templates – Diff between revs 41 and 42
?pathlinks?
Rev 41 | Rev 42 | |||
---|---|---|---|---|
Line 247... | Line 247... | |||
247 | return; |
247 | return; |
|
Line 248... | Line 248... | |||
248 | |
248 | |
|
249 | // Remove command. |
249 | // Remove command. |
|
Line 250... | Line 250... | |||
250 | command = llDeleteSubList(command, 0, 0); |
250 | command = llDeleteSubList(command, 0, 0); |
|
251 | |
251 | |
|
252 | // Get an URL. |
252 | // Get heartbeat. |
|
253 | state url; |
253 | state heartbeat; |
|
254 | } |
254 | } |
|
255 | on_rez(integer num) { |
255 | on_rez(integer num) { |
|
256 | llResetScript(); |
256 | llResetScript(); |
|
Line 262... | Line 262... | |||
262 | llResetScript(); |
262 | llResetScript(); |
|
263 | } |
263 | } |
|
264 | } |
264 | } |
|
265 | } |
265 | } |
|
Line 266... | Line -... | |||
266 | |
- | ||
267 | state url { |
- | ||
268 | state_entry() { |
- | ||
269 | // DEBUG |
- | ||
270 | llOwnerSay("[Heartbeat] Requesting URL..."); |
- | ||
271 | llRequestURL(); |
- | ||
272 | } |
- | ||
273 | http_request(key id, string method, string body) { |
- | ||
274 | if(method != URL_REQUEST_GRANTED) return; |
- | ||
275 | URL = body; |
- | ||
276 | // DEBUG |
- | ||
277 | llOwnerSay("[Heartbeat] Got URL..."); |
- | ||
278 | state version; |
- | ||
279 | } |
- | ||
280 | on_rez(integer num) { |
- | ||
281 | llResetScript(); |
- | ||
282 | } |
- | ||
283 | changed(integer change) { |
- | ||
284 | if((change & CHANGED_INVENTORY) || |
- | ||
285 | (change & CHANGED_REGION_START) || |
- | ||
286 | (change & CHANGED_OWNER)) { |
- | ||
287 | llResetScript(); |
- | ||
288 | } |
- | ||
289 | } |
- | ||
290 | } |
- | ||
291 | |
266 | |
|
292 | state version { |
267 | state heartbeat { |
|
293 | state_entry() { |
268 | state_entry() { |
|
294 | // DEBUG |
269 | // DEBUG |
|
295 | llOwnerSay("[Heartbeat] Getting heartbeat data..."); |
270 | llOwnerSay("[Heartbeat] Getting heartbeat data..."); |
|
296 | llInstantMessage( |
271 | llInstantMessage( |
|
Line 315... | Line 290... | |||
315 | ), |
290 | ), |
|
316 | "data", wasListToCSV( |
291 | "data", wasListToCSV( |
|
317 | [ |
292 | [ |
|
318 | "AverageCPUUsage", |
293 | "AverageCPUUsage", |
|
319 | "AverageRAMUsage", |
294 | "AverageRAMUsage", |
|
- | 295 | "AverageNETUsage", |
||
320 | "Uptime" |
296 | "Uptime" |
|
321 | ] |
297 | ] |
|
322 | ), |
298 | ), |
|
323 | "callback", wasURLEscape(URL) |
299 | "callback", wasURLEscape( |
|
- | 300 | wasKeyValueGet( |
||
- | 301 | "URL", |
||
- | 302 | configuration |
||
- | 303 | ) |
||
- | 304 | ) |
||
324 | ] |
305 | ] |
|
325 | ) |
306 | ) |
|
326 | ); |
307 | ); |
|
327 | llSetTimerEvent(60); |
308 | llSetTimerEvent(60); |
|
328 | } |
309 | } |
|
329 | http_request(key id, string method, string body) { |
310 | link_message(integer sender, integer num, string body, key id) { |
|
330 | llHTTPResponse(id, 200, "OK"); |
311 | // Only process callbacks for the database command. |
|
331 | llReleaseURL(URL); |
- | ||
332 | if(wasKeyValueGet("command", body) != "getheartbeatdata" || |
312 | if(id != "callback" || wasKeyValueGet("command", body) != "getheartbeatdata") |
|
- | 313 | return; |
||
- | 314 | |
||
333 | wasKeyValueGet("success", body) != "True") { |
315 | if(wasKeyValueGet("success", body) != "True") { |
|
334 | // DEBUG |
316 | // DEBUG |
|
335 | llOwnerSay("[Heartbeat] Unable to get heartbeat data: " + |
317 | llOwnerSay("[Heartbeat] Unable to get heartbeat data: " + |
|
336 | wasURLUnescape( |
318 | wasURLUnescape( |
|
337 | wasKeyValueGet("error", body) |
319 | wasKeyValueGet("error", body) |
|
338 | ) |
320 | ) |
|
Line 367... | Line 349... | |||
367 | ["AverageRAMUsage"] |
349 | ["AverageRAMUsage"] |
|
368 | ) + 1 |
350 | ) + 1 |
|
369 | ) / 1024 / 1024 |
351 | ) / 1024 / 1024 |
|
370 | ); |
352 | ); |
|
Line -... | Line 353... | |||
- | 353 | |
||
- | 354 | // AverageNETUsage is returned in bytes, |
||
- | 355 | // so convert the value to MiB and round. |
||
- | 356 | string NET = (string)llRound( |
||
- | 357 | llList2Float( |
||
- | 358 | stats, |
||
- | 359 | llListFindList( |
||
- | 360 | stats, |
||
- | 361 | ["AverageNETUsage"] |
||
- | 362 | ) + 1 |
||
- | 363 | ) / 1024 / 1024 |
||
- | 364 | ); |
||
371 | |
365 | |
|
372 | string uptime = llList2String( |
366 | string uptime = llList2String( |
|
373 | stats, |
367 | stats, |
|
374 | llListFindList( |
368 | llListFindList( |
|
375 | stats, |
369 | stats, |
|
376 | ["Uptime"] |
370 | ["Uptime"] |
|
377 | ) + 1 |
371 | ) + 1 |
|
Line 378... | Line 372... | |||
378 | ); |
372 | ); |
|
Line 379... | Line 373... | |||
379 | |
373 | |
|
380 | data = "RAM: " + RAM + "MiB" + " CPU: " + CPU + "%" + " Uptime: " + uptime; |
374 | data = "RAM: " + RAM + "MiB" + " CPU: " + CPU + "%" + " NET: " + NET + "MiB" + " Uptime: " + uptime; |
|
381 | |
375 | |
|
382 | state tell; |
- | ||
383 | } |
376 | state tell; |
|
384 | timer() { |
377 | } |
|
385 | llReleaseURL(URL); |
378 | timer() { |
|
386 | state listen_group; |
379 | state listen_group; |
|
387 | } |
380 | } |