python抓取jenkins slave总数、online数、offline数写道mysql并展现,,python抓取je
python抓取jenkins slave总数、online数、offline数写道mysql并展现,,python抓取je
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 aa@‘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并展现
相关内容
- 关于基于python27使用 from pylab import * 报错问题,,### 这里
- Python中print函数中中逗号和加号的区别,,先看看print中
- Python爬取js动态添加的内容,,爬虫从 HTML 数
- Python列表:元素的修改、添加、删除和排序,,本文参考
- 模拟登录知乎selenium在python中,,from selen
- Python保留字与标识符Python保留字有哪些,,保留字是Py
- yum -y install python-devel,,yum -y ins
- Python3 爬虫爬取中国图书网(淘书团) 记录,,本人为一名
- python2.7导入mysqldb,,my噶地~~学习了一
- 升级centos6自带的python2.6版本至python2.75,,背景:
评论关闭