1. Список говнокодов пользователя munin

    Всего: 55

  2. Python / Говнокод #22393

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    #!/usr/bin/python
    import sys, os, string, urllib2, json
    from urllib2 import HTTPError
    import socket
    
    THIS_SCRIPT_NAME = "piwik-num-visits_"
    THIS_PIWIK_URL = ""
    THIS_TOKEN_AUTH = ""
    THIS_ID_SITE = ""
    
    def get_json_data(method, json_key):
    	piwik_api_url = THIS_PIWIK_URL + "?module=API&idSite=" + THIS_ID_SITE + "&method=" + method + "&format=json&token_auth=" + THIS_TOKEN_AUTH
    
    	contents=""
    	try:
    		socket.setdefaulttimeout(10)
    		response = urllib2.urlopen(piwik_api_url)
    		contents = response.read()
    	except HTTPError, e:
    		sys.exit()
    
    	jsonContents = json.loads(contents)
    
    	result = None
    	if(not isinstance(jsonContents, list)):
    		result = jsonContents.get("result")
    
    	if(result != None and result == "error"):
    		return(0)
    
    	if(method.rfind("period") != -1):
    		return(jsonContents[json_key])
    	else:
    		return(jsonContents[0][json_key])
    
    def get_site_name():
    	try:
    		return(get_json_data("SitesManager.getSiteFromId", "name"))
    	except KeyError:
    		# we couldn't find the site name
    		return("Error Retrieving site")
    
    def get_num_visits():
    	try:
    		return(get_json_data("API.get&period=day&date=today", "nb_visits"))
    	except KeyError:
    		# we couldn't find the site name
    		return(0)
    
    if __name__ == "__main__":
    	# figure out which one we are doing
    	full_caller_name = sys.argv[0]
    	index_of_script = full_caller_name.find(THIS_SCRIPT_NAME)
    
    	piwik_url = os.environ.get("piwik.url")
    	token_auth = os.environ.get("piwik.token_auth")
    
    	if(None == piwik_url or None == token_auth):
    		print("FATAL: need url and auth token, got:")
    		print(piwik_url)
    		print(  "and")
    		print(token_auth)
    		sys.exit()
    	else:
    		THIS_PIWIK_URL = piwik_url
    		THIS_TOKEN_AUTH = token_auth
    
    	THIS_ID_SITE = sys.argv[0][len(THIS_SCRIPT_NAME) + index_of_script:]
    
    	# are we doing config/autoconfig?
    	if(len(sys.argv) > 1):
    		if (sys.argv[1]=="config"):
    			print "graph_title Daily Visits for: " + get_site_name()
    			print "graph_vlabel Number Of Visits"
    			print "graph_category piwik"
    			print "graph_order NUM_HITS"
    
    			# in green
    			print "NUM_HITS.label Number of Hits"
    			print "NUM_HITS.colour 00cc00"
    			print "NUM_HITS.draw AREA"
    
    			print "graph_args --base 1000 -l 0 "
    			sys.exit()
    
    	# now that we know the caller, get the environment
    	#stat_url = os.environ.get("url." + caller)
    
    	print("NUM_HITS.value %i" % (get_num_visits()))

    munin, 19 Февраля 2017

    Комментарии (0)
  3. Python / Говнокод #22392

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    #!/usr/bin/python
    
    # encoding utf8
    # head1 NAME
    #
    # ssl-expiry_ - Munin plugin to display number of days until an SSL certificate
    #     expires.
    #
    # APPLICABLE SYSTEMS
    #
    # Any system that can connect to the internet
    #
    # CONFIGURATION
    # 
    #
    
    import sys, os, string, subprocess, time
    from ssl import SSLError, cert_time_to_seconds
    
    THIS_SCRIPT_NAME = "ssl-expiry_"
    
    def get_num_days(site_name):
    	p1 = subprocess.Popen(["openssl", "s_client", "-connect", site_name + ":443"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    	p2 = subprocess.Popen(["openssl", "x509", "-noout", "-enddate"], stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    	p1.stdout.close()
    	output = p2.communicate();
    	not_after = output[0]
    	index_of = not_after.find("notAfter") 
    	if(index_of < 0):
    		# have an error here
    		return(0)
    	else:
    		# notAfter=Jan  6 11:02:56 2017 GMT
    		time_string = not_after[index_of + len("notAfter") + 1:-1]
    		num_seconds = cert_time_to_seconds(time_string)
    		return(int(round( (num_seconds - time.time())/(60*60*24))))
    
    if __name__ == "__main__":
    	# figure out which one we are doing
    	full_caller_name = sys.argv[0]
    	index_of_script = full_caller_name.find(THIS_SCRIPT_NAME)
    	site_name = sys.argv[0][len(THIS_SCRIPT_NAME) + index_of_script:]
    	# are we doing config/autoconfig?
    	if(len(sys.argv) > 1):
    		if (sys.argv[1]=="config"):
    			print "graph_title Days until SSL certificate for " + site_name + " expires."
    			print "graph_vlabel Number Of Days"
    			print "graph_category SSL"
    
    			# in green
    			print "NUM_DAYS.label Number of Days"
    			print "NUM_DAYS.colour 00cc00"
    			print "NUM_DAYS.draw AREA"
    
    			print "graph_args --base 1000 -l 0 "
    			sys.exit()
    
    	# now that we know the caller, get the environment
    	#stat_url = os.environ.get("url." + caller)
    
    	print("NUM_DAYS.value %i" % (get_num_days(site_name)))

    munin, 19 Февраля 2017

    Комментарии (0)
  4. Python / Говнокод #22391

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    #!/usr/bin/python
    
    # encoding utf8
    # head1 NAME
    #
    # stripe_account_balance
    #
    # CONFIGURATION
    #
    # This script is used to generate the daily totals for events that stripe has
    # fired within the current day.  At the time of writing the following events
    # are supported (see: https://stripe.com/docs/api#event_types)
    #
    # account.updated, account.application.deauthorized, balance.available, 
    # charge.succeeded, charge.failed, charge.refunded, charge.captured, 
    # charge.dispute.created, charge.dispute.updated, charge.dispute.closed, 
    # customer.created, customer.updated, customer.deleted, customer.card.created, 
    # customer.card.updated, customer.card.deleted, customer.subscription.created, 
    # customer.subscription.updated, customer.subscription.deleted, 
    # customer.subscription.trial_will_end, customer.discount.created, 
    # customer.discount.updated, customer.discount.deleted, invoice.created, 
    # invoice.updated, invoice.payment_succeeded, invoice.payment_failed, 
    # invoiceitem.created, invoiceitem.updated, invoiceitem.deleted, plan.created, 
    # plan.updated, plan.deleted, coupon.created, coupon.deleted, transfer.created, 
    # transfer.updated, transfer.paid, transfer.failed, ping, 
    # 
    # APPLICABLE SYSTEMS
    #
    # Any
    #
    # CONFIGURATION
    #
    # you will need to have the following configuration items
    #  env.STRIPE_API_KEY_PROD
    #
    
    import sys, os, string, urllib2, stripe
    from urllib2 import HTTPError
    from datetime import datetime
    import time
    import socket
    
    THIS_SCRIPT_NAME ="stripe_event_counter_"
    stripe.api_key = os.environ.get("STRIPE_API_KEY_PROD")
    
    def get_stats(event_type):
    	# get the time for todays 00:00
    	now = datetime.now()
    	previous_midnight = datetime(now.year, now.month, now.day)
    	previous_midnight_timestamp = int(time.mktime(previous_midnight.timetuple()))
    
    	# make the call
    	try:
    		jsonPayload = stripe.Event.all(count=0, type=event_type, created={"gt":previous_midnight_timestamp})
    		print("EVENT_COUNT.value %i" % (len(jsonPayload["data"])))
    	except HTTPError, e:
    		sys.exit()
    
    
    if __name__ == "__main__":
    	full_caller_name = sys.argv[0]
    	index_of_script = full_caller_name.find(THIS_SCRIPT_NAME)
    	event_type = sys.argv[0][len(THIS_SCRIPT_NAME) + index_of_script:]
    
    	# are we doing config/autoconfig?
    	if(len(sys.argv) > 1):
    		if (sys.argv[1]=="config"):
    			print "graph_title Event Count for '" + event_type + "'."
    			print "graph_vlabel Number of Events"
    			print "graph_category stripe"
    
    			# in green
    			print "EVENT_COUNT.label " + event_type + ""
    			print "EVENT_COUNT.colour 00cc00"
    			print "EVENT_COUNT.draw AREA"
    
    			print "graph_args --base 1000 "
    			sys.exit()
    
    	get_stats(event_type)

    munin, 19 Февраля 2017

    Комментарии (0)
  5. Python / Говнокод #22390

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    #!/usr/bin/python
    
    # encoding utf8
    # head1 NAME
    #
    # stripe_customers
    #
    # CONFIGURATION
    #
    # This script is used to generate data for the number of customers that are
    # attached to stripe
    #
    # APPLICABLE SYSTEMS
    #
    # Any
    #
    # CONFIGURATION
    #
    # you will need to have the following configuration items
    #  env.STRIPE_API_KEY_TEST
    #  env.STRIPE_API_KEY_PROD
    
    import sys, os, string, urllib2, stripe
    from urllib2 import HTTPError
    import socket
    
    def get_stats():
    	# we are going to look 
    	for env in "PROD", "TEST":
    		stripe.api_key = os.environ.get("STRIPE_API_KEY_" + env)
    		if(None != stripe.api_key):
    			try:
    				jsonPayload = stripe.Customer.all(count=0)
    				print("CUSTOMERS_%s.value %i" % (env, jsonPayload["count"]))
    			except HTTPError, e:
    				sys.exit()
    
    
    if __name__ == "__main__":
    	# are we doing config/autoconfig?
    	if(len(sys.argv) > 1):
    		if (sys.argv[1]=="config"):
    
    			print "graph_title Number of Stripe Customers"
    			print "graph_vlabel Number Of Customers"
    			print "graph_category stripe"
    
    			if(None != os.environ.get("STRIPE_API_KEY_PROD")):
    				# in green
    				print "CUSTOMERS_PROD.label Prod Customers"
    				print "CUSTOMERS_PROD.colour 00cc00"
    				print "CUSTOMERS_PROD.draw AREA"
    
    			if(None != os.environ.get("STRIPE_API_KEY_TEST")):
    				# in lovely orange
    				print "CUSTOMERS_TEST.label Test Customers"
    				print "CUSTOMERS_TEST.colour FF6600"
    				print "CUSTOMERS_TEST.draw LINE3"
    
    			sys.exit()
    
    			print "graph_args --base 1000 "
    
    	get_stats()

    munin, 19 Февраля 2017

    Комментарии (0)
  6. Python / Говнокод #22389

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    #!/usr/bin/python
    
    # encoding utf8
    # head1 NAME
    #
    # stripe_account_balance
    #
    # CONFIGURATION
    #
    # This script is used to generate data for the number of customers that are
    # attached to stripe
    #
    # APPLICABLE SYSTEMS
    #
    # Any
    #
    #
    # CONFIGURATION
    #
    # you will need to have the following configuration items
    #  env.STRIPE_API_KEY_PROD
    #
    
    import sys, os, string, urllib2, stripe
    from urllib2 import HTTPError
    import socket
    
    stripe.api_key = os.environ.get("STRIPE_API_KEY_PROD")
    
    def get_stats():
    	try:
    		jsonPayload = stripe.Balance.retrieve()
    		print("BALANCE_PENDING.value %i" % (jsonPayload["pending"][0]["amount"]))
    		print("BALANCE_AVAILABLE.value %i" % (jsonPayload["available"][0]["amount"]))
    	except HTTPError, e:
    		sys.exit()
    
    
    if __name__ == "__main__":
    	# are we doing config/autoconfig?
    	if(len(sys.argv) > 1):
    		if (sys.argv[1]=="config"):
    			print "graph_title Account Balance"
    			print "graph_vlabel Amount"
    			print "graph_category stripe"
    
    			# in green
    			print "BALANCE_PENDING.label Pending"
    			print "BALANCE_PENDING.colour 00cc00"
    			print "BALANCE_PENDING.draw LINE3"
    
    			print "BALANCE_AVAILABLE.label Available"
    			print "BALANCE_AVAILABLE.colour cc0000"
    			print "BALANCE_AVAILABLE.draw LINE3"
    
    			print "graph_args --base 1000 "
    			sys.exit()
    
    	get_stats()

    munin, 19 Февраля 2017

    Комментарии (2)
  7. Python / Говнокод #22388

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    #!/usr/bin/python
    
    # encoding utf8
    # head1 NAME
    #
    # wordpress - Number of wordpress sites currently active
    #
    # CONFIGURATION
    #
    # This script is used to generate data for the number of wordpress sites in the
    # wild
    #
    # APPLICABLE SYSTEMS
    #
    # Any
    #
    # CONFIGURATION
    #
    # None
    #
    
    import sys, os, string, urllib2
    from urllib2 import HTTPError
    import socket
    
    WORDPRESS_STATS_URL = "http://en.wordpress.com/stats/"
    
    def get_stats():
    	contents=""
    	try:
    		socket.setdefaulttimeout(10)
    		response = urllib2.urlopen(WORDPRESS_STATS_URL)
    		contents = response.read()
    	except HTTPError, e:
    		sys.exit()
    
    	flipper = ""
    
    	splitter = contents.split()
    	for line in splitter:
    		if not line:
    			break
    		if line.find("stats-flipper-number") != -1:
    			flipper += line
    
    	flipper_number = ""
    	for f in flipper:
    		if(f.isdigit()):
    			flipper_number += f
    
    	print("BLOGS.value " + flipper_number)
    
    if __name__ == "__main__":
    	# are we doing config/autoconfig?
    	if(len(sys.argv) > 1):
    		if (sys.argv[1]=="config"):
    			print "graph_title Number of Wordpress Blogs "
    			print "graph_vlabel Number Of Blogs"
    			print "graph_category wordpress"
    
    			# in green
    			print "BLOGS.label BLOGS"
    			print "BLOGS.colour 00cc00"
    			print "BLOGS.draw AREA"
    
    			print "graph_args --base 1000 "
    			sys.exit()
    
    	get_stats()

    munin, 19 Февраля 2017

    Комментарии (0)
  8. Python / Говнокод #22387

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    #!/usr/bin/python
    
    # encoding utf8
    # head1 NAME
    #
    # wordpress_plugin_ - Munin plugin to display wordpress download stats for plugins.
    #
    # CONFIGURATION
    #
    # This script is used to generate data for the number of downloads of plugins
    #
    # APPLICABLE SYSTEMS
    #
    # Any system that can connect to wordpress plugins
    #
    # CONFIGURATION
    #
    # This script is used to generate data for several graphs. To generate data for
    # one specific wordpress plugin instance, you need to create a symbolic link
    # with a name like wordpress_plugin_download_counter_<NAME> to this script.
    #
    # For example: to track the WP Super Cache number of downloads
    #
    #   The URL for it is http://wordpress.org/plugins/wp-super-cache/
    #   So you would use the following --------------> ^^^^^^^^^^^^^^
    #   wp-super-cache as the name
    #
    # i.e. 
    #
    #   cd /etc/munin/plugins
    #   ln -s /usr/share/munin/plugins/wordpress_plugin_download_counter_ wordpress_plugin_download_counter_wp-super-cache
    #   /etc/init.d/munin-node restart
    #
    
    import sys, os, string, urllib2
    from urllib2 import HTTPError
    import socket
    
    THIS_SCRIPT_NAME = "wordpress_plugin_download_counter_"
    THIS_TO_BE_FOUND = "UserDownloads"
    
    def get_stats(stat_url):
    	contents=""
    	try:
    		socket.setdefaulttimeout(10)
    		response = urllib2.urlopen(stat_url)
    		contents = response.read()
    	except HTTPError, e:
    		sys.exit()
    
    	start_index_of_download = string.find(contents, THIS_TO_BE_FOUND) + len(THIS_TO_BE_FOUND) + 1
    	end_index_of_download = string.find(contents, "\"", start_index_of_download)
    
    	print("DOWNLOADS.value " + (contents[start_index_of_download: end_index_of_download]))
    
    if __name__ == "__main__":
    	# figure out which one we are doing
    	full_caller_name = sys.argv[0]
    	index_of_wordpress = full_caller_name.find(THIS_SCRIPT_NAME)
    	caller = sys.argv[0][len(THIS_SCRIPT_NAME) + index_of_wordpress:]
    	caller_nice_name = caller.replace("_", " ")
    	caller_nice_name = caller_nice_name.replace("-", " ")
    
    	# are we doing config/autoconfig?
    	if(len(sys.argv) > 1):
    		if (sys.argv[1]=="config"):
    			print "graph_title Plugin Downloads for '" + caller_nice_name.title() + "'"
    			print "graph_vlabel Number Of Downloads"
    			print "graph_category wordpress"
    			print "graph_order DOWNLOADS"
    
    			# in green
    			print "DOWNLOADS.label Downloads"
    			print "DOWNLOADS.colour 00cc00"
    			print "DOWNLOADS.draw AREA"
    
    			print "graph_args --base 1000 -l 0 "
    			print "graph_scale no "
    			sys.exit()
    
    	# now that we know the caller, get the environment
    	stat_url = "http://wordpress.org/extend/plugins/" + caller_nice_name + "/"
    	if(None != stat_url):
    		get_stats(stat_url)

    munin, 19 Февраля 2017

    Комментарии (0)
  9. Perl / Говнокод #22386

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    #!/usr/bin/env perl
    
    # Parameters supported:
    #
    # config
    # autoconf
    #
    # Magic markers:
    #%# family=auto
    #%# capabilities=autoconf
    
    use strict;
    use warnings;
    use LWP;
    use JSON qw/decode_json/;
    
    =head1 NAME
    elasticsearch_open_files - A munin plugin that collects the number of open files in your elasticsearch instances
    =head1 APPLICABLE SYSTEMS
    Elasticsearch
    =head1 CONFIGURATION
    None
    =head1 BUGS
    None known so far. If you find any, let me know.
    =head1 AUTHOR
    Kentaro Yoshida - https://github.com/y-ken
    =cut
    
    my $host = exists $ENV{'host'} ? $ENV{'host'} : 'localhost';
    my $port = exists $ENV{'port'} ? $ENV{'port'} : 9200;
    
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    
    sub get_json_from_url {
        my $uri = shift;
        my $res = $ua->get($uri, 'Content-Type' => 'application/json' );
        Carp::confess($res->code . " for " . $uri) unless $res->is_success;
        my $data = do { local $@; eval { decode_json($res->content) } };
        die("Could not decode JSON from: " . $res->content) unless $data;
        return $data;
    }
    
    sub collect_max_file_descriptors {
        my $data = get_json_from_url("http://$host:$port/_nodes/_local/stats/process");
        foreach my $full_node_name (keys %{$data->{nodes}}) {
            return $data->{nodes}{$full_node_name}{process}{max_file_descriptors};
        }
    }
    
    sub collect_open_file_descriptors {
        my $data = get_json_from_url("http://$host:$port/_nodes/_local/stats/process");
        foreach my $full_node_name (keys %{$data->{nodes}}) {
            return $data->{nodes}{$full_node_name}{process}{open_file_descriptors};
        }
    }
    
    my %out = (
        max_file_descriptors => collect_max_file_descriptors,
        open_file_descriptors => collect_open_file_descriptors
    );
    
    if ($ARGV[0] and $ARGV[0] eq 'config') {
        print "graph_title Elasticsearch open files\n";
        print "graph_args --base 1000 -l 0\n";
        print "graph_vlabel number of open files\n";
        print "graph_category elasticsearch\n";
        print "open_file_descriptors.label open files\n";
        print "open_file_descriptors.type GAUGE\n";
        print "open_file_descriptors.info The number of currently open files.\n";
        print "max_file_descriptors.label max open files\n";
        print "max_file_descriptors.type GAUGE\n";
    }
    elsif (!$ARGV[0] || $ARGV[0] eq 'autoconf') {
        print "max_file_descriptors.value $out{max_file_descriptors}\n";
        print "open_file_descriptors.value $out{open_file_descriptors}\n";
    }
    
    exit(0);

    munin, 19 Февраля 2017

    Комментарии (0)
  10. Perl / Говнокод #22385

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    #!/usr/bin/env perl
    
    # Parameters supported:
    #
    # config
    # autoconf
    #
    # Magic markers:
    #%# family=auto
    #%# capabilities=autoconf
    
    use strict;
    use warnings;
    use LWP;
    use JSON qw/decode_json/;
    
    =head1 NAME
    elasticsearch_jvm_threads - A munin plugin that collects stats from the JVM of your elasticsearch instances
    =head1 APPLICABLE SYSTEMS
    Elasticsearch
    =head1 CONFIGURATION
    None
    =head1 BUGS
    None known so far. If you find any, let me know.
    =head1 AUTHOR
    Tomas Doran (t0m) - c<< <[email protected]> >>
    Kentaro Yoshida - https://github.com/y-ken
    =cut
    
    my $host = exists $ENV{'host'} ? $ENV{'host'} : 'localhost';
    my $port = exists $ENV{'port'} ? $ENV{'port'} : 9200;
    
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    
    sub get_json_from_url {
        my $uri = shift;
        my $res = $ua->get($uri, 'Content-Type' => 'application/json' );
        Carp::confess($res->code . " for " . $uri) unless $res->is_success;
        my $data = do { local $@; eval { decode_json($res->content) } };
        die("Could not decode JSON from: " . $res->content) unless $data;
        return $data;
    }
    
    my $data = get_json_from_url("http://$host:$port/_nodes/jvm");
    my $t_data = get_json_from_url("http://$host:$port/_nodes/stats/jvm");
    my %out = (count => 0, peak_count => 0);
    
    foreach my $full_node_name (keys %{$data->{nodes}}) {
        next unless $t_data->{nodes}{$full_node_name};
        foreach my $name (keys %{ $t_data->{nodes}{$full_node_name}{jvm}{threads} }) {
            $out{$name} += $t_data->{nodes}{$full_node_name}{jvm}{threads}{$name};
        }
    }
    if ($ARGV[0] and $ARGV[0] eq 'config') {
        print "graph_title Elasticsearch JVM threads\n";
        print "graph_category elasticsearch\n";
        print "graph_scale no\n";
    
        foreach my $name (keys %out) {
            print "$name.label $name\n"."$name.type GAUGE\n";
        }
    }
    elsif (!$ARGV[0] || $ARGV[0] eq 'autoconf') {
        foreach my $name (keys %out) {
            print "$name.value " . $out{$name} . "\n";
        }
    }
    
    exit(0);

    munin, 19 Февраля 2017

    Комментарии (0)
  11. Perl / Говнокод #22384

    −98

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    #!/usr/bin/env perl
    
    # Parameters supported:
    #
    # config
    # autoconf
    #
    # Magic markers:
    #%# family=auto
    #%# capabilities=autoconf
    
    use strict;
    use warnings;
    use LWP;
    use JSON qw/decode_json/;
    
    =head1 NAME
    elasticsearch_jvm_pools_size - A munin plugin that collects jvm pools size stats of your elasticsearch instances
    =head1 APPLICABLE SYSTEMS
    Elasticsearch
    =head1 CONFIGURATION
    None
    =head1 BUGS
    None known so far. If you find any, let me know.
    =head1 AUTHOR
    Timothy Messier (t0m) - c<< <[email protected]> >>
    Kentaro Yoshida - https://github.com/y-ken
    =cut
    
    my $host = exists $ENV{'host'} ? $ENV{'host'} : 'localhost';
    my $port = exists $ENV{'port'} ? $ENV{'port'} : 9200;
    
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    
    sub get_json_from_url {
        my $uri = shift;
        my $res = $ua->get($uri, 'Content-Type' => 'application/json' );
        Carp::confess($res->code . " for " . $uri) unless $res->is_success;
        my $data = do { local $@; eval { decode_json($res->content) } };
        die("Could not decode JSON from: " . $res->content) unless $data;
        return $data;
    }
    
    my $data = get_json_from_url("http://$host:$port/_nodes/jvm");
    my $t_data = get_json_from_url("http://$host:$port/_nodes/stats/jvm");
    my %out = (young_used => 0, young_peak => 0, survivor_used => 0, survivor_peak => 0, old_used => 0, old_peak => 0);
    
    foreach my $full_node_name (keys %{$data->{nodes}}) {
        next unless $t_data->{nodes}{$full_node_name};
        if (defined($t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{young})) {
            $out{young_used} += $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{young}{used_in_bytes};
            $out{young_peak} += $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{young}{peak_used_in_bytes};
        }
        if (defined($t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{survivor})) {
            $out{survivor_used} += $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{survivor}{used_in_bytes};
            $out{survivor_peak} += $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{survivor}{peak_used_in_bytes};
        }
        if (defined($t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{old})) {
            $out{old_used} += $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{old}{used_in_bytes};
            $out{old_peak} += $t_data->{nodes}{$full_node_name}{jvm}{mem}{pools}{old}{peak_used_in_bytes};
        }
    }
    if ($ARGV[0] and $ARGV[0] eq 'config') {
        print "graph_title Elasticsearch jvm pools size\n";
        print "graph_category elasticsearch\n";
        print "graph_vlabel bytes\n";
    
        foreach my $name (keys %out) {
            print "$name.label $name\n"."$name.type GAUGE\n";
        }
    }
    elsif (!$ARGV[0] || $ARGV[0] eq 'autoconf') {
        foreach my $name (keys %out) {
            print "$name.value " . $out{$name} . "\n";
        }
    }
    
    exit(0);

    munin, 19 Февраля 2017

    Комментарии (0)