Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions README.md
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
python-haproxy
python-haproxy collectD plugin
==============

Read haproxy stats using socket.

based on python-haproxy `git clone https://github.com/nl5887/python-haproxy.git`

Read haproxy stats using socket
before using it in CollectD
replace
```import collectd_mockup as collectd```
to
```#import collectd```


and comment out at the bottom
```read_callback()```


data returnded to collectD looks like:
```
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BE_test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/FE_test_r36/qcur =
instance/type/type_instance: master-prod/FE_fe_test_r37/qcur =

```


# Info from python-haproxy

## Install
There are a few different ways you can install pyechonest:
Expand Down
146 changes: 146 additions & 0 deletions haproxy-plugin.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys
import os
import commands
import socket
import time

try:
import collectd
except:
import tools.collectd_mockup as collectd

from haproxy import haproxy
from tools.data_list import data_gathered
from tools. data_list import data_stat_index


PLUGIN_NAME = os.path.basename(__file__).split(".")[0]
stats = haproxy.HAProxyStats('/var/run/haproxy/haproxy.sock')
VERBOSE_LOGGING = True

# convert list of "arg: val" to dict[arg]=val
def str2dict(arg):
rez = {}
for x in arg:
if x:
rez[(x.split(':')[0]).strip()] = x.split(':')[1].strip()

return rez

def log_verbose(msg):
if not VERBOSE_LOGGING:
return
collectd.info('haproxy plugin [verbose]: %s' % msg)




# callback funcion for collectd Daemon
def read_callback(data=None):

metric = collectd.Values()

#
# get Haproxy stat info
#
rez = str2dict(stats.execute('show info'))
instance = rez['node'] or socket.gethostname()
# loop over keys that we need
for i in data_gathered['info']:

metric.plugin = PLUGIN_NAME
metric.interval = 60
metric.plugin_instance = instance
metric.type = 'status'
metric.type_instance = i
metric.values = (unicodedata.numeric(rez[i]),) #values must be list or tuple
# metric.dispatch()

#
# get stat info
#
f_ends = {}
b_ends = {}
b_ends_summ = {}
for x in stats.execute('show stat'):

# skiping some trash
if x.startswith("#"):
continue
if x.startswith("stats"):
continue
if x == '':
continue

# convert string into array
tmp = x.split(',')

# fill frontends
if tmp[1] == 'FRONTEND':
f_ends[tmp[0]] = tmp
continue

# fill backend summary info
if tmp[1] == 'BACKEND':
b_ends_summ[tmp[0]] = tmp
continue

# fill backen workers info
b_ends["%s@%s" % (tmp[1],tmp[0])] = tmp




# fill data for backends
for z in data_gathered['stat']:
# fill info for backend/workers
for k, v in b_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = 'be_workers'
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in b_ends_summ.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "backend"
metric.type_instance = "%s_%s" % (k,z)
metric.values = (v[data_stat_index[z]],) # values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in f_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "frontend"
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()




#for debugging purposes
read_callback()

collectd.register_read(read_callback)

6 changes: 4 additions & 2 deletions haproxy/haproxy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,8 +42,10 @@ def execute(self, command, timeout=200):

for s in r:
if (s is client):
buffer = buffer + client.recv(16384)
running = (len(buffer)==0)
tmp = client.recv(16384)
buffer = buffer + tmp
if tmp == '':
running = (len(buffer)==0)

client.close()

Expand Down
2 changes: 2 additions & 0 deletions tools/__init__.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-

23 changes: 23 additions & 0 deletions tools/collectd_mockup.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python


class Values:
plugin = ''
interval = ''
plugin_instance = ''
type = ''
type_instance = ''
values = ''

def dispatch(self):
pass
#print "instance/type/type_instance: %s/%s/%s = %s" % (self.plugin_instance, self.type, self.type_instance, self.values)
# print ""

def info(self, arg=''):
pass


def register_read(read_callback):
pass

152 changes: 152 additions & 0 deletions tools/data_list.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
#!/usr/bin/py

data_gathered = {}

data_gathered['info'] = [
#'Name',
#'Version',
#'Release_date',
#'Nbproc',
#'Process_num',
#'Pid',
#'Uptime',
#'Uptime_sec',
#'Memmax_MB',
#'Ulimit-n',
#'Maxsock',
#'Maxconn',
#'Hard_maxconn',
#'CurrConns',
#'CumConns',
#'CumReq',
#'MaxSslConns',
#'CurrSslConns',
#'CumSslConns',
#'Maxpipes',
#'PipesUsed',
#'PipesFree',
#'ConnRate',
#'ConnRateLimit',
#'MaxConnRate',
#'SessRate',
#'SessRateLimit',
#'MaxSessRate',
#'SslRate',
#'SslRateLimit',
#'MaxSslRate',
#'SslFrontendKeyRate',
#'SslFrontendMaxKeyRate',
#'SslFrontendSessionReuse_pct',
#'SslBackendKeyRate',
#'SslBackendMaxKeyRate',
#'SslCacheLookups',
#'SslCacheMisses',
#'CompressBpsIn',
#'CompressBpsOut',
#'CompressBpsRateLim',
#'ZlibMemUsage',
#'MaxZlibMemUsage',
#'Tasks',
#'Run_queue',
#'Idle_pct',
#'node',
#'description'
]


data_gathered['stat'] = [
#'pxname',
#'svname',
'qcur',
'scur',
'stot',
'bin',
'bout',
'dreq',
'dresp',
'ereqeconeresp',
]


data_stat_index = {
'pxname':0,
'svname':1,
'qcur':2,
'qmax':3,
'scur':4,
'smax':5,
'slim':6,
'stot':7,
'bin':8,
'bout':9,
'dreq':10,
'dresp':11,
'ereqeconeresp':12,
'wretr':13,
'wredis':14,
'status':15,
'weight':16,
'act':17,
'bckchkfail':18,
'chkdown':19,
'lastchg':20,
'downtime':21,
'qlimit':22,
'pid':23,
'iid':24,
'sid':25,
'throttle':26,
'lbtot':27,
'tracked':28,
'type':29,
'rate':30,
'rate_lim':31,
'rate_max':32,
'check_status':33,
'check_code':34,
'check_duration':35,
'hrsp_1xx':36,
'hrsp_2xx':37,
'hrsp_3xx':38,
'hrsp_4xx':39,
'hrsp_5xx':40,
'hrsp_other':41,
'hanafail':42,
'req_rate':43,
'req_rate_max':44,
'req_tot':45,
'cli_abrt':46,
'srv_abrt':47,
'comp_in':48,
'comp_out':49,
'comp_byp':50,
'comp_rsp':51,
'lastsess':52,
'last_chk':53,
'last_agt':54,
'qtime':55,
'ctime':56,
'rtime':57,
'ttime':58,
'agent_status':59,
'agent_code':60,
'agent_duration':61,
'check_desc':62,
'agent_desc':63,
'check_rise':64,
'check_fall':65,
'check_health':66,
'agent_rise':67,
'agent_fall':68,
'agent_health':69,
'addr':70,
'cookie':71,
'mode':72,
'algo':73,
'conn_rate':74,
'conn_rate_max':75,
'conn_tot':76,
'intercepted':77,
'dcon':78,
'dses':79
}
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions README.md
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
python-haproxy
python-haproxy collectD plugin
==============

