README 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # runcached (Run Cached)
  2. Execute commands while caching their output for subsequent calls.
  3. Command output will be cached for <cacheperiod> seconds and "replayed" for
  4. any subsequent calls. Original exit status will also be emulated.
  5. ## Details
  6. After cacheperiod has expired, command will be re-executed and a new result
  7. will be cached.
  8. Cache data is tied to the command and arguments executed and the
  9. path of the runcached executable. Cache results are stored in /tmp
  10. You can use runcached to run resource-expensive commands multiple times,
  11. parsing different parts of its output each time. Those commands will be
  12. run only once for each cacheperiod.
  13. Implementation is provided in 3 languages, python, C, BASH. Of course the BASH version is not really suggested but it works.
  14. ## Usage
  15. ### Python
  16. runcached.py [-c cacheperiod] <command to execute with args>
  17. ### C
  18. runcached [-c cacheperiod] <command to execute with args>
  19. ### Bash
  20. runcached.sh <command to execute with args>
  21. ## Examples
  22. ### Example 1: Run the date command. Produce a new "date" every 5 seconds.
  23. runcached.py -c 5 date
  24. ### Example 2: Zabbix userparameter which can be called multiple times , but actually executes only once every 20 seconds.
  25. Query multiple parameters of mysql at the same time, without re-running the query.
  26. ```
  27. #!
  28. UserParameter=mysql.globalstatus[*],/usr/local/bin/runcached.py -c 20 /usr/bin/mysql -ANe \"show global status\"|egrep '$1\b'|awk '{print $ 2}'
  29. ```
  30. And then define some items like so:
  31. ```
  32. #!nolang
  33. Item Name Item Key
  34. -------------- --------------
  35. MySQL DELETES mysql.globalstatus[Com_delete]
  36. MySQL INSERTS mysql.globalstatus[Com_insert]
  37. MySQL UPDATES mysql.globalstatus[Com_update]
  38. MySQL CREATE TABLE mysql.globalstatus[Com_create_table]
  39. MySQL SELECTS mysql.globalstatus[Com_select]
  40. MySQL Uptime mysql.globalstatus[Uptime]
  41. MySQL ALTER TABLE mysql.globalstatus[Com_alter_table]
  42. E.g. for DELETE:
  43. Type: Numeric,
  44. Data Type: Decimal.
  45. Units: QPS
  46. Store Value: Delta (Speed per second)
  47. Show Value: As Is
  48. ```