comparison service/audioInputLevels/audioInputLevelsPulse.py @ 1112:03b4882517dd

audiolevels output to influxdb Ignore-this: e5f3559928a638bb311eb70dc751ef87 darcs-hash:e419b63c2335d1dd2a5267440bf73ee9b1bf3291
author drewp <drewp@bigasterisk.com>
date Fri, 16 Sep 2016 01:22:11 -0700
parents 64a2ba088665
children 30cd6cb833e3
comparison
equal deleted inserted replaced
1111:aa70001ea0c9 1112:03b4882517dd
1 # based on http://freshfoo.com/blog/pulseaudio_monitoring 1 # based on http://freshfoo.com/blog/pulseaudio_monitoring
2 from __future__ import division 2 from __future__ import division
3 import socket, argparse 3 import socket, argparse, time
4 from Queue import Queue 4 from Queue import Queue
5 from ctypes import POINTER, c_ubyte, c_void_p, c_ulong, cast 5 from ctypes import POINTER, c_ubyte, c_void_p, c_ulong, cast
6 import galena 6 from influxdb import InfluxDBClient
7 7
8 # From https://github.com/Valodim/python-pulseaudio 8 # From https://github.com/Valodim/python-pulseaudio
9 from pulseaudio import lib_pulseaudio as P 9 from pulseaudio import lib_pulseaudio as P
10 10
11 METER_RATE = 1 11 METER_RATE = 1
100 '--source', required=True, 100 '--source', required=True,
101 help='pulseaudio source name (use `pactl list sources | grep Name`)') 101 help='pulseaudio source name (use `pactl list sources | grep Name`)')
102 102
103 args = parser.parse_args() 103 args = parser.parse_args()
104 104
105 105 def ipv6Init(self, host="localhost", port=2003):
106 out = galena.Galena(host='bang') 106 self._addr = (host, port, 0, 0)
107 prefix = 'system.house.audio.%s' % socket.gethostname() 107 self._sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
108 self._sock.connect(self._addr)
109
110 influx = InfluxDBClient('bang6', 9060, 'root', 'root', 'main')
111
112 hostname = socket.gethostname()
108 monitor = PeakMonitor(args.source, METER_RATE) 113 monitor = PeakMonitor(args.source, METER_RATE)
109 for sample in monitor: 114 for sample in monitor:
110 #print ' %3d %s' % (sample, '>' * sample) 115 #print ' %3d %s' % (sample, '>' * sample)
111 out.send(prefix + ".max", sample / 128) 116 influx.write_points([{'measurement': 'audioLevel',
117 "tags": dict(stat='max', location=hostname),
118 "fields": {"value": sample / 128},
119 "time": int(time.time())}], time_precision='s')
112 120
113 if __name__ == '__main__': 121 if __name__ == '__main__':
114 main() 122 main()