Read haproxy stats using socket.

based on python-haproxy `git clone https://github.com/nl5887/python-haproxy.git`

Read haproxy stats using socket
before using it in CollectD
replace
```import collectd_mockup as collectd```
to
```#import collectd```


and comment out at the bottom
```read_callback()```


data returnded to collectD looks like:
```
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BE_test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/FE_test_r36/qcur =
instance/type/type_instance: master-prod/FE_fe_test_r37/qcur =

```


# Info from python-haproxy

## Install
There are a few different ways you can install pyechonest:
Expand Down
146 changes: 146 additions & 0 deletions haproxy-plugin.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys
import os
import commands
import socket
import time

try:
import collectd
except:
import tools.collectd_mockup as collectd

from haproxy import haproxy
from tools.data_list import data_gathered
from tools. data_list import data_stat_index


PLUGIN_NAME = os.path.basename(__file__).split(".")[0]
stats = haproxy.HAProxyStats('/var/run/haproxy/haproxy.sock')
VERBOSE_LOGGING = True

# convert list of "arg: val" to dict[arg]=val
def str2dict(arg):
rez = {}
for x in arg:
if x:
rez[(x.split(':')[0]).strip()] = x.split(':')[1].strip()

return rez

def log_verbose(msg):
if not VERBOSE_LOGGING:
return
collectd.info('haproxy plugin [verbose]: %s' % msg)




# callback funcion for collectd Daemon
def read_callback(data=None):

metric = collectd.Values()

#
# get Haproxy stat info
#
rez = str2dict(stats.execute('show info'))
instance = rez['node'] or socket.gethostname()
# loop over keys that we need
for i in data_gathered['info']:

metric.plugin = PLUGIN_NAME
metric.interval = 60
metric.plugin_instance = instance
metric.type = 'status'
metric.type_instance = i
metric.values = (unicodedata.numeric(rez[i]),) #values must be list or tuple
# metric.dispatch()

#
# get stat info
#
f_ends = {}
b_ends = {}
b_ends_summ = {}
for x in stats.execute('show stat'):

# skiping some trash
if x.startswith("#"):
continue
if x.startswith("stats"):
continue
if x == '':
continue

# convert string into array
tmp = x.split(',')

# fill frontends
if tmp[1] == 'FRONTEND':
f_ends[tmp[0]] = tmp
continue

# fill backend summary info
if tmp[1] == 'BACKEND':
b_ends_summ[tmp[0]] = tmp
continue

# fill backen workers info
b_ends["%s@%s" % (tmp[1],tmp[0])] = tmp




# fill data for backends
for z in data_gathered['stat']:
# fill info for backend/workers
for k, v in b_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = 'be_workers'
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in b_ends_summ.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "backend"
metric.type_instance = "%s_%s" % (k,z)
metric.values = (v[data_stat_index[z]],) # values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in f_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "frontend"
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()




#for debugging purposes
read_callback()

collectd.register_read(read_callback)

6 changes: 4 additions & 2 deletions haproxy/haproxy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,8 +42,10 @@ def execute(self, command, timeout=200):

for s in r:
if (s is client):
buffer = buffer + client.recv(16384)
running = (len(buffer)==0)
tmp = client.recv(16384)
buffer = buffer + tmp
if tmp == '':
running = (len(buffer)==0)

client.close()

Expand Down
2 changes: 2 additions & 0 deletions tools/__init__.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-

23 changes: 23 additions & 0 deletions tools/collectd_mockup.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python


class Values:
plugin = ''
interval = ''
plugin_instance = ''
type = ''
type_instance = ''
values = ''

def dispatch(self):
pass
#print "instance/type/type_instance: %s/%s/%s = %s" % (self.plugin_instance, self.type, self.type_instance, self.values)
# print ""

def info(self, arg=''):
pass


def register_read(read_callback):
pass

152 changes: 152 additions & 0 deletions tools/data_list.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
#!/usr/bin/py

data_gathered = {}

data_gathered['info'] = [
#'Name',
#'Version',
#'Release_date',
#'Nbproc',
#'Process_num',
#'Pid',
#'Uptime',
#'Uptime_sec',
#'Memmax_MB',
#'Ulimit-n',
#'Maxsock',
#'Maxconn',
#'Hard_maxconn',
#'CurrConns',
#'CumConns',
#'CumReq',
#'MaxSslConns',
#'CurrSslConns',
#'CumSslConns',
#'Maxpipes',
#'PipesUsed',
#'PipesFree',
#'ConnRate',
#'ConnRateLimit',
#'MaxConnRate',
#'SessRate',
#'SessRateLimit',
#'MaxSessRate',
#'SslRate',
#'SslRateLimit',
#'MaxSslRate',
#'SslFrontendKeyRate',
#'SslFrontendMaxKeyRate',
#'SslFrontendSessionReuse_pct',
#'SslBackendKeyRate',
#'SslBackendMaxKeyRate',
#'SslCacheLookups',
#'SslCacheMisses',
#'CompressBpsIn',
#'CompressBpsOut',
#'CompressBpsRateLim',
#'ZlibMemUsage',
#'MaxZlibMemUsage',
#'Tasks',
#'Run_queue',
#'Idle_pct',
#'node',
#'description'
]


data_gathered['stat'] = [
#'pxname',
#'svname',
'qcur',
'scur',
'stot',
'bin',
'bout',
'dreq',
'dresp',
'ereqeconeresp',
]


data_stat_index = {
'pxname':0,
'svname':1,
'qcur':2,
'qmax':3,
'scur':4,
'smax':5,
'slim':6,
'stot':7,
'bin':8,
'bout':9,
'dreq':10,
'dresp':11,
'ereqeconeresp':12,
'wretr':13,
'wredis':14,
'status':15,
'weight':16,
'act':17,
'bckchkfail':18,
'chkdown':19,
'lastchg':20,
'downtime':21,
'qlimit':22,
'pid':23,
'iid':24,
'sid':25,
'throttle':26,
'lbtot':27,
'tracked':28,
'type':29,
'rate':30,
'rate_lim':31,
'rate_max':32,
'check_status':33,
'check_code':34,
'check_duration':35,
'hrsp_1xx':36,
'hrsp_2xx':37,
'hrsp_3xx':38,
'hrsp_4xx':39,
'hrsp_5xx':40,
'hrsp_other':41,
'hanafail':42,
'req_rate':43,
'req_rate_max':44,
'req_tot':45,
'cli_abrt':46,
'srv_abrt':47,
'comp_in':48,
'comp_out':49,
'comp_byp':50,
'comp_rsp':51,
'lastsess':52,
'last_chk':53,
'last_agt':54,
'qtime':55,
'ctime':56,
'rtime':57,
'ttime':58,
'agent_status':59,
'agent_code':60,
'agent_duration':61,
'check_desc':62,
'agent_desc':63,
'check_rise':64,
'check_fall':65,
'check_health':66,
'agent_rise':67,
'agent_fall':68,
'agent_health':69,
'addr':70,
'cookie':71,
'mode':72,
'algo':73,
'conn_rate':74,
'conn_rate_max':75,
'conn_tot':76,
'intercepted':77,
'dcon':78,
'dses':79
}
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions README.md
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
python-haproxy
python-haproxy collectD plugin
==============

Read haproxy stats using socket.

