Ema has submitted this change and it was merged.

Change subject: Port varnishmedia to new VSL API
......................................................................


Port varnishmedia to new VSL API

Bug: T131353
Change-Id: I7c502f6f1919353a8a6695acf16f5c58eb444ead
---
A modules/varnish/files/varnishmedia4
M modules/varnish/manifests/logging/media.pp
2 files changed, 67 insertions(+), 1 deletion(-)

Approvals:
  Ema: Verified; Looks good to me, approved



diff --git a/modules/varnish/files/varnishmedia4 
b/modules/varnish/files/varnishmedia4
new file mode 100755
index 0000000..27a0535
--- /dev/null
+++ b/modules/varnish/files/varnishmedia4
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+  varnishmedia
+  ~~~~~~~~~~~~
+
+  Accumulate browser cache hit ratio and total request volume statistics
+  for media requests and report to StatsD.
+
+  Usage: varnishmedia [--statsd-server SERVER] [--key-prefix PREFIX]
+
+    --statsd-server SERVER  statsd server (default: none; echo to stdout)
+    --key-prefix PREFIX     metric key prefix (default: 
media.thumbnail.varnish)
+
+  Copyright 2015 Ori Livneh <o...@wikimedia.org>
+  Copyright 2015 Gilles Dubuc <gil...@wikimedia.org>
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+"""
+from __future__ import division
+
+import re
+
+import varnishlog
+import varnishprocessor
+
+
+class MediaVarnishLogProcessor(varnishprocessor.VarnishLogProcessor):
+    description = 'Media Browser Cache Hit Ratio StatsD Reporter'
+    key_prefix = 'media.thumbnail.varnish'
+
+    def process_transaction(self, transaction):
+        """Process a single completed transaction."""
+        status_code = transaction.get('RespStatus')
+        if status_code is None:
+            return
+
+        metric_keys = ['reqs.all', 'resps.' + status_code]
+
+        for key in metric_keys:
+            self.stats[key] = self.stats.get(key, 0) + 1
+
+        if self.stats['reqs.all'] > 10000:
+            self.flush_stats()
+
+    def start(self):
+        varnishlog.varnishlog((
+            ('q', 'ReqURL ~ "/thumb/"'), # Only look at thumb requests
+            ('n', 'frontend'),           # Only frontend Varnish instance
+            ('i', 'RespStatus'),         # RespStatus for the HTTP status code
+            ('i', 'ReqURL'),             # ReqURL to delimit requests
+            ('i', 'Timestamp'),          # Timestamp to delimit requests
+        ), self.handle_log_record)
+
+lp = MediaVarnishLogProcessor()
diff --git a/modules/varnish/manifests/logging/media.pp 
b/modules/varnish/manifests/logging/media.pp
index f39e0a1..48815c8 100644
--- a/modules/varnish/manifests/logging/media.pp
+++ b/modules/varnish/manifests/logging/media.pp
@@ -19,7 +19,7 @@
     include varnish::common
 
     file { '/usr/local/bin/varnishmedia':
-        source  => 'puppet:///modules/varnish/varnishmedia',
+        source  => 
"puppet:///modules/varnish/varnishmedia${varnish::common::varnish4_python_suffix}",
         owner   => 'root',
         group   => 'root',
         mode    => '0555',

-- 
To view, visit https://gerrit.wikimedia.org/r/305527
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7c502f6f1919353a8a6695acf16f5c58eb444ead
Gerrit-PatchSet: 2
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ema <e...@wikimedia.org>
Gerrit-Reviewer: BBlack <bbl...@wikimedia.org>
Gerrit-Reviewer: Ema <e...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to