python抓取jenkins slave总数online数offline数写道mysql并展现
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python抓取jenkins slave总数online数offline数写道mysql并展现相关的知识,希望对你有一定的参考价值。
python抓取jenkins slave总数、online数、offline数写道mysql并展现到grafana:mysql -u root -p‘xxxx‘
create database jenkins default character set utf8;
create table slaves(time datetime,online float,offline float,total float);
grant all on ming.* to [email protected]‘10.0.0.2‘ identified by ‘xxxx‘;
exit
apt-get install python-jenkins
apt-get install python-pymysql
vi aa.py
#!/usr/bin/python
#coding:utf-8
import jenkins
import collections
import pymysql
import time
server = jenkins.Jenkins(‘http://10.0.0.2:8080/jenkins‘, username="ming", password="xxxxx")
nodes = server.get_nodes()
To = len(nodes)
on = collections.Counter(str(nodes))[‘F‘]
off = collections.Counter(str(nodes))[‘T‘]
ti = time.localtime()
conn = pymysql.connect(host="10.0.0.3",port=3306,database=‘jenkins‘,user=‘ming‘,password=‘xxxxx‘,charset=‘utf8‘)
cur = conn.cursor()
cur.execute("insert into slaves (time,online,offline,total) values (%s,%s,%s,%s)", [ti,on,off,To])
conn.commit()
conn.close();
print (‘Data has been inserted‘)
:wq
python aa.py
grafa:
select UNIX_TIMESTAMP(time) as time_sec, total-1 as total from slaves group by time_sec;
select UNIX_TIMESTAMP(time) as time_sec, online-1 as online from slaves group by time_sec;
select UNIX_TIMESTAMP(time) as time_sec, offline as offline from slaves group by time_sec;
以上是关于python抓取jenkins slave总数online数offline数写道mysql并展现的主要内容,如果未能解决你的问题,请参考以下文章
Jenkins on Kubernetes中的Pipeline语法以及自定义Slave的使用方式
jenkins主从从服务器发布脚本执行成功但总提示失败 FATAL: Remote call on XXXX failed
jenkins 在windows上配置master 和 agent(slave)
[Python]通过python-jenkins操作jenkins slave启动job | 通过python-jenkins实现ios自动化打包接口