based on python-haproxy `git clone https://github.com/nl5887/python-haproxy.git`

Read haproxy stats using socket
before using it in CollectD
replace
```import collectd_mockup as collectd```
to
```#import collectd```


and comment out at the bottom
```read_callback()```


data returnded to collectD looks like:
```
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BE_test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/FE_test_r36/qcur =
instance/type/type_instance: master-prod/FE_fe_test_r37/qcur =

```


# Info from python-haproxy

## Install
There are a few different ways you can install pyechonest:
Expand Down
146 changes: 146 additions & 0 deletions haproxy-plugin.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys
import os
import commands
import socket
import time

try:
import collectd
except:
import tools.collectd_mockup as collectd

from haproxy import haproxy
from tools.data_list import data_gathered
from tools. data_list import data_stat_index


PLUGIN_NAME = os.path.basename(__file__).split(".")[0]
stats = haproxy.HAProxyStats('/var/run/haproxy/haproxy.sock')
VERBOSE_LOGGING = True

# convert list of "arg: val" to dict[arg]=val
def str2dict(arg):
rez = {}
for x in arg:
if x:
rez[(x.split(':')[0]).strip()] = x.split(':')[1].strip()

return rez

def log_verbose(msg):
if not VERBOSE_LOGGING:
return
collectd.info('haproxy plugin [verbose]: %s' % msg)




# callback funcion for collectd Daemon
def read_callback(data=None):

metric = collectd.Values()

#
# get Haproxy stat info
#
rez = str2dict(stats.execute('show info'))
instance = rez['node'] or socket.gethostname()
# loop over keys that we need
for i in data_gathered['info']:

metric.plugin = PLUGIN_NAME
metric.interval = 60
metric.plugin_instance = instance
metric.type = 'status'
metric.type_instance = i
metric.values = (unicodedata.numeric(rez[i]),) #values must be list or tuple
# metric.dispatch()

#
# get stat info
#
f_ends = {}
b_ends = {}
b_ends_summ = {}
for x in stats.execute('show stat'):

# skiping some trash
if x.startswith("#"):
continue
if x.startswith("stats"):
continue
if x == '':
continue

# convert string into array
tmp = x.split(',')

# fill frontends
if tmp[1] == 'FRONTEND':
f_ends[tmp[0]] = tmp
continue

# fill backend summary info
if tmp[1] == 'BACKEND':
b_ends_summ[tmp[0]] = tmp
continue

# fill backen workers info
b_ends["%s@%s" % (tmp[1],tmp[0])] = tmp




# fill data for backends
for z in data_gathered['stat']:
# fill info for backend/workers
for k, v in b_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = 'be_workers'
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in b_ends_summ.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "backend"
metric.type_instance = "%s_%s" % (k,z)
metric.values = (v[data_stat_index[z]],) # values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in f_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "frontend"
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()




#for debugging purposes
read_callback()

collectd.register_read(read_callback)

6 changes: 4 additions & 2 deletions haproxy/haproxy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,8 +42,10 @@ def execute(self, command, timeout=200):

for s in r:
if (s is client):
buffer = buffer + client.recv(16384)
running = (len(buffer)==0)
tmp = client.recv(16384)
buffer = buffer + tmp
if tmp == '':
running = (len(buffer)==0)

client.close()

Expand Down
2 changes: 2 additions & 0 deletions tools/__init__.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-

23 changes: 23 additions & 0 deletions tools/collectd_mockup.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python


class Values:
plugin = ''
interval = ''
plugin_instance = ''
type = ''
type_instance = ''
values = ''

def dispatch(self):
pass
#print "instance/type/type_instance: %s/%s/%s = %s" % (self.plugin_instance, self.type, self.type_instance, self.values)
# print ""

def info(self, arg=''):
pass


def register_read(read_callback):
pass

152 changes: 152 additions & 0 deletions tools/data_list.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
#!/usr/bin/py

data_gathered = {}

data_gathered['info'] = [
#'Name',
#'Version',
#'Release_date',
#'Nbproc',
#'Process_num',
#'Pid',
#'Uptime',
#'Uptime_sec',
#'Memmax_MB',
#'Ulimit-n',
#'Maxsock',
#'Maxconn',
#'Hard_maxconn',
#'CurrConns',
#'CumConns',
#'CumReq',
#'MaxSslConns',
#'CurrSslConns',
#'CumSslConns',
#'Maxpipes',
#'PipesUsed',
#'PipesFree',
#'ConnRate',
#'ConnRateLimit',
#'MaxConnRate',
#'SessRate',
#'SessRateLimit',
#'MaxSessRate',
#'SslRate',
#'SslRateLimit',
#'MaxSslRate',
#'SslFrontendKeyRate',
#'SslFrontendMaxKeyRate',
#'SslFrontendSessionReuse_pct',
#'SslBackendKeyRate',
#'SslBackendMaxKeyRate',
#'SslCacheLookups',
#'SslCacheMisses',
#'CompressBpsIn',
#'CompressBpsOut',
#'CompressBpsRateLim',
#'ZlibMemUsage',
#'MaxZlibMemUsage',
#'Tasks',
#'Run_queue',
#'Idle_pct',
#'node',
#'description'
]


data_gathered['stat'] = [
#'pxname',
#'svname',
'qcur',
'scur',
'stot',
'bin',
'bout',
'dreq',
'dresp',
'ereqeconeresp',
]


data_stat_index = {
'pxname':0,
'svname':1,
'qcur':2,
'qmax':3,
'scur':4,
'smax':5,
'slim':6,
'stot':7,
'bin':8,
'bout':9,
'dreq':10,
'dresp':11,
'ereqeconeresp':12,
'wretr':13,
'wredis':14,
'status':15,
'weight':16,
'act':17,
'bckchkfail':18,
'chkdown':19,
'lastchg':20,
'downtime':21,
'qlimit':22,
'pid':23,
'iid':24,
'sid':25,
'throttle':26,
'lbtot':27,
'tracked':28,
'type':29,
'rate':30,
'rate_lim':31,
'rate_max':32,
'check_status':33,
'check_code':34,
'check_duration':35,
'hrsp_1xx':36,
'hrsp_2xx':37,
'hrsp_3xx':38,
'hrsp_4xx':39,
'hrsp_5xx':40,
'hrsp_other':41,
'hanafail':42,
'req_rate':43,
'req_rate_max':44,
'req_tot':45,
'cli_abrt':46,
'srv_abrt':47,
'comp_in':48,
'comp_out':49,
'comp_byp':50,
'comp_rsp':51,
'lastsess':52,
'last_chk':53,
'last_agt':54,
'qtime':55,
'ctime':56,
'rtime':57,
'ttime':58,
'agent_status':59,
'agent_code':60,
'agent_duration':61,
'check_desc':62,
'agent_desc':63,
'check_rise':64,
'check_fall':65,
'check_health':66,
'agent_rise':67,
'agent_fall':68,
'agent_health':69,
'addr':70,
'cookie':71,
'mode':72,
'algo':73,
'conn_rate':74,
'conn_rate_max':75,
'conn_tot':76,
'intercepted':77,
'dcon':78,
'dses':79
}
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions README.md
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
python-haproxy
python-haproxy collectD plugin
==============

Read haproxy stats using socket.

based on python-haproxy `git clone https://github.com/nl5887/python-haproxy.git`

