OLD | NEW |
(Empty) | |
| 1 # SETTING UP GAE_TS_MON WITH APPENGINE |
| 2 |
| 3 Symlink this directory to your appengine app. |
| 4 |
| 5 Add a cron job to the cron.yaml file |
| 6 cron: |
| 7 - description: flush alerts metrics |
| 8 url: /monitoring |
| 9 schedule: every 5 minutes |
| 10 target: monitoring |
| 11 |
| 12 Add a dispatch.yaml file |
| 13 dispatch: |
| 14 - url: "*/monitoring" |
| 15 module: monitoring |
| 16 |
| 17 - url: "*/monitoring/*" |
| 18 module: monitoring |
| 19 |
| 20 - url: "*/_ah/start" |
| 21 module: monitoring |
| 22 |
| 23 - url: "*/*" |
| 24 module: default |
| 25 |
| 26 # INCREMENTING OR SETTING A PROVIDED METRIC |
| 27 |
| 28 import gae_ts_mon |
| 29 url = app_identity.get_default_version_hostname() |
| 30 gae_ts_mon.access_count.increment(fields={'url_path': url + '/' + key, |
| 31 'request_path': key, |
| 32 'request_type': 'GET'}) |
| 33 gae_ts_mon.request_bytes.add(48) |
| 34 |
| 35 See __init__.py for list of predefined metrics. |
| 36 |
| 37 # SENDING A SPECIFIC METRIC TO MONARCH |
| 38 |
| 39 gae_ts_mon.send(gae_ts_mon.access_count) |
| 40 |
| 41 # MANUALLY FLUSHING (SEND TO MONARCH) ALL METRICS |
| 42 |
| 43 gae_ts_mon.flush() |
| 44 |
| 45 All metrics will already flush automatically every five minutes. |
| 46 |
| 47 # ADDING A NEW METRIC |
| 48 |
| 49 alerts_count = gae_ts_mon.CounterMetric('gae/alerts') |
| 50 |
| 51 This may raise a MonitoringDuplicateRegistrationError if the name is already |
| 52 registered with a metric of a different type. |
| 53 |
| 54 # ADDING A NEW METRIC WITH CUSTOM TARGET: |
| 55 |
| 56 service, job, region, hostname, task = 'service', 'job', 'reg', 'host', 1 |
| 57 custom_target = gae_ts_mon.TaskTarget(service, job, region, hostname, task) |
| 58 cats_metric = gae_ts_mon.CounterMetric('gae/cats', target=custom_target) |
OLD | NEW |