-
Notifications
You must be signed in to change notification settings - Fork 5
/
redis-client.php
59 lines (45 loc) · 1.41 KB
/
redis-client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
require_once __DIR__ . '/vendor/autoload.php';
if (!file_exists('config/podisum.yml')) {
die("No config file");
}
$config = \Symfony\Component\Yaml\Yaml::parse('config/podisum.yml');
if (class_exists('MongoClient')) {
$mongo = new \MongoClient($config['mongo']);
} else {
$mongo = new \Mongo($config['mongo']);
}
$podisum = new Podisum($mongo, $config);
$podisum->ensureIndexes();
$redis = new Predis\Client($config['redis']);
$len = $redis->llen($config['redis_key']);
echo "Found $len entries waiting on list...\n";
$processed = 0;
$sleep = $podisum->getConfig('default_sleep', 1);
while(1) {
$value = $redis->rpop($config['redis_key']);
if (null === $value) {
echo "no more data, sleeping...\n";
sleep($sleep);
continue;
}
$data = json_decode($value, true);
if (!$data) {
echo "Invalid json string ".$value;
continue;
}
$process = false;
$tags = isset($data['tags']) ? $data['tags'] : $data['@tags'];
foreach($tags as $tag) {
$cfgs = $podisum->getConfigForTag($tag);
foreach($cfgs as $cfg) {
$podisum->insertMetric($data, $cfg['metric'], $cfg['ttl'], $cfg['summaries']);
$processed++;
echo $processed. " - processing ".$cfg['metric']."\n";
$process = true;
}
}
if (!$process) {
echo "No config for tags ".implode(", ", $tags)."\n";
}
}