Read haproxy stats using socket
before using it in CollectD
replace
```import collectd_mockup as collectd```
to
```#import collectd```


and comment out at the bottom
```read_callback()```


data returnded to collectD looks like:
```
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BE_test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/FE_test_r36/qcur =
instance/type/type_instance: master-prod/FE_fe_test_r37/qcur =

```


# Info from python-haproxy

## Install
There are a few different ways you can install pyechonest:
Expand Down
146 changes: 146 additions & 0 deletions haproxy-plugin.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys
import os
import commands
import socket
import time

try:
import collectd
except:
import tools.collectd_mockup as collectd

from haproxy import haproxy
from tools.data_list import data_gathered
from tools. data_list import data_stat_index


PLUGIN_NAME = os.path.basename(__file__).split(".")[0]
stats = haproxy.HAProxyStats('/var/run/haproxy/haproxy.sock')
VERBOSE_LOGGING = True

# convert list of "arg: val" to dict[arg]=val
def str2dict(arg):
rez = {}
for x in arg:
if x:
rez[(x.split(':')[0]).strip()] = x.split(':')[1].strip()

return rez

def log_verbose(msg):
if not VERBOSE_LOGGING:
return
collectd.info('haproxy plugin [verbose]: %s' % msg)




# callback funcion for collectd Daemon
def read_callback(data=None):

metric = collectd.Values()

#
# get Haproxy stat info
#
rez = str2dict(stats.execute('show info'))
instance = rez['node'] or socket.gethostname()
# loop over keys that we need
for i in data_gathered['info']:

metric.plugin = PLUGIN_NAME
metric.interval = 60
metric.plugin_instance = instance
metric.type = 'status'
metric.type_instance = i
metric.values = (unicodedata.numeric(rez[i]),) #values must be list or tuple
# metric.dispatch()

#
# get stat info
#
f_ends = {}
b_ends = {}
b_ends_summ = {}
for x in stats.execute('show stat'):

# skiping some trash
if x.startswith("#"):
continue
if x.startswith("stats"):
continue
if x == '':
continue

# convert string into array
tmp = x.split(',')

# fill frontends
if tmp[1] == 'FRONTEND':
f_ends[tmp[0]] = tmp
continue

# fill backend summary info
if tmp[1] == 'BACKEND':
b_ends_summ[tmp[0]] = tmp
continue

# fill backen workers info
b_ends["%s@%s" % (tmp[1],tmp[0])] = tmp




# fill data for backends
for z in data_gathered['stat']:
# fill info for backend/workers
for k, v in b_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = 'be_workers'
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in b_ends_summ.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "backend"
metric.type_instance = "%s_%s" % (k,z)
metric.values = (v[data_stat_index[z]],) # values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in f_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "frontend"
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()




#for debugging purposes
read_callback()

collectd.register_read(read_callback)

6 changes: 4 additions & 2 deletions haproxy/haproxy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,8 +42,10 @@ def execute(self, command, timeout=200):

for s in r:
if (s is client):
buffer = buffer + client.recv(16384)
running = (len(buffer)==0)
tmp = client.recv(16384)
buffer = buffer + tmp
if tmp == '':
running = (len(buffer)==0)

client.close()

Expand Down
2 changes: 2 additions & 0 deletions tools/__init__.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-

23 changes: 23 additions & 0 deletions tools/collectd_mockup.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python


class Values:
plugin = ''
interval = ''
plugin_instance = ''
type = ''
type_instance = ''
values = ''

def dispatch(self):
pass
#print "instance/type/type_instance: %s/%s/%s = %s" % (self.plugin_instance, self.type, self.type_instance, self.values)
# print ""

def info(self, arg=''):
pass


def register_read(read_callback):
pass

152 changes: 152 additions & 0 deletions tools/data_list.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
#!/usr/bin/py

data_gathered = {}

data_gathered['info'] = [
#'Name',
#'Version',
#'Release_date',
#'Nbproc',
#'Process_num',
#'Pid',
#'Uptime',
#'Uptime_sec',
#'Memmax_MB',
#'Ulimit-n',
#'Maxsock',
#'Maxconn',
#'Hard_maxconn',
#'CurrConns',
#'CumConns',
#'CumReq',
#'MaxSslConns',
#'CurrSslConns',
#'CumSslConns',
#'Maxpipes',
#'PipesUsed',
#'PipesFree',
#'ConnRate',
#'ConnRateLimit',
#'MaxConnRate',
#'SessRate',
#'SessRateLimit',
#'MaxSessRate',
#'SslRate',
#'SslRateLimit',
#'MaxSslRate',
#'SslFrontendKeyRate',
#'SslFrontendMaxKeyRate',
#'SslFrontendSessionReuse_pct',
#'SslBackendKeyRate',
#'SslBackendMaxKeyRate',
#'SslCacheLookups',
#'SslCacheMisses',
#'CompressBpsIn',
#'CompressBpsOut',
#'CompressBpsRateLim',
#'ZlibMemUsage',
#'MaxZlibMemUsage',
#'Tasks',
#'Run_queue',
#'Idle_pct',
#'node',
#'description'
]


data_gathered['stat'] = [
#'pxname',
#'svname',
'qcur',
'scur',
'stot',
'bin',
'bout',
'dreq',
'dresp',
'ereqeconeresp',
]


data_stat_index = {
'pxname':0,
'svname':1,
'qcur':2,
'qmax':3,
'scur':4,
'smax':5,
'slim':6,
'stot':7,
'bin':8,
'bout':9,
'dreq':10,
'dresp':11,
'ereqeconeresp':12,
'wretr':13,
'wredis':14,
'status':15,
'weight':16,
'act':17,
'bckchkfail':18,
'chkdown':19,
'lastchg':20,
'downtime':21,
'qlimit':22,
'pid':23,
'iid':24,
'sid':25,
'throttle':26,
'lbtot':27,
'tracked':28,
'type':29,
'rate':30,
'rate_lim':31,
'rate_max':32,
'check_status':33,
'check_code':34,
'check_duration':35,
'hrsp_1xx':36,
'hrsp_2xx':37,
'hrsp_3xx':38,
'hrsp_4xx':39,
'hrsp_5xx':40,
'hrsp_other':41,
'hanafail':42,
'req_rate':43,
'req_rate_max':44,
'req_tot':45,
'cli_abrt':46,
'srv_abrt':47,
'comp_in':48,
'comp_out':49,
'comp_byp':50,
'comp_rsp':51,
'lastsess':52,
'last_chk':53,
'last_agt':54,
'qtime':55,
'ctime':56,
'rtime':57,
'ttime':58,
'agent_status':59,
'agent_code':60,
'agent_duration':61,
'check_desc':62,
'agent_desc':63,
'check_rise':64,
'check_fall':65,
'check_health':66,
'agent_rise':67,
'agent_fall':68,
'agent_health':69,
'addr':70,
'cookie':71,
'mode':72,
'algo':73,
'conn_rate':74,
'conn_rate_max':75,
'conn_tot':76,
'intercepted':77,
'dcon':78,
'dses':79
}
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions README.md
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
python-haproxy
python-haproxy collectD plugin
==============

Read haproxy stats using socket.

based on python-haproxy `git clone https://github.com/nl5887/python-haproxy.git`

Read haproxy stats using socket
before using it in CollectD
replace
```import collectd_mockup as collectd```
to
```#import collectd```


and comment out at the bottom
```read_callback()```


data returnded to collectD looks like:
```
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BE_test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/FE_test_r36/qcur =
instance/type/type_instance: master-prod/FE_fe_test_r37/qcur =

```


# Info from python-haproxy

## Install
There are a few different ways you can install pyechonest:
Expand Down
146 changes: 146 additions & 0 deletions haproxy-plugin.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys
import os
import commands
import socket
import time

try:
import collectd
except:
import tools.collectd_mockup as collectd

from haproxy import haproxy
from tools.data_list import data_gathered
from tools. data_list import data_stat_index


PLUGIN_NAME = os.path.basename(__file__).split(".")[0]
stats = haproxy.HAProxyStats('/var/run/haproxy/haproxy.sock')
VERBOSE_LOGGING = True

# convert list of "arg: val" to dict[arg]=val
def str2dict(arg):
rez = {}
for x in arg:
if x:
rez[(x.split(':')[0]).strip()] = x.split(':')[1].strip()

return rez

def log_verbose(msg):
if not VERBOSE_LOGGING:
return
collectd.info('haproxy plugin [verbose]: %s' % msg)




# callback funcion for collectd Daemon
def read_callback(data=None):

metric = collectd.Values()

#
# get Haproxy stat info
#
rez = str2dict(stats.execute('show info'))
instance = rez['node'] or socket.gethostname()
# loop over keys that we need
for i in data_gathered['info']:

metric.plugin = PLUGIN_NAME
metric.interval = 60
metric.plugin_instance = instance
metric.type = 'status'
metric.type_instance = i
metric.values = (unicodedata.numeric(rez[i]),) #values must be list or tuple
# metric.dispatch()

#
# get stat info
#
f_ends = {}
b_ends = {}
b_ends_summ = {}
for x in stats.execute('show stat'):

# skiping some trash
if x.startswith("#"):
continue
if x.startswith("stats"):
continue
if x == '':
continue

# convert string into array
tmp = x.split(',')

# fill frontends
if tmp[1] == 'FRONTEND':
f_ends[tmp[0]] = tmp
continue

# fill backend summary info
if tmp[1] == 'BACKEND':
b_ends_summ[tmp[0]] = tmp
continue

# fill backen workers info
b_ends["%s@%s" % (tmp[1],tmp[0])] = tmp




# fill data for backends
for z in data_gathered['stat']:
# fill info for backend/workers
for k, v in b_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = 'be_workers'
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in b_ends_summ.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "backend"
metric.type_instance = "%s_%s" % (k,z)
metric.values = (v[data_stat_index[z]],) # values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in f_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "frontend"
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()




#for debugging purposes
read_callback()

collectd.register_read(read_callback)

6 changes: 4 additions & 2 deletions haproxy/haproxy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,8 +42,10 @@ def execute(self, command, timeout=200):

for s in r:
if (s is client):
buffer = buffer + client.recv(16384)
running = (len(buffer)==0)
tmp = client.recv(16384)
buffer = buffer + tmp
if tmp == '':
running = (len(buffer)==0)

client.close()

Expand Down
2 changes: 2 additions & 0 deletions tools/__init__.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-

23 changes: 23 additions & 0 deletions tools/collectd_mockup.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python


class Values:
plugin = ''
interval = ''
plugin_instance = ''
type = ''
type_instance = ''
values = ''

def dispatch(self):
pass
#print "instance/type/type_instance: %s/%s/%s = %s" % (self.plugin_instance, self.type, self.type_instance, self.values)
# print ""

def info(self, arg=''):
pass


def register_read(read_callback):
pass

152 changes: 152 additions & 0 deletions tools/data_list.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
#!/usr/bin/py

data_gathered = {}

data_gathered['info'] = [
#'Name',
#'Version',
#'Release_date',
#'Nbproc',
#'Process_num',
#'Pid',
#'Uptime',
#'Uptime_sec',
#'Memmax_MB',
#'Ulimit-n',
#'Maxsock',
#'Maxconn',
#'Hard_maxconn',
#'CurrConns',
#'CumConns',
#'CumReq',
#'MaxSslConns',
#'CurrSslConns',
#'CumSslConns',
#'Maxpipes',
#'PipesUsed',
#'PipesFree',
#'ConnRate',
#'ConnRateLimit',
#'MaxConnRate',
#'SessRate',
#'SessRateLimit',
#'MaxSessRate',
#'SslRate',
#'SslRateLimit',
#'MaxSslRate',
#'SslFrontendKeyRate',
#'SslFrontendMaxKeyRate',
#'SslFrontendSessionReuse_pct',
#'SslBackendKeyRate',
#'SslBackendMaxKeyRate',
#'SslCacheLookups',
#'SslCacheMisses',
#'CompressBpsIn',
#'CompressBpsOut',
#'CompressBpsRateLim',
#'ZlibMemUsage',
#'MaxZlibMemUsage',
#'Tasks',
#'Run_queue',
#'Idle_pct',
#'node',
#'description'
]


data_gathered['stat'] = [
#'pxname',
#'svname',
'qcur',
'scur',
'stot',
'bin',
'bout',
'dreq',
'dresp',
'ereqeconeresp',
]


data_stat_index = {
'pxname':0,
'svname':1,
'qcur':2,
'qmax':3,
'scur':4,
'smax':5,
'slim':6,
'stot':7,
'bin':8,
'bout':9,
'dreq':10,
'dresp':11,
'ereqeconeresp':12,
'wretr':13,
'wredis':14,
'status':15,
'weight':16,
'act':17,
'bckchkfail':18,
'chkdown':19,
'lastchg':20,
'downtime':21,
'qlimit':22,
'pid':23,
'iid':24,
'sid':25,
'throttle':26,
'lbtot':27,
'tracked':28,
'type':29,
'rate':30,
'rate_lim':31,
'rate_max':32,
'check_status':33,
'check_code':34,
'check_duration':35,
'hrsp_1xx':36,
'hrsp_2xx':37,
'hrsp_3xx':38,
'hrsp_4xx':39,
'hrsp_5xx':40,
'hrsp_other':41,
'hanafail':42,
'req_rate':43,
'req_rate_max':44,
'req_tot':45,
'cli_abrt':46,
'srv_abrt':47,
'comp_in':48,
'comp_out':49,
'comp_byp':50,
'comp_rsp':51,
'lastsess':52,
'last_chk':53,
'last_agt':54,
'qtime':55,
'ctime':56,
'rtime':57,
'ttime':58,
'agent_status':59,
'agent_code':60,
'agent_duration':61,
'check_desc':62,
'agent_desc':63,
'check_rise':64,
'check_fall':65,
'check_health':66,
'agent_rise':67,
'agent_fall':68,
'agent_health':69,
'addr':70,
'cookie':71,
'mode':72,
'algo':73,
'conn_rate':74,
'conn_rate_max':75,
'conn_tot':76,
'intercepted':77,
'dcon':78,
'dses':79
}
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions README.md
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
python-haproxy
python-haproxy collectD plugin
==============

Read haproxy stats using socket.

based on python-haproxy `git clone https://github.com/nl5887/python-haproxy.git`

Read haproxy stats using socket
before using it in CollectD
replace
```import collectd_mockup as collectd```
to
```#import collectd```


and comment out at the bottom
```read_callback()```


data returnded to collectD looks like:
```
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BE_test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/FE_test_r36/qcur =
instance/type/type_instance: master-prod/FE_fe_test_r37/qcur =

```


# Info from python-haproxy

## Install
There are a few different ways you can install pyechonest:
Expand Down
146 changes: 146 additions & 0 deletions haproxy-plugin.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys
import os
import commands
import socket
import time

try:
import collectd
except:
import tools.collectd_mockup as collectd

from haproxy import haproxy
from tools.data_list import data_gathered
from tools. data_list import data_stat_index


PLUGIN_NAME = os.path.basename(__file__).split(".")[0]
stats = haproxy.HAProxyStats('/var/run/haproxy/haproxy.sock')
VERBOSE_LOGGING = True

# convert list of "arg: val" to dict[arg]=val
def str2dict(arg):
rez = {}
for x in arg:
if x:
rez[(x.split(':')[0]).strip()] = x.split(':')[1].strip()

return rez

def log_verbose(msg):
if not VERBOSE_LOGGING:
return
collectd.info('haproxy plugin [verbose]: %s' % msg)




# callback funcion for collectd Daemon
def read_callback(data=None):

metric = collectd.Values()

#
# get Haproxy stat info
#
rez = str2dict(stats.execute('show info'))
instance = rez['node'] or socket.gethostname()
# loop over keys that we need
for i in data_gathered['info']:

metric.plugin = PLUGIN_NAME
metric.interval = 60
metric.plugin_instance = instance
metric.type = 'status'
metric.type_instance = i
metric.values = (unicodedata.numeric(rez[i]),) #values must be list or tuple
# metric.dispatch()

#
# get stat info
#
f_ends = {}
b_ends = {}
b_ends_summ = {}
for x in stats.execute('show stat'):

# skiping some trash
if x.startswith("#"):
continue
if x.startswith("stats"):
continue
if x == '':
continue

# convert string into array
tmp = x.split(',')

# fill frontends
if tmp[1] == 'FRONTEND':
f_ends[tmp[0]] = tmp
continue

# fill backend summary info
if tmp[1] == 'BACKEND':
b_ends_summ[tmp[0]] = tmp
continue

# fill backen workers info
b_ends["%s@%s" % (tmp[1],tmp[0])] = tmp




# fill data for backends
for z in data_gathered['stat']:
# fill info for backend/workers
for k, v in b_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = 'be_workers'
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in b_ends_summ.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "backend"
metric.type_instance = "%s_%s" % (k,z)
metric.values = (v[data_stat_index[z]],) # values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in f_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "frontend"
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()




#for debugging purposes
read_callback()

collectd.register_read(read_callback)

6 changes: 4 additions & 2 deletions haproxy/haproxy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,8 +42,10 @@ def execute(self, command, timeout=200):

for s in r:
if (s is client):
buffer = buffer + client.recv(16384)
running = (len(buffer)==0)
tmp = client.recv(16384)
buffer = buffer + tmp
if tmp == '':
running = (len(buffer)==0)

client.close()

Expand Down
2 changes: 2 additions & 0 deletions tools/__init__.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-

23 changes: 23 additions & 0 deletions tools/collectd_mockup.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python


class Values:
plugin = ''
interval = ''
plugin_instance = ''
type = ''
type_instance = ''
values = ''

def dispatch(self):
pass
#print "instance/type/type_instance: %s/%s/%s = %s" % (self.plugin_instance, self.type, self.type_instance, self.values)
# print ""

def info(self, arg=''):
pass


def register_read(read_callback):
pass

152 changes: 152 additions & 0 deletions tools/data_list.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
#!/usr/bin/py

data_gathered = {}

data_gathered['info'] = [
#'Name',
#'Version',
#'Release_date',
#'Nbproc',
#'Process_num',
#'Pid',
#'Uptime',
#'Uptime_sec',
#'Memmax_MB',
#'Ulimit-n',
#'Maxsock',
#'Maxconn',
#'Hard_maxconn',
#'CurrConns',
#'CumConns',
#'CumReq',
#'MaxSslConns',
#'CurrSslConns',
#'CumSslConns',
#'Maxpipes',
#'PipesUsed',
#'PipesFree',
#'ConnRate',
#'ConnRateLimit',
#'MaxConnRate',
#'SessRate',
#'SessRateLimit',
#'MaxSessRate',
#'SslRate',
#'SslRateLimit',
#'MaxSslRate',
#'SslFrontendKeyRate',
#'SslFrontendMaxKeyRate',
#'SslFrontendSessionReuse_pct',
#'SslBackendKeyRate',
#'SslBackendMaxKeyRate',
#'SslCacheLookups',
#'SslCacheMisses',
#'CompressBpsIn',
#'CompressBpsOut',
#'CompressBpsRateLim',
#'ZlibMemUsage',
#'MaxZlibMemUsage',
#'Tasks',
#'Run_queue',
#'Idle_pct',
#'node',
#'description'
]


data_gathered['stat'] = [
#'pxname',
#'svname',
'qcur',
'scur',
'stot',
'bin',
'bout',
'dreq',
'dresp',
'ereqeconeresp',
]


data_stat_index = {
'pxname':0,
'svname':1,
'qcur':2,
'qmax':3,
'scur':4,
'smax':5,
'slim':6,
'stot':7,
'bin':8,
'bout':9,
'dreq':10,
'dresp':11,
'ereqeconeresp':12,
'wretr':13,
'wredis':14,
'status':15,
'weight':16,
'act':17,
'bckchkfail':18,
'chkdown':19,
'lastchg':20,
'downtime':21,
'qlimit':22,
'pid':23,
'iid':24,
'sid':25,
'throttle':26,
'lbtot':27,
'tracked':28,
'type':29,
'rate':30,
'rate_lim':31,
'rate_max':32,
'check_status':33,
'check_code':34,
'check_duration':35,
'hrsp_1xx':36,
'hrsp_2xx':37,
'hrsp_3xx':38,
'hrsp_4xx':39,
'hrsp_5xx':40,
'hrsp_other':41,
'hanafail':42,
'req_rate':43,
'req_rate_max':44,
'req_tot':45,
'cli_abrt':46,
'srv_abrt':47,
'comp_in':48,
'comp_out':49,
'comp_byp':50,
'comp_rsp':51,
'lastsess':52,
'last_chk':53,
'last_agt':54,
'qtime':55,
'ctime':56,
'rtime':57,
'ttime':58,
'agent_status':59,
'agent_code':60,
'agent_duration':61,
'check_desc':62,
'agent_desc':63,
'check_rise':64,
'check_fall':65,
'check_health':66,
'agent_rise':67,
'agent_fall':68,
'agent_health':69,
'addr':70,
'cookie':71,
'mode':72,
'algo':73,
'conn_rate':74,
'conn_rate_max':75,
'conn_tot':76,
'intercepted':77,
'dcon':78,
'dses':79
}
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions README.md
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
python-haproxy
python-haproxy collectD plugin
==============

Read haproxy stats using socket.

based on python-haproxy `git clone https://github.com/nl5887/python-haproxy.git`

Read haproxy stats using socket
before using it in CollectD
replace
```import collectd_mockup as collectd```
to
```#import collectd```


and comment out at the bottom
```read_callback()```


data returnded to collectD looks like:
```
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BE_test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/FE_test_r36/qcur =
instance/type/type_instance: master-prod/FE_fe_test_r37/qcur =

```


# Info from python-haproxy

## Install
There are a few different ways you can install pyechonest:
Expand Down
146 changes: 146 additions & 0 deletions haproxy-plugin.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys
import os
import commands
import socket
import time

try:
import collectd
except:
import tools.collectd_mockup as collectd

from haproxy import haproxy
from tools.data_list import data_gathered
from tools. data_list import data_stat_index


PLUGIN_NAME = os.path.basename(__file__).split(".")[0]
stats = haproxy.HAProxyStats('/var/run/haproxy/haproxy.sock')
VERBOSE_LOGGING = True

# convert list of "arg: val" to dict[arg]=val
def str2dict(arg):
rez = {}
for x in arg:
if x:
rez[(x.split(':')[0]).strip()] = x.split(':')[1].strip()

return rez

def log_verbose(msg):
if not VERBOSE_LOGGING:
return
collectd.info('haproxy plugin [verbose]: %s' % msg)




# callback funcion for collectd Daemon
def read_callback(data=None):

metric = collectd.Values()

#
# get Haproxy stat info
#
rez = str2dict(stats.execute('show info'))
instance = rez['node'] or socket.gethostname()
# loop over keys that we need
for i in data_gathered['info']:

metric.plugin = PLUGIN_NAME
metric.interval = 60
metric.plugin_instance = instance
metric.type = 'status'
metric.type_instance = i
metric.values = (unicodedata.numeric(rez[i]),) #values must be list or tuple
# metric.dispatch()

#
# get stat info
#
f_ends = {}
b_ends = {}
b_ends_summ = {}
for x in stats.execute('show stat'):

# skiping some trash
if x.startswith("#"):
continue
if x.startswith("stats"):
continue
if x == '':
continue

# convert string into array
tmp = x.split(',')

# fill frontends
if tmp[1] == 'FRONTEND':
f_ends[tmp[0]] = tmp
continue

# fill backend summary info
if tmp[1] == 'BACKEND':
b_ends_summ[tmp[0]] = tmp
continue

# fill backen workers info
b_ends["%s@%s" % (tmp[1],tmp[0])] = tmp




# fill data for backends
for z in data_gathered['stat']:
# fill info for backend/workers
for k, v in b_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = 'be_workers'
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in b_ends_summ.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "backend"
metric.type_instance = "%s_%s" % (k,z)
metric.values = (v[data_stat_index[z]],) # values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in f_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "frontend"
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()




#for debugging purposes
read_callback()

collectd.register_read(read_callback)

6 changes: 4 additions & 2 deletions haproxy/haproxy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,8 +42,10 @@ def execute(self, command, timeout=200):

for s in r:
if (s is client):
buffer = buffer + client.recv(16384)
running = (len(buffer)==0)
tmp = client.recv(16384)
buffer = buffer + tmp
if tmp == '':
running = (len(buffer)==0)

client.close()

Expand Down
2 changes: 2 additions & 0 deletions tools/__init__.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-

23 changes: 23 additions & 0 deletions tools/collectd_mockup.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python


class Values:
plugin = ''
interval = ''
plugin_instance = ''
type = ''
type_instance = ''
values = ''

def dispatch(self):
pass
#print "instance/type/type_instance: %s/%s/%s = %s" % (self.plugin_instance, self.type, self.type_instance, self.values)
# print ""

def info(self, arg=''):
pass


def register_read(read_callback):
pass

152 changes: 152 additions & 0 deletions tools/data_list.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
#!/usr/bin/py

data_gathered = {}

data_gathered['info'] = [
#'Name',
#'Version',
#'Release_date',
#'Nbproc',
#'Process_num',
#'Pid',
#'Uptime',
#'Uptime_sec',
#'Memmax_MB',
#'Ulimit-n',
#'Maxsock',
#'Maxconn',
#'Hard_maxconn',
#'CurrConns',
#'CumConns',
#'CumReq',
#'MaxSslConns',
#'CurrSslConns',
#'CumSslConns',
#'Maxpipes',
#'PipesUsed',
#'PipesFree',
#'ConnRate',
#'ConnRateLimit',
#'MaxConnRate',
#'SessRate',
#'SessRateLimit',
#'MaxSessRate',
#'SslRate',
#'SslRateLimit',
#'MaxSslRate',
#'SslFrontendKeyRate',
#'SslFrontendMaxKeyRate',
#'SslFrontendSessionReuse_pct',
#'SslBackendKeyRate',
#'SslBackendMaxKeyRate',
#'SslCacheLookups',
#'SslCacheMisses',
#'CompressBpsIn',
#'CompressBpsOut',
#'CompressBpsRateLim',
#'ZlibMemUsage',
#'MaxZlibMemUsage',
#'Tasks',
#'Run_queue',
#'Idle_pct',
#'node',
#'description'
]


data_gathered['stat'] = [
#'pxname',
#'svname',
'qcur',
'scur',
'stot',
'bin',
'bout',
'dreq',
'dresp',
'ereqeconeresp',
]


data_stat_index = {
'pxname':0,
'svname':1,
'qcur':2,
'qmax':3,
'scur':4,
'smax':5,
'slim':6,
'stot':7,
'bin':8,
'bout':9,
'dreq':10,
'dresp':11,
'ereqeconeresp':12,
'wretr':13,
'wredis':14,
'status':15,
'weight':16,
'act':17,
'bckchkfail':18,
'chkdown':19,
'lastchg':20,
'downtime':21,
'qlimit':22,
'pid':23,
'iid':24,
'sid':25,
'throttle':26,
'lbtot':27,
'tracked':28,
'type':29,
'rate':30,
'rate_lim':31,
'rate_max':32,
'check_status':33,
'check_code':34,
'check_duration':35,
'hrsp_1xx':36,
'hrsp_2xx':37,
'hrsp_3xx':38,
'hrsp_4xx':39,
'hrsp_5xx':40,
'hrsp_other':41,
'hanafail':42,
'req_rate':43,
'req_rate_max':44,
'req_tot':45,
'cli_abrt':46,
'srv_abrt':47,
'comp_in':48,
'comp_out':49,
'comp_byp':50,
'comp_rsp':51,
'lastsess':52,
'last_chk':53,
'last_agt':54,
'qtime':55,
'ctime':56,
'rtime':57,
'ttime':58,
'agent_status':59,
'agent_code':60,
'agent_duration':61,
'check_desc':62,
'agent_desc':63,
'check_rise':64,
'check_fall':65,
'check_health':66,
'agent_rise':67,
'agent_fall':68,
'agent_health':69,
'addr':70,
'cookie':71,
'mode':72,
'algo':73,
'conn_rate':74,
'conn_rate_max':75,
'conn_tot':76,
'intercepted':77,
'dcon':78,
'dses':79
}
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions README.md
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
python-haproxy
python-haproxy collectD plugin
==============

Read haproxy stats using socket.

based on python-haproxy `git clone https://github.com/nl5887/python-haproxy.git`

Read haproxy stats using socket
before using it in CollectD
replace
```import collectd_mockup as collectd```
to
```#import collectd```


and comment out at the bottom
```read_callback()```


data returnded to collectD looks like:
```
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_1@test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/BW_server_192.168.99.203_25036_2@be_test_sql_r37/qcur = 0
instance/type/type_instance: master-prod/BE_test_sql_r36/qcur = 0
instance/type/type_instance: master-prod/FE_test_r36/qcur =
instance/type/type_instance: master-prod/FE_fe_test_r37/qcur =

```


# Info from python-haproxy

## Install
There are a few different ways you can install pyechonest:
Expand Down
146 changes: 146 additions & 0 deletions haproxy-plugin.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys
import os
import commands
import socket
import time

try:
import collectd
except:
import tools.collectd_mockup as collectd

from haproxy import haproxy
from tools.data_list import data_gathered
from tools. data_list import data_stat_index


PLUGIN_NAME = os.path.basename(__file__).split(".")[0]
stats = haproxy.HAProxyStats('/var/run/haproxy/haproxy.sock')
VERBOSE_LOGGING = True

# convert list of "arg: val" to dict[arg]=val
def str2dict(arg):
rez = {}
for x in arg:
if x:
rez[(x.split(':')[0]).strip()] = x.split(':')[1].strip()

return rez

def log_verbose(msg):
if not VERBOSE_LOGGING:
return
collectd.info('haproxy plugin [verbose]: %s' % msg)




# callback funcion for collectd Daemon
def read_callback(data=None):

metric = collectd.Values()

#
# get Haproxy stat info
#
rez = str2dict(stats.execute('show info'))
instance = rez['node'] or socket.gethostname()
# loop over keys that we need
for i in data_gathered['info']:

metric.plugin = PLUGIN_NAME
metric.interval = 60
metric.plugin_instance = instance
metric.type = 'status'
metric.type_instance = i
metric.values = (unicodedata.numeric(rez[i]),) #values must be list or tuple
# metric.dispatch()

#
# get stat info
#
f_ends = {}
b_ends = {}
b_ends_summ = {}
for x in stats.execute('show stat'):

# skiping some trash
if x.startswith("#"):
continue
if x.startswith("stats"):
continue
if x == '':
continue

# convert string into array
tmp = x.split(',')

# fill frontends
if tmp[1] == 'FRONTEND':
f_ends[tmp[0]] = tmp
continue

# fill backend summary info
if tmp[1] == 'BACKEND':
b_ends_summ[tmp[0]] = tmp
continue

# fill backen workers info
b_ends["%s@%s" % (tmp[1],tmp[0])] = tmp




# fill data for backends
for z in data_gathered['stat']:
# fill info for backend/workers
for k, v in b_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = 'be_workers'
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in b_ends_summ.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "backend"
metric.type_instance = "%s_%s" % (k,z)
metric.values = (v[data_stat_index[z]],) # values must be list or tuple
metric.dispatch()
# fill info for backend summary
for k, v in f_ends.iteritems():
# skip empty values
if v[data_stat_index[z]]:
metric.plugin = PLUGIN_NAME
metric.interval = 60

metric.plugin_instance = instance
metric.type = "frontend"
metric.type_instance = "%s_%s" % (k,z)

metric.values = (v[data_stat_index[z]],) #values must be list or tuple
metric.dispatch()




#for debugging purposes
read_callback()

collectd.register_read(read_callback)

6 changes: 4 additions & 2 deletions haproxy/haproxy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,8 +42,10 @@ def execute(self, command, timeout=200):

for s in r:
if (s is client):
buffer = buffer + client.recv(16384)
running = (len(buffer)==0)
tmp = client.recv(16384)
buffer = buffer + tmp
if tmp == '':
running = (len(buffer)==0)

client.close()

Expand Down
2 changes: 2 additions & 0 deletions tools/__init__.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-

23 changes: 23 additions & 0 deletions tools/collectd_mockup.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python


class Values:
plugin = ''
interval = ''
plugin_instance = ''
type = ''
type_instance = ''
values = ''

def dispatch(self):
pass
#print "instance/type/type_instance: %s/%s/%s = %s" % (self.plugin_instance, self.type, self.type_instance, self.values)
# print ""

def info(self, arg=''):
pass


def register_read(read_callback):
pass

152 changes: 152 additions & 0 deletions tools/data_list.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
#!/usr/bin/py

data_gathered = {}

data_gathered['info'] = [
#'Name',
#'Version',
#'Release_date',
#'Nbproc',
#'Process_num',
#'Pid',
#'Uptime',
#'Uptime_sec',
#'Memmax_MB',
#'Ulimit-n',
#'Maxsock',
#'Maxconn',
#'Hard_maxconn',
#'CurrConns',
#'CumConns',
#'CumReq',
#'MaxSslConns',
#'CurrSslConns',
#'CumSslConns',
#'Maxpipes',
#'PipesUsed',
#'PipesFree',
#'ConnRate',
#'ConnRateLimit',
#'MaxConnRate',
#'SessRate',
#'SessRateLimit',
#'MaxSessRate',
#'SslRate',
#'SslRateLimit',
#'MaxSslRate',
#'SslFrontendKeyRate',
#'SslFrontendMaxKeyRate',
#'SslFrontendSessionReuse_pct',
#'SslBackendKeyRate',
#'SslBackendMaxKeyRate',
#'SslCacheLookups',
#'SslCacheMisses',
#'CompressBpsIn',
#'CompressBpsOut',
#'CompressBpsRateLim',
#'ZlibMemUsage',
#'MaxZlibMemUsage',
#'Tasks',
#'Run_queue',
#'Idle_pct',
#'node',
#'description'
]


data_gathered['stat'] = [
#'pxname',
#'svname',
'qcur',
'scur',
'stot',
'bin',
'bout',
'dreq',
'dresp',
'ereqeconeresp',
]


data_stat_index = {
'pxname':0,
'svname':1,
'qcur':2,
'qmax':3,
'scur':4,
'smax':5,
'slim':6,
'stot':7,
'bin':8,
'bout':9,
'dreq':10,
'dresp':11,
'ereqeconeresp':12,
'wretr':13,
'wredis':14,
'status':15,
'weight':16,
'act':17,
'bckchkfail':18,
'chkdown':19,
'lastchg':20,
'downtime':21,
'qlimit':22,
'pid':23,
'iid':24,
'sid':25,
'throttle':26,
'lbtot':27,
'tracked':28,
'type':29,
'rate':30,
'rate_lim':31,
'rate_max':32,
'check_status':33,
'check_code':34,
'check_duration':35,
'hrsp_1xx':36,
'hrsp_2xx':37,
'hrsp_3xx':38,
'hrsp_4xx':39,
'hrsp_5xx':40,
'hrsp_other':41,
'hanafail':42,
'req_rate':43,
'req_rate_max':44,
'req_tot':45,
'cli_abrt':46,
'srv_abrt':47,
'comp_in':48,
'comp_out':49,
'comp_byp':50,
'comp_rsp':51,
'lastsess':52,
'last_chk':53,
'last_agt':54,
'qtime':55,
'ctime':56,
'rtime':57,
'ttime':58,
'agent_status':59,
'agent_code':60,
'agent_duration':61,
'check_desc':62,
'agent_desc':63,
'check_rise':64,
'check_fall':65,
'check_health':66,
'agent_rise':67,
'agent_fall':68,
'agent_health':69,
'addr':70,
'cookie':71,
'mode':72,
'algo':73,
'conn_rate':74,
'conn_rate_max':75,
'conn_tot':76,
'intercepted':77,
'dcon':78,
'dses':79
}