运维监控系统介绍Prometheus是用Golang编写的。编译后为二进制文件,不依赖第三方运行时库。这使我们可以非常方便地部署它。下载安装Golang交叉编译,轻松实现跨平台。如果是测试实验,可以下载windows版。我这边全是Linux环境,直接下载Linux版wget-chttps://github.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-2.23.0.linux-amd64.tar.gztarzxvfprometheus-2.23。运行0.linux-amd64.tar.gz并解压后,可以执行二进制文件prometheus。/prometheus默认的配置文件是当前目录下的prometheus.yml。默认的配置文件只拉取prometheus本身的指标。help./prometheus--helpprometheus提供了很多参数可以配置,根据实际情况设置即可。usage:prometheus[]ThePrometheusmonitoringserverFlags:-h,--helpShowcontext-sensitivehelp(alsotry--help-longand--help-man).--versionShowapplicationversion.--config.file="prometheus.yml"Prometheus配置文件路径.--web.listen-address="0.0.0.0:9090"用于UI、API和遥测的侦听地址。--web.read-timeout=5m超时读取请求和关闭空闲连接之前的最长持续时间。--web.max-connections=512最大同时连接数。--web.external-url=TheURLunderwhichPrometheusisexternallyreachable(forexample,ifPrometheusisservedviaareverseproxy).UsedforgeneratingrelativeandabsolutelinksbacktoPrometheusitself.IftheURLhasapathportion,itwillbeusedtoprefixallHTTPendpointsservedbyPrometheus.Ifomitted,relevantURLcomponentswillbederivedautomatically.--web.route-prefix=Prefixfortheinternalroutesofwebendpoints.Defaultstopathof--web.external-url.--web.user-assets=病理学setdirectory,availableat/user.--web.enable-lifecycleEnableshutdownandreloadviaHTTPrequest.--web.enable-admin-apiEnableAPIendpointsforadmincontrolactions.--web.console.templates="consoles"控制台模板目录路径,availableat/consoles.--web.console.libraries="console_libraries"Pathtotheconsolelibrarydirectory.--web.page-title="PrometheusTimeSeriesCollectionandProcessingServer"DocumenttitleofPrometheusinstance.--web.cors.origin=".*"CORSorigin.Itisfullyanchored.Example:'https?://(domain1|domain2)\.com'--storage.tsdb.path="data/"Basepathformetricsstorage.--storage.tsdb.retention=STORAGE.TSDB.RETENTION[DEPRECATED]在存储中保留样本的时间。此标志已被弃用,请改用“storage.tsdb.retention.time”。--存储。tsdb.retention.time=STORAGE.TSDB.RETENTION.TIME在存储中保留样本的时间。当此标志设置为覆盖“storage.tsdb.retention”时。如果没有此标志或“storage.tsdb.retention”或“storage.tsdb.retention.size”isset,保留时间默认为15d。支持的单位:y,w,d,h,m,s,ms。--storage.tsdb.retention.size=STORAGE。TSDB.RETENTION.SIZE[实验]块可以存储的最大字节数。需要单位,支持的单位:B、KB、MB、GB、TB、PB、EB。例如:“512MB”。这个标志是实验性的,可以在未来的版本中改变。--storage.tsdb.no-lockfileDonotcreatelockfileindatadirectory--storage。tsdb.allow-overlapping-blocks[实验性]允许重叠块,从而启用垂直压缩和垂直查询合并。--storage.tsdb.wal-compressionCompressthetsdbWAL。--storage.remote.flush-deadline=Howlongtowaitflushingsampleonshutdownorconfigreload。--storage.remote.read-sample-limit=5e7Maximumoverallnumberofsamplestoreturturnviatheremotereadinterface,inasinglequery.0meansnolimit.Thislimitisignoredforstreamedresponsetypes.--storage.remote.read-concurrent-limit=10Maximumnumberofconcurrentremotereadcalls.0meansnolimit.--storage.remote.read-max-bytes-in-frame=1048576Maximumnumberofbytesinasingleframeforstreamingremotereadresponsetypesbeforemarshalling.Notethatclientmighthavelimitonframesizeaswell.1MBasrecommendedbyprotobufbydefault.--rules.alert.for-outage-tolerance=1hMaxtimetotolerateprometheusoutageforrestoring"for"stateofalert.--rules.alert.for-grace-period=10mMinimumdurationbetweenalertandrestored"for"state.Thisismaintainedonlyforalertswithconfigured"for"timegreaterthangraceperiod.--rules.alert.resend-delay=1mMinimumamountoftimetowaitbeforeresendinganalerttoAlertmanager.--alertmanager.notification-queue-capacity=10000ThecapacityofthequeueforpendingAlertmanagernotifications.--alertmanager.timeout=10sTimeoutforsendingalertstoAlertmanager.--query.lookback-delta=5mThemaximumlookbackdurationforretrievingmetricsduringexpressionevaluationsandfederation.--query.timeout=2mMaximumtimeaquerymaytakebeforebeingaborted.--query.max-concurrency=20Maximumnumberofqueriesexecutedconcurrently.--query.max-samples=50000000Maximumnumberofsamplesasinglequerycanloadintomemory.Notethatquerieswillfailiftheytrytoloadmoresamplesthanthisintomemory,sothisalsolimitsthenumberofsamplesaquerycanreturn.--log.level=infoOnlylogmessageswiththegivenseverityorabove.Oneof:[debug,info,warn,error]--log.format=logfmtOutputformatoflogmessages.Oneof:[logfmt,json]被注册为服务。目前,大多数Linux发行版都使用systemd管理系统服务。我们可以直接编辑一个systemd服务文件来部署prometheus服务vim/etc/systemd/system/prometheus.service如果没有设置--storage.tsdb.path,记得设置工作目录WorkingDirectory,否则所有数据都会保存在主目录。[Unit]Description=prometheusAfter=network.target[Service]Type=simpleWorkingDirectory=/opt/prometheus/prometheusExecStart=/opt/prometheus/prometheus/prometheus--config.file="/opt/prometheus/prometheus/prometheus.yml"LimitNOFILE=65536PrivateTmp=trueRestartSec=2StartLimitInterval=0Restart=always[Install]WantedBy=multi-user.target使用systemctl加载文件并控制服务/[ip]:9090【编者推荐】2021年更适合web开发的7种编程语言,为什么用Eclipse和VSCode?权威数据来了,中国到底有多少程序员?10个实用工具网站你收藏了吗?2021年可能有五种编程语言前景更好