https://bitbucket.org/sivann/runcached/

Spiros Ioannou 67269ad7b5 LICENSE 6 年之前
LICENSE 67269ad7b5 LICENSE 6 年之前
Makefile 52ada10ea3 added files 10 年之前
README.md 75ce11f016 README.md edited online with Bitbucket 9 年之前
contributors.txt ca02f81d05 Initial commit with contributors 10 年之前
gittag.sh 0daabffc93 updated readme 10 年之前
runcached 8920bf777b some includes & prototype declarations 8 年之前
runcached.c 8920bf777b some includes & prototype declarations 8 年之前
runcached.py 52ada10ea3 added files 10 年之前
runcached.sh 52ada10ea3 added files 10 年之前

README.md

RunCached

Execute commands while caching their output for subsequent calls. Command output will be cached for seconds and "replayed" for any subsequent calls. Original exit status will also be emulated.

Details

After cacheperiod has expired, command will be re-executed and a new result will be cached. Cache data is tied to the command and arguments executed and the path of the runcached executable. Cache results are stored in /tmp

You can use runcached to run resource-expensive commands multiple times, parsing different parts of its output each time. Those commands will be run only once for each cacheperiod.

Implementation is provided in 3 languages, python, C, BASH. Of course the BASH version is not really suggested but it works.

Usage

Python

runcached.py [-c cacheperiod]

C

runcached [-c cacheperiod]

Bash

runcached.sh

Examples

Example 1: Run the date command. Each time it executes prints the same date for 5 seconds.

runcached.py -c 5 date

Example 2: Zabbix userparameter which can be called multiple times , but actually executes only once every 20 seconds.

Query multiple parameters of mysql at the same time, without re-running the query.

#!

UserParameter=mysql.globalstatus[*],/usr/local/bin/runcached.py -c 20 /usr/bin/mysql -ANe \"show global status\"|egrep '$1\b'|awk '{print $ 2}'

And then define some items like so:

#!nolang
Item Name                      Item Key
--------------                  --------------
MySQL DELETES	 	mysql.globalstatus[Com_delete]
MySQL INSERTS	 	mysql.globalstatus[Com_insert]
MySQL UPDATES	 	mysql.globalstatus[Com_update]
MySQL CREATE TABLE	mysql.globalstatus[Com_create_table]
MySQL SELECTS	 	mysql.globalstatus[Com_select]
MySQL Uptime	 	mysql.globalstatus[Uptime]
MySQL ALTER TABLE	mysql.globalstatus[Com_alter_table]

E.g. for DELETE: 
Type: Numeric, 
Data Type: Decimal. 
Units: QPS
Store Value: Delta (Speed per second)
Show Value: As Is