{"id":1357,"date":"2013-08-20T07:48:53","date_gmt":"2013-08-20T05:48:53","guid":{"rendered":"http:\/\/blog.gocept.com\/?p=1357"},"modified":"2013-11-06T18:15:01","modified_gmt":"2013-11-06T17:15:01","slug":"viewing-scales-metrics-from-pyramid","status":"publish","type":"post","link":"https:\/\/blog.gocept.com\/2013\/08\/20\/viewing-scales-metrics-from-pyramid\/","title":{"rendered":"Viewing scales metrics from Pyramid"},"content":{"rendered":"

We’ve recently started experimenting with the excellent scales<\/a> library to collect in-process metrics (see Coda Hale’s CodeConf talk “Metrics everywhere<\/a>” among many others for reasons why one definitely wants to do that).<\/p>\n

Scales comes with a flask-based HTTP server that allows viewing the collected measurements and dumping them as JSON. But if you already are in a web application, there’s no real need to spin up yet another thread, open another port etc. to do this. In our case, we’re using Pyramid, so here’s a quick recipe to get the same view that greplin.scales.flaskhandler provides:<\/p>\n

Update 2013-11-06:<\/strong> This code is now released as pyramid_scales<\/a>.<\/p>\n

# in your Pyramid setup\r\nconfig.add_route('scales', '\/scales\/*prefix')\r\n\r\nfrom StringIO import StringIO\r\nfrom pyramid.view import view_config\r\nimport greplin.scales\r\nimport greplin.scales.formats\r\n\r\n@view_config(route_name='scales', renderer='string')\r\ndef scales_stats(request):\r\n\u00a0\u00a0\u00a0 parts = request.matchdict.get('prefix')\r\n\u00a0\u00a0\u00a0 path = '\/'.join(parts)\r\n\u00a0\u00a0\u00a0 stats = greplin.scales.util.lookup(greplin.scales.getStats(), parts)\r\n\r\n\u00a0\u00a0\u00a0 output = StringIO()\r\n\u00a0\u00a0\u00a0 outputFormat = request.params.get('format', 'html')\r\n\u00a0\u00a0\u00a0 query = request.params.get('query', None)\r\n\u00a0\u00a0\u00a0 if outputFormat == 'json':\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 request.response.content_type = 'application\/json'\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 greplin.scales.formats.jsonFormat(output, stats, query)\r\n\u00a0\u00a0\u00a0 elif outputFormat == 'prettyjson':\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 request.response.content_type = 'application\/json'\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 greplin.scales.formats.jsonFormat(output, stats, query, pretty=True)\r\n\u00a0\u00a0\u00a0 else:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 request.response.content_type = 'text\/html'\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # XXX Dear pyramid.renderers.string_renderer_factory,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # you can't be serious\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 request.response.default_content_type = 'not-text\/html'\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 output.write('<html>')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 greplin.scales.formats.htmlHeader(output, '\/' + path, __name__, query)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 greplin.scales.formats.htmlFormat(output, tuple(parts), stats, query)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 output.write('<\/html>')\r\n\r\n\u00a0\u00a0\u00a0 return output.getvalue()<\/pre>\n","protected":false},"excerpt":{"rendered":"

We’ve recently started experimenting with the excellent scales library to collect in-process metrics (see Coda Hale’s CodeConf talk “Metrics everywhere” among many others for reasons why one definitely wants to do that). Scales comes with a flask-based HTTP server that allows viewing the collected measurements and dumping them as JSON. But if you already are … Continue reading “Viewing scales metrics from Pyramid”<\/span><\/a><\/p>\n","protected":false},"author":10315341,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[10221],"tags":[7092,144718,832,63064],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pFP3y-lT","jetpack-related-posts":[{"id":1327,"url":"https:\/\/blog.gocept.com\/2013\/07\/09\/monitoringlove-sprint-takeaway\/","url_meta":{"origin":1357,"position":0},"title":"#monitoringlove sprint takeaway","author":"Daniel Havlik","date":"July 9, 2013","format":false,"excerpt":"A few weeks ago I co-organised and participated in a #monitoringlove sprint in Berlin. My personal plan was to play with more modern utilities that can potentially replace our existing Nagios monitoring chain. The result of what I think would be a good setup would probably look like this: Most\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2013\/07\/monitoringlove2.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1293,"url":"https:\/\/blog.gocept.com\/2013\/05\/29\/august-15th-17th-sprinting-on-pyramid\/","url_meta":{"origin":1357,"position":1},"title":"August, 15th\u201317th: Sprinting on Pyramid","author":"Daniel Havlik","date":"May 29, 2013","format":false,"excerpt":"After Zope \"-the-Framework\" reaching the end of its lifecycle during the last few years, we did a bunch of new projects with Pyramid, a nice web framework primarily authored by long-term Zope developer Chris McDonough. We think it's about time to give something back to the community, and become more\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":349,"url":"https:\/\/blog.gocept.com\/2012\/12\/17\/yafowil-in-a-pyramid-project\/","url_meta":{"origin":1357,"position":2},"title":"yafowil in a Pyramid project","author":"Michael Howitz","date":"December 17, 2012","format":false,"excerpt":"In a new Pyramid\u00a0project we used deform\u00a0to render forms. We did not really like it. (The reasons might be detailed in another post.) To see if other form libraries do better I\u00a0gave yafowil\u00a0a try at our\u00a0gocept Developer Punsch\u00a03: yafowil comes with written documentation. To get a form in our Pyramid\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":39,"url":"https:\/\/blog.gocept.com\/2011\/01\/24\/testing-pyramid-applications-with-zope-testbrowser\/","url_meta":{"origin":1357,"position":3},"title":"Testing pyramid applications with zope.testbrowser","author":"","date":"January 24, 2011","format":false,"excerpt":"The Pyramid documentation recommends using WebTest for functional tests, but coming from the Zope world, zope.testbrowser is the more familiar tool for this job (and it seems a little more high-level than WebTest at first glance). With the 3.11 release,\u00a0 zope.testbrowser gained out-of-the-box support for talking to WSGI applications (courtesy\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1278,"url":"https:\/\/blog.gocept.com\/2013\/06\/07\/save-the-date-sommerfest-bei-gocept\/","url_meta":{"origin":1357,"position":4},"title":"Sommerfest bei gocept","author":"","date":"June 7, 2013","format":false,"excerpt":"english version below 13 \u2013 eine missverstandene Zahl. Was gibt es nicht alles f\u00fcr Vorurteile, ob nun Gl\u00fccks- oder Ungl\u00fcckszahl und Verschw\u00f6rungstheorien ohne Ende. gocept wird 13 Jahre. Das wollen wir mit unseren Familien, Freunden und Gesch\u00e4ftspartnern feiern. Grund genug also f\u00fcr ein Sommerfest in unserem tollen Garten. Tragt das\u2026","rel":"","context":"In "de"","block_context":{"text":"de","link":"https:\/\/blog.gocept.com\/category\/de\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1361,"url":"https:\/\/blog.gocept.com\/2013\/08\/28\/run-tests-using-layers-with-py-test\/","url_meta":{"origin":1357,"position":5},"title":"Run tests using layers with py.test","author":"Michael Howitz","date":"August 28, 2013","format":false,"excerpt":"TL;DR Use gocept.pytestlayer. Long Story We have many test suites which use test layers (e. g. the ones from plone.testing). We want to use py.test\u00a0and all its fancy features to have a modern test runner. There was no way to convert such tests partly: either you have to port the\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/1357"}],"collection":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/users\/10315341"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/comments?post=1357"}],"version-history":[{"count":6,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/1357\/revisions"}],"predecessor-version":[{"id":1429,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/1357\/revisions\/1429"}],"wp:attachment":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/media?parent=1357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/categories?post=1357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/tags?post=1357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}