分享更有价值
被信任是一种快乐

Kubernetes节点之间的ping监控怎么实现

文章页正文上

小编给大家分享一下Kubernetes节点之间的ping监控怎么实现,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!脚本和配置我们解决方案的主要组件是一个脚本,该脚本监视每个节点的.免费云主机、域名status.addresses值。如果某个节点的该值已更改(例如添加了新节点),则我们的脚本使用Helm value方式将节点列表以ConfigMap的形式传递给Helm图表:下面是Python脚本:#!/usr/bin/envpython3importsubprocessimportprometheus_clientimportreimportstatisticsimportosimportjsonimportglobimportbetter_exchookimportdatetimebetter_exchook.install()FPING_CMDLINE=”/usr/sbin/fping-p1000-C30-B1-q-r1″.split(“”)FPING_REGEX=re.compile(r”^(S*)s*:(.*)$”,re.MULTILINE)CONFIG_PATH=”/config/targets.json”registry=prometheus_client.CollectorRegistry()prometheus_exceptions_counter=prometheus_client.Counter(‘kube_node_ping_exceptions’,’Totalnumberofexceptions’,[],registry=registry)prom_metrics_cluster={“sent”:prometheus_client.Counter(‘kube_node_ping_packets_sent_total’,’ICMPpacketssent’,[‘destination_node’,’destination_node_ip_address’],registry=registry),”received”:prometheus_client.Counter(‘kube_node_ping_packets_received_total’,’ICMPpacketsreceived’,[‘destination_node’,’destination_node_ip_address’],registry=registry),”rtt”:prometheus_client.Counter(‘kube_node_ping_rtt_milliseconds_total’,’round-triptime’,[‘destination_node’,’destination_node_ip_address’],registry=registry),”min”:prometheus_client.Gauge(‘kube_node_ping_rtt_min’,’minimumround-triptime’,[‘destination_node’,’destination_node_ip_address’],registry=registry),”max”:prometheus_client.Gauge(‘kube_node_ping_rtt_max’,’maximumround-triptime’,[‘destination_node’,’destination_node_ip_address’],registry=registry),”mdev”:prometheus_client.Gauge(‘kube_node_ping_rtt_mdev’,’meandeviationofround-triptimes’,[‘destination_node’,’destination_node_ip_address’],registry=registry)}prom_metrics_external={“sent”:prometheus_client.Counter(‘external_ping_packets_sent_total’,’ICMPpacketssent’,[‘destination_name’,’destination_host’],registry=registry),”received”:prometheus_client.Counter(‘external_ping_packets_received_total’,’ICMPpacketsreceived’,[‘destination_name’,’destination_host’],registry=registry),”rtt”:prometheus_client.Counter(‘external_ping_rtt_milliseconds_total’,’round-triptime’,[‘destination_name’,’destination_host’],registry=registry),”min”:prometheus_client.Gauge(‘external_ping_rtt_min’,’minimumround-triptime’,[‘destination_name’,’destination_host’],registry=registry),”max”:prometheus_client.Gauge(‘external_ping_rtt_max’,’maximumround-triptime’,[‘destination_name’,’destination_host’],registry=registry),”mdev”:prometheus_client.Gauge(‘external_ping_rtt_mdev’,’meandeviationofround-triptimes’,[‘destination_name’,’destination_host’],registry=registry)}defvalidate_envs():envs={“MY_NODE_NAME”:os.getenv(“MY_NODE_NAME”),”PROMETHEUS_TEXTFILE_DIR”:os.getenv(“PROMETHEUS_TEXTFILE_DIR”),”PROMETHEUS_TEXTFILE_PREFIX”:os.getenv(“PROMETHEUS_TEXTFILE_PREFIX”)}fork,vinenvs.items():ifnotv:raiseValueError(“{}environmentvariableisempty”.format(k))returnenvs@prometheus_exceptions_counter.count_exceptions()defcompute_results(results):computed={}matches=FPING_REGEX.finditer(results)formatchinmatches:host=match.group(1)ping_results=match.group(2)if”duplicate”inping_results:continuesplitted=ping_results.split(“”)iflen(splitted)!=30:raiseValueError(“pingreturnedwrongnumberofresults:”{}””.format(splitted))positive_results=[float(x)forxinsplittedifx!=”-“]iflen(positive_results)>0:computed[host]={“sent”:30,”received”:len(positive_results),”rtt”:sum(positive_results),”max”:max(positive_results),”min”:min(positive_results),”mdev”:statistics.pstdev(positive_results)}else:computed[host]={“sent”:30,”received”:len(positive_results),”rtt”:0,”max”:0,”min”:0,”mdev”:0}ifnotlen(computed):raiseValueError(“regexmatch”{}”foundnothinginfpingoutput”{}””.format(FPING_REGEX,results))returncomputed@prometheus_exceptions_counter.count_exceptions()defcall_fping(ips):cmdline=FPING_CMDLINE+ipsprocess=subprocess.run(cmdline,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,universal_newlines=True)ifprocess.returncode==3:raiseValueError(“invalidarguments:{}”.format(cmdline))ifprocess.returncode==4:raiseOSError(“fpingreportedsyscallerror:{}”.format(process.stderr))returnprocess.stdoutenvs=validate_envs()files=glob.glob(envs[“PROMETHEUS_TEXTFILE_DIR”]+”*”)forfinfiles:os.remove(f)labeled_prom_metrics={“cluster_targets”:[],”external_targets”:[]}whileTrue:withopen(CONFIG_PATH,”r”)asf:config=json.loads(f.read())config[“external_targets”]=[]ifconfig[“external_targets”]isNoneelseconfig[“external_targets”]fortargetinconfig[“external_targets”]:target[“name”]=target[“host”]if”name”notintarget.keys()elsetarget[“name”]iflabeled_prom_metrics[“cluster_targets”]:formetricinlabeled_prom_metrics[“cluster_targets”]:if(metric[“node_name”],metric[“ip”])notin[(node[“name”],node[“ipAddress”])fornodeinconfig[‘cluster_targets’]]:fork,vinprom_metrics_cluster.items():v.remove(metric[“node_name”],metric[“ip”])iflabeled_prom_metrics[“external_targets”]:formetricinlabeled_prom_metrics[“external_targets”]:if(metric[“target_name”],metric[“host”])notin[(target[“name”],target[“host”])fortargetinconfig[‘external_targets’]]:fork,vinprom_metrics_external.items():v.remove(metric[“target_name”],metric[“host”])labeled_prom_metrics={“cluster_targets”:[],”external_targets”:[]}fornodeinconfig[“cluster_targets”]:metrics={“node_name”:node[“name”],”ip”:node[“ipAddress”],”prom_metrics”:{}}fork,vinprom_metrics_cluster.items():metrics[“prom_metrics”][k]=v.labels(node[“name”],node[“ipAddress”])labeled_prom_metrics[“cluster_targets”].append(metrics)fortargetinconfig[“external_targets”]:metrics={“target_name”:target[“name”],”host”:target[“host”],”prom_metrics”:{}}fork,vinprom_metrics_external.items():metrics[“prom_metrics”][k]=v.labels(target[“name”],target[“host”])labeled_prom_metrics[“external_targets”].append(metrics)out=call_fping([prom_metric[“ip”]forprom_metricinlabeled_prom_metrics[“cluster_targets”]]+[prom_metric[“host”]forprom_metricinlabeled_prom_metrics[“external_targets”]])computed=compute_results(out)fordimensioninlabeled_prom_metrics[“cluster_targets”]:result=computed[dimension[“ip”]]dimension[“prom_metrics”][“sent”].inc(computed[dimension[“ip”]][“sent”])dimension[“prom_metrics”][“received”].inc(computed[dimension[“ip”]][“received”])dimension[“prom_metrics”][“rtt”].inc(computed[dimension[“ip”]][“rtt”])dimension[“prom_metrics”][“min”].set(computed[dimension[“ip”]][“min”])dimension[“prom_metrics”][“max”].set(computed[dimension[“ip”]][“max”])dimension[“prom_metrics”][“mdev”].set(computed[dimension[“ip”]][“mdev”])fordimensioninlabeled_prom_metrics[“external_targets”]:result=computed[dimension[“host”]]dimension[“prom_metrics”][“sent”].inc(computed[dimension[“host”]][“sent”])dimension[“prom_metrics”][“received”].inc(computed[dimension[“host”]][“received”])dimension[“prom_metrics”][“rtt”].inc(computed[dimension[“host”]][“rtt”])dimension[“prom_metrics”][“min”].set(computed[dimension[“host”]][“min”])dimension[“prom_metrics”][“max”].set(computed[dimension[“host”]][“max”])dimension[“prom_metrics”][“mdev”].set(computed[dimension[“host”]][“mdev”])prometheus_client.write_to_textfile(
该脚本在每个Kubernetes节点上运行,并且每秒两次发送ICMP数据包到Kubernetes集群的所有实例。收集的结果会存储在文本文件中。该脚本会包含在Docker镜像中:另外,我们还创建了一个ServiceAccount和一个具有唯一权限的对应角色用于获取节点列表(这样我们就可以知道它们的IP地址):

相关推荐: jquery如何查询同级元素

这篇文章主要为大家展示了“jquery如何查询同级元素”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“jquery如何查询同级元素”这篇文章吧。 查询方法:1、用siblings()方法,可获得同级所有元素;2、用n…

文章页内容下
赞(0) 打赏
版权声明:本站采用知识共享、学习交流,不允许用于商业用途;文章由发布者自行承担一切责任,与本站无关。
文章页正文下
文章页评论上

云服务器、web空间可免费试用

宝塔面板主机、支持php,mysql等,SSL部署;安全高速企业专供99.999%稳定,另有高防主机、不限制内容等类型,具体可咨询QQ:360163164,Tel同微信:18905205712

主机选购导航云服务器试用

登录

找回密码

注册