Add git hash to metrics.
This commit is contained in:
parent
802dc220ac
commit
891c51a278
9
prom.py
9
prom.py
|
@ -15,11 +15,18 @@ import os # for ENV arguments
|
||||||
|
|
||||||
import scraperMain, prom_servers
|
import scraperMain, prom_servers
|
||||||
|
|
||||||
|
### ENV Vars ###
|
||||||
hostname = str(os.environ['SSH_HOSTNAME'])
|
hostname = str(os.environ['SSH_HOSTNAME'])
|
||||||
encname = str(os.environ['ENC_NAME'])
|
encname = str(os.environ['ENC_NAME'])
|
||||||
sshkeypath = os.getenv('SSH_KEYPATH','/bss/.ssh/id_rsa')
|
sshkeypath = os.getenv('SSH_KEYPATH','/bss/.ssh/id_rsa')
|
||||||
PREFIX = os.getenv('PREFIX','bladetest_')
|
PREFIX = os.getenv('PREFIX','bladetest_')
|
||||||
|
|
||||||
|
### Get git hash ###
|
||||||
|
with open('.git/HEAD', 'r') as file:
|
||||||
|
current_branch = file.read().replace('\n', '').replace('ref: ', '')
|
||||||
|
with open('.git/' + current_branch, 'r') as file:
|
||||||
|
git_hash = file.read().replace('\n', '')
|
||||||
|
|
||||||
### FLASK ###
|
### FLASK ###
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@app.route('/metrics', methods=['GET'])
|
@app.route('/metrics', methods=['GET'])
|
||||||
|
@ -29,6 +36,6 @@ def parse_request(): # If somebody accesses us
|
||||||
#with open("prom_servers.out", "a") as f: # DO NOT UNCOMMENT IN PROD
|
#with open("prom_servers.out", "a") as f: # DO NOT UNCOMMENT IN PROD
|
||||||
# print(data, file=f)
|
# print(data, file=f)
|
||||||
|
|
||||||
response_list = prom_servers.prom_servers(PREFIX, data[0], data[1]) # Convert our python lists to prometheus format whatever.
|
response_list = prom_servers.prom_servers(git_hash, PREFIX, data[0], data[1]) # Convert our python lists to prometheus format whatever.
|
||||||
response = '\n'.join(response_list) # Oh you still don't want a list? Fine, newlines!
|
response = '\n'.join(response_list) # Oh you still don't want a list? Fine, newlines!
|
||||||
return Response(response + '\n', mimetype='text/plain') # The pizza is already cold.
|
return Response(response + '\n', mimetype='text/plain') # The pizza is already cold.
|
||||||
|
|
|
@ -21,8 +21,10 @@ def prom_header(desc, item, promtype):
|
||||||
|
|
||||||
return(item)
|
return(item)
|
||||||
|
|
||||||
def prom_servers(PREFIX, baysInUseCount, servers):
|
def prom_servers(git_hash, PREFIX, baysInUseCount, servers):
|
||||||
# Input validation
|
# Input validation
|
||||||
|
if not type(git_hash) is str:
|
||||||
|
raise TypeError("git_hash: desc must be a string, '" + str(git_hash) + "' is not.")
|
||||||
if not type(baysInUseCount) is int:
|
if not type(baysInUseCount) is int:
|
||||||
raise TypeError("parseServers: baysInUseCount must be an integer, '" + str(baysInUseCount) + "' is not.")
|
raise TypeError("parseServers: baysInUseCount must be an integer, '" + str(baysInUseCount) + "' is not.")
|
||||||
if not type(servers) is list:
|
if not type(servers) is list:
|
||||||
|
@ -99,6 +101,8 @@ def prom_servers(PREFIX, baysInUseCount, servers):
|
||||||
prom_disp_servers = prom_disp_servers + prom_header('Number of blades with bad health.', errorsHealth_prom, 'counter')
|
prom_disp_servers = prom_disp_servers + prom_header('Number of blades with bad health.', errorsHealth_prom, 'counter')
|
||||||
errors_prom = [PREFIX + 'errors_total{} ' + str(float(errors))]
|
errors_prom = [PREFIX + 'errors_total{} ' + str(float(errors))]
|
||||||
prom_disp_servers = prom_disp_servers + prom_header('Number of errors or warnings encountered during the gathering of data see logs of promServers in blade-ssh-scraper', errors_prom, 'counter')
|
prom_disp_servers = prom_disp_servers + prom_header('Number of errors or warnings encountered during the gathering of data see logs of promServers in blade-ssh-scraper', errors_prom, 'counter')
|
||||||
|
prom_git_hash = [PREFIX + 'info{git_hash="' + git_hash + '"} 1.0']
|
||||||
|
prom_disp_servers = prom_disp_servers + prom_header('Git hash of HEAD on current branch, version', prom_git_hash, 'gauge')
|
||||||
|
|
||||||
#prom_disp_servers = '\n'.join(prom_disp_servers)
|
#prom_disp_servers = '\n'.join(prom_disp_servers)
|
||||||
#breakpoint()
|
#breakpoint()
|
||||||
|
@ -106,10 +110,11 @@ def prom_servers(PREFIX, baysInUseCount, servers):
|
||||||
return(prom_disp_servers)
|
return(prom_disp_servers)
|
||||||
|
|
||||||
# Test data
|
# Test data
|
||||||
|
#git_hash = 'fakegithash'
|
||||||
#PREFIX = 'bladetest_'
|
#PREFIX = 'bladetest_'
|
||||||
#baysInUseCount = 11
|
#baysInUseCount = 11
|
||||||
# 0~ 1~ 2~ 3~ 4~ 5~ 6~ 7~ 8~
|
# 0~ 1~ 2~ 3~ 4~ 5~ 6~ 7~ 8~
|
||||||
# [BayNumber "Server Name", "Serial Number", "Status", "Power", "UID Partner", presentPowerDirectDC, relativeUsageAC, "encname"]
|
# [BayNumber "Server Name", "Serial Number", "Status", "Power", "UID Partner", presentPowerDirectDC, relativeUsageAC, "encname"]
|
||||||
#servers = [[1, 'foo-lab-1', '', 'OK', 'On', 'Off', 142, 222, "k-space-blade-02"], [2, 'foo-lab-2', 'CZ302243P9', 'OK', 'On', 'Off', 87, 136, "k-space-blade-02"], [3, 'foo-lab-3', 'CZJI441OKP', 'Failed', 'On', 'Off', 127, 198, "k-space-blade-02"], [4, 'kspve1', 'CZJ18450FK', 'OK', 'On', 'Off', 86, 134, "k-space-blade-02"], [5, 'kspve2-2', '', 'OK', 'On', 'Off', 71, 111, "k-space-blade-02"], [6, 'kspve3', '', 'OK', 'On', 'Off', 80, 125, "k-space-blade-02"], [7, 'foo-blade', '', 'OK', 'On', 'Off', 81, 127, "k-space-blade-02"], [8, 'Bar-01', 'CZ241274CC', 'OK', 'On', 'Off', 126, 197, "k-space-blade-02"], [9, 'baz-sar', 'CZ3217FNYE', 'OK', 'On', 'Off', 129, 202, "k-space-blade-02"], [10, 'baz-sar2', 'CZ3217FFSS', 'OK', 'On', 'Off', 97, 152, "k-space-blade-02"], [12, 'bee-bar', '', 'OK', 'On', 'Off', 86, 134, "k-space-blade-02"]]
|
#servers = [[1, 'foo-lab-1', '', 'OK', 'On', 'Off', 142, 222, "k-space-blade-02"], [2, 'foo-lab-2', 'CZ302243P9', 'OK', 'On', 'Off', 87, 136, "k-space-blade-02"], [3, 'foo-lab-3', 'CZJI441OKP', 'Failed', 'On', 'Off', 127, 198, "k-space-blade-02"], [4, 'kspve1', 'CZJ18450FK', 'OK', 'On', 'Off', 86, 134, "k-space-blade-02"], [5, 'kspve2-2', '', 'OK', 'On', 'Off', 71, 111, "k-space-blade-02"], [6, 'kspve3', '', 'OK', 'On', 'Off', 80, 125, "k-space-blade-02"], [7, 'foo-blade', '', 'OK', 'On', 'Off', 81, 127, "k-space-blade-02"], [8, 'Bar-01', 'CZ241274CC', 'OK', 'On', 'Off', 126, 197, "k-space-blade-02"], [9, 'baz-sar', 'CZ3217FNYE', 'OK', 'On', 'Off', 129, 202, "k-space-blade-02"], [10, 'baz-sar2', 'CZ3217FFSS', 'OK', 'On', 'Off', 97, 152, "k-space-blade-02"], [12, 'bee-bar', '', 'OK', 'On', 'Off', 86, 134, "k-space-blade-02"]]
|
||||||
|
|
||||||
#print(prom_servers(PREFIX, baysInUseCount, servers))
|
#print(prom_servers(git_hash, PREFIX, baysInUseCount, servers))
|
||||||
|
|
Loading…
Reference in New Issue