class FormK8sIngress(Form): _, contexts, _ = tools.k8s_conf() contexts = SelectField(choices=[(context, context) for context in contexts], id='contexts') service_name = SelectField(choices=[], id='service_name') service_port = StringField(validators=[DataRequired()],id='service_port') domains = TextAreaField(validators=[DataRequired()],id='domains') submit = SubmitField('提交', id='btn1')
class FormK8sDeploy(Form): try: db_project = db_op.project_list _, contexts, _ = tools.k8s_conf() contexts = SelectField(choices=[(context, context) for context in contexts], id='contexts') projects = StringField('projects', validators=[DataRequired()],id='projects') object = StringField('object', validators=[DataRequired()],id='object') version = StringField('version', validators=[DataRequired()], id='version') container_port = StringField('container_port',id='container_port') ingress_port = IntegerField('ingress_port', id='ingress_port') replicas = IntegerField('replicas', validators=[DataRequired()],id='replicas') dm_name = StringField('dm_name', validators=[DataRequired()],id='dm_name') docker_args = TextAreaField( id='docker_args') run_args = TextAreaField(validators=[DataRequired()], id='run_args') healthcheck = StringField('healthcheck',id='healthcheck') label_project = StringField('label_project', id='label_project') label_deploy = StringField('label_deploy', id='label_deploy') mount_path = StringField('mount_path', id='mount_path') mount_name = StringField('mount_name', id='mount_name') domain = StringField('domain', id='domain') sidecar = StringField('sidecar', id='sidecar') request_cpu = IntegerField('request_cpu',id='request_cpu') request_mem = IntegerField('request_mem',id='request_mem') limit_cpu = IntegerField('limit_cpu',id='limit_cpu') limit_mem = IntegerField('limit_mem',id='limit_mem') submit = SubmitField('提交', id='btn1') except Exception as e: logging.error(e)
class FormK8sHpa(Form): try: _, contexts, _ = tools.k8s_conf() contexts = SelectField(choices=[(context, context) for context in contexts], id='contexts') deployment = SelectField(choices=[],id='deployment') max_replica = IntegerField(validators=[DataRequired()], id='max_replica') min_replica = IntegerField(validators=[DataRequired()],id='min_replica') cpu_value = IntegerField(validators=[DataRequired()],id='cpu_value') submit = SubmitField('提交', id='btn1') except Exception as e: logging.error(e)
class FormK8sUpdate(Form): try: _, contexts, _ = tools.k8s_conf() choices = [(context, context) for context in contexts] contexts = SelectField(choices=choices, id='contexts') deployment = SelectField(choices=[], id='deployment') version = SelectField(choices=[], id='version') rollback = StringField('rollback', id='rollback') submit = SubmitField('提交', id='btn1') except Exception as e: logging.error(e) finally: db_op.DB.session.remove()
class FormK8sDeploy(Form): try: db_project = db_op.project_list _, contexts, _ = tools.k8s_conf() contexts = SelectField(choices=[(context, context) for context in contexts], id='contexts') projects = db_project.query.with_entities(distinct( db_project.project)).all() projects = SelectField(choices=[(project[0], project[0]) for project in projects], id='projects') object = StringField('object', validators=[DataRequired()], id='object') version = StringField('version', validators=[DataRequired()], id='version') container_port = StringField('container_port', validators=[DataRequired()], id='container_port') ingress_port = IntegerField('ingress_port', id='ingress_port') replicas = IntegerField('replicas', validators=[DataRequired()], id='replicas') dm_name = StringField('dm_name', validators=[DataRequired()], id='dm_name') run_args = TextAreaField(validators=[DataRequired()], id='run_args') healthcheck = StringField('healthcheck', id='healthcheck') mount_path1 = StringField('mount_path1', id='mount_path1') mount_name1 = StringField('mount_name1', id='mount_name1') mount_path2 = StringField('mount_path2', id='mount_path2') mount_name2 = StringField('mount_name2', id='mount_name2') domain = StringField('domain', id='domain') sidecar = StringField('sidecar', id='sidecar') request_cpu = IntegerField('request_cpu', id='request_cpu') request_mem = IntegerField('request_mem', id='request_mem') limit_cpu = IntegerField('limit_cpu', id='limit_cpu') limit_mem = IntegerField('limit_mem', id='limit_mem') submit = SubmitField('提交', id='btn1') except Exception as e: logging.error(e) finally: db_op.DB.session.remove()
class FormK8sUpdate(Form): try: _, contexts, _ = tools.k8s_conf() choices = [(context, context) for context in contexts] choices.insert(0, ('--all-cluster--', '--all-cluster--')) contexts = SelectField(choices=choices, id='contexts') db_k8s_deploy = db_op.k8s_deploy values = db_k8s_deploy.query.with_entities( distinct(db_k8s_deploy.deployment)).all() deployment = SelectField(choices=[(val[0], val[0]) for val in values], id='deployment') version = SelectField(choices=[], id='version') replicas = IntegerField('replicas', id='replicas') submit = SubmitField('提交', id='btn1') except Exception as e: logging.error(e) finally: db_op.DB.session.remove()
class FormK8sHpa(Form): try: _, contexts, _ = tools.k8s_conf() contexts = SelectField(choices=[(context, context) for context in contexts], id='contexts') db_k8s_deploy = db_op.k8s_deploy values = db_k8s_deploy.query.with_entities( distinct(db_k8s_deploy.deployment)).all() deployment = SelectField(choices=[(val[0], val[0]) for val in values], id='deployment') max_replica = IntegerField(validators=[DataRequired()], id='max_replica') min_replica = IntegerField(validators=[DataRequired()], id='min_replica') cpu_value = IntegerField(validators=[DataRequired()], id='cpu_value') submit = SubmitField('提交', id='btn1') except Exception as e: logging.error(e) finally: db_op.DB.session.remove()
class FormK8sContexts(Form): _, contexts, _ = tools.k8s_conf() select = SelectField(choices=[(context, context) for context in contexts], id='contexts')
redis_host = app.config.get('REDIS_HOST') redis_port = app.config.get('REDIS_PORT') redis_password = app.config.get('REDIS_PASSWORD') docker_user = app.config.get('USER') docker_password = app.config.get('PASSWORD') docker_base_url = app.config.get('BASE_URL') dockerfile_path = app.config.get('DOCKERFILE_PATH') ops_token = app.config.get('OPS_TOKEN') oss_id = app.config.get('OSS_ID') oss_key = app.config.get('OSS_KEY') oss_url = app.config.get('OSS_URL') Redis = redis.StrictRedis(host=redis_host, port=redis_port, decode_responses=True) logging = loging.Error() config, contexts, config_file = tools.k8s_conf() flow_number = time.strftime('%Y%m%d%H%M%S', time.localtime()) Files = tools.get_k8s_packages() #流水日志记录 def _flow_log(Msg): try: logpath = "/opt/k8s/flow_logs" tm = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) if not os.path.exists(logpath): os.system("/bin/mkdir -p %s" % logpath) flow_log_ptah = "%s/%s.log" % (logpath, flow_number) with open(flow_log_ptah, 'a+') as f: f.write("%s %s\n" % (tm, str(Msg))) except Exception as e:
def alarm_show(): try: whitelist = [] Key = "op_alarm_load_whitelist" if RC_CLUSTER.exists(Key): whitelist = RC_CLUSTER.smembers(Key) td = time.strftime("%Y-%m-%d", time.localtime()) BUSIS = [] #获取每日工单数量 try: db_work_order = db_op.work_order vals = db_work_order.query.with_entities( db_work_order.date, func.count(db_work_order.date)).group_by( db_work_order.date).all() work_bar = EffectScatter("运维工单每日实时统计", width='107%', height=250, title_pos='center', title_text_size=12) bar_vals = [val[0].split('-')[-1] for val in vals[-10:]] bar_counts = [int(val[1]) for val in vals[-10:]] work_bar.add("", bar_vals, bar_counts, is_label_show=True, is_toolbox_show=False, legend_orient='vertical', legend_pos='right', xaxis_interval=0, xaxis_type="category", label_color=['green']) except Exception as e: logging.error(e) #服务器预警信息 try: z_infos = defaultdict() dict_load = None dict_openfile = None if RC_CLUSTER.exists('op_zabbix_server_load_top'): dict_load = eval(RC_CLUSTER.get('op_zabbix_server_load_top')) if RC_CLUSTER.exists('op_zabbix_server_openfile_top'): dict_openfile = eval( RC_CLUSTER.get('op_zabbix_server_openfile_top')) if dict_load: dict_load = [load for load in dict_load if load[-1] > 100] z_infos['cpu_load'] = dict_load if dict_openfile: dict_openfile = [ openfile for openfile in dict_openfile if openfile[-1] > 300000 ] z_infos['openfile'] = dict_openfile except Exception as e: logging.error(e) # 容器平台资源统计 config, contexts, config_file = tools.k8s_conf() _, active_contexts = config.list_kube_config_contexts(config_file) v1 = client.CoreV1Api() ret = v1.list_node(watch=False) nodes = len(ret.items) ret = v1.list_pod_for_all_namespaces() pods = len(ret.items) ret = v1.list_service_for_all_namespaces() services = len(ret.items) v1 = client.AppsV1Api() ret = v1.list_deployment_for_all_namespaces() deployments = len(ret.items) ret = v1.list_daemon_set_for_all_namespaces() daemonsets = len(ret.items) k8s_bar = EffectScatter("容器平台资源实时统计", width='107%', height=250, title_pos='center', title_text_size=12) bar_counts = [nodes, pods, deployments, daemonsets, services] bar_vals = ['nodes', 'pods', 'deployments', 'daemonsets', 'services'] k8s_bar.add("", bar_vals, bar_counts, is_label_show=True, is_toolbox_show=False, legend_orient='vertical', legend_pos='right', xaxis_interval=0, xaxis_type="category", label_color=['blue']) return render_template('alarm_show.html', z_infos=z_infos, BUSIS=BUSIS, whitelist=whitelist, work_bar=work_bar, k8s_bar=k8s_bar) except Exception as e: logging.error(e) return redirect(url_for('error'))