设为首页 收藏本站
查看: 973|回复: 0

[经验分享] 用Saltstack的modules和grains实现实时监控平台

[复制链接]

尚未签到

发表于 2018-8-1 11:33:49 | 显示全部楼层 |阅读模式
#!/usr/bin/env python  
#coding=utf-8
  
#xiaorui.cc
  
from flask import Flask,url_for,request,render_template,redirect,abort,escape,session
  
from werkzeug import secure_filename
  
import os
  
print __name__
  
app = Flask(__name__)
  
app.secret_key = 'hello'
  
@app.route('/')
  
def index():
  p=os.popen('salt \'*\' grains.item psnum netnum').read()
  p=os.popen('salt \* cmd.run \'netstat -an|wc -l\'').read()
  return '''
  
<!DOCTYPE html>
  
<!-- saved from url=(0053)http://www.bootcss.com/examples/marketing-narrow.html -->
  
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta charset="utf-8">
  <title>xiaorui.cc</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="">
  <meta name="author" content="">
  <!-- Le styles -->

  <link href="http://cdnjs.bootcss.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap.min.css">  <style type="text/css">
  body {
  padding-top: 20px;
  padding-bottom: 40px;
  }
  /* Custom container */
  .container-narrow {
  margin: 0 auto;
  max-width: 700px;
  }
  .container-narrow > hr {
  margin: 30px 0;
  }
  /* Main marketing message and sign up button */
  .jumbotron {
  margin: 60px 0;
  text-align: center;
  }
  .jumbotron h1 {
  font-size: 72px;
  line-height: 1;
  }
  .jumbotron .btn {
  font-size: 21px;
  padding: 14px 24px;
  }
  /* Supporting marketing content */
  .marketing {
  margin: 60px 0;
  }
  .marketing p + h4 {
  margin-top: 28px;
  }
  </style>

  <link href="http://cdnjs.bootcss.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css">  <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
  <!--[if lt IE 9]>
  <script src="//cdnjs.bootcss.com/ajax/libs/html5shiv/3.6.2/html5shiv.js"></script>
  <![endif]-->
  <!-- Fav and touch icons -->

  <link>
  <link>
  <link>
  <link>
  <link>  <script>window["_GOOG_TRANS_EXT_VER"] = "1";</script></head>
  <body>
  <div>
  <div>
  <ul>
  <li><a href="http://www.bootcss.com/examples/marketing-narrow.html#">Home</a></li>
  <li><a href="http://www.bootcss.com/examples/marketing-narrow.html#">命令推送</a></li>
  <li><a href="http://www.bootcss.com/examples/marketing-narrow.html#">图标监控</a></li>
  </ul>
  <h3>实时监控</h3>
  </div>
  <hr>
  <div>
  <pre>%s</pre>
  <a href="http://10.10.10.66:8888">刷新</a>
  </div>
  <hr>
  <hr>
  <div>
  <h4>by xiaorui.cc</h4>
  </div>
  </div> <!-- /container -->
  <!-- Le javascript
  ================================================== -->
  <!-- Placed at the end of the document so the pages load faster -->
  
</body></html>
  
'''%p
  
@app.route('/charts.html')
  
def show_username():
  p=[1,2,3,4,5,6,7,8,9,1,2,3]
  return '''
  
<!DOCTYPE html>
  
<!-- saved from url=(0053)http://www.bootcss.com/examples/marketing-narrow.html -->
  
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta charset="utf-8">
  <title>xiaorui.cc</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="">
  <meta name="author" content="">

  <link href="http://67.xiaorui.cc/bootstrap.min.css">  <script type="text/javascript"  src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
  <script  type="text/javascript" src="http://67.xiaorui.cc/highcharts.js"></script>
  <script  type="text/javascript" src="http://67.xiaorui.cc/exporting.js"></script>
  <style type="text/css">
  body {
  padding-top: 20px;
  padding-bottom: 40px;
  }
  /* Custom container */
  .container-narrow {
  margin: 0 auto;
  max-width: 700px;
  }
  .container-narrow > hr {
  margin: 30px 0;
  }
  /* Main marketing message and sign up button */
  .jumbotron {
  margin: 60px 0;
  text-align: center;
  }
  .jumbotron h1 {
  font-size: 72px;
  line-height: 1;
  }
  .jumbotron .btn {
  font-size: 21px;
  padding: 14px 24px;
  }
  /* Supporting marketing content */
  .marketing {
  margin: 60px 0;
  }
  .marketing p + h4 {
  margin-top: 28px;
  }
  </style>
  
<script type="text/javascript">
  var chart;
  $(document).ready(function() {
  chart = new Highcharts.Chart({
  chart: {
  renderTo: 'container',
  defaultSeriesType: 'line',
  marginRight: 130,
  marginBottom: 25
  },
  title: {
  text: 'netstat 监控',
  x: -20 //center
  },
  subtitle: {
  text: '让我们看看连接书哈',
  x: -20
  },
  xAxis: {
  categories: ['1', '2', '3', '4', '5', '6',
  '7', '8', '9', '10', '11', '12']
  },
  yAxis: {
  title: {
  text: '连接数'
  },
  plotLines: [{
  value: 0,
  width: 1,
  color: '#808080'
  }]
  },
  tooltip: {
  formatter: function() {
  return '<b>'+ this.series.name +'</b><br/>'+
  this.x +': '+ this.y +'°C';
  },
  },
  legend: {
  layout: 'vertical',
  align: 'right',
  verticalAlign: 'top',
  x: -10,
  y: 100,
  borderWidth: 0
  },
  series: [{
  name: '66.ruifengyun.cc',
  data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
  }, {
  name: '67.ruifengyun.cc',
  data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
  }, {
  name: 'ceshi',
  data: %s
  }]
  });
  });
  </script>
  <!-- Fav and touch icons -->

  <link>
  <link>
  <link>
  <link>
  <link>  <script>window["_GOOG_TRANS_EXT_VER"] = "1";</script></head>
  <body>
  <div>
  <div>
  <ul>
  <li><a href="http://66.xiaorui.cc:8888">Home</a></li>
  <li><a href="http://66.xiaorui.cc:8888/pushcmd">命令推送</a></li>
  <li><a href="http://66.xiaorui.cc:8888/charts.html#">图表监控</a></li>
  </ul>
  <h3>图表监控</h3>
  </div>
  <hr>
  <div>
  <div></div>
  <a href="http://10.10.10.66:8888">刷新</a>
  </div>
  <hr>
  <hr>
  <div>
  <h4>by xiaorui.cc</h4>
  </div>
  </div> <!-- /container -->
  <!-- Le javascript
  ================================================== -->
  <!-- Placed at the end of the document so the pages load faster -->
  
</body></html>
  
'''%p
  
@app.route('/post/<int:post_id>')
  
def show_post(post_id):
  return 'post_id:%d' % post_id
  
@app.route('/index/')
  
def test_session():
  if 'username' in session:
  return 'logged in as %s' % escape(session['username'])
  return redirect(url_for('login'))
  
@app.route('/login/',methods=['GET','POST'])
  
def login():
  if request.method == 'POST':
  session['username'] = request.form['username']
  return redirect(url_for('test_session'))
  else:
  return
  
'''
  
<form action="/login/" method="post">
  
<input type=text name=username>
  
<input type=submit value=login>
  
</form>
  
'''
  
if __name__ == "__main__":
  app.run(host="10.10.10.66",port=8888,debug=True)

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-544707-1-1.html 上篇帖子: 用Saltstack的returners实现批量监控和数据存储 下篇帖子: 通过python和websocket构建实时通信系统[扩展saltstack监控]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表