简介
Prometheus是Golang写的,编译后就是一个二进制文件,不依赖于第三方运行库。这样子就可以让我们很方便的部署。
下载安装
Golang的交叉编译,可以很容易实现跨平台。
如果是测试实验可以在下载windows版本的就可以了。
我这边都是Linux环境,直接下载Linux版本
wget-chttps://github.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-2.23.0.linux-amd64.tar.gz
tarzxvfprometheus-2.23.0.linux-amd64.tar.gz
运行
解压后,就可以执行二进制文件prometheus
./prometheus
默认配置文件是当前目录下的prometheus.yml
默认配置文件里面只有拉取prometheus自己的指标。
帮助
./prometheus–help
prometheus 提供了很多参数可以进行配置,根据实际情况进行设置即可。
usage:prometheus[<flags>]
ThePrometheusmonitoringserver
Flags:
-h,–helpShowcontext-sensitivehelp(alsotry–help-longand–help-man).
–versionShowapplicationversion.
–config.file="prometheus.yml"
Prometheusconfigurationfilepath.
–web.listen-address="0.0.0.0:9090"
AddresstolistenonforUI,API,andtelemetry.
–web.read-timeout=5mMaximumdurationbeforetimingoutreadoftherequest,andclosingidleconnections.
–web.max-connections=512Maximumnumberofsimultaneousconnections.
–web.external-url=<URL>TheURLunderwhichPrometheusisexternallyreachable(forexample,ifPrometheusisservedviaareverseproxy).Usedforgeneratingrelativeandabsolutelinksbackto
Prometheusitself.IftheURLhasapathportion,itwillbeusedtoprefixallHTTPendpointsservedbyPrometheus.Ifomitted,relevantURLcomponentswillbederived
automatically.
–web.route-prefix=<path>Prefixfortheinternalroutesofwebendpoints.Defaultstopathof–web.external-url.
–web.user-assets=<path>Pathtostaticassetdirectory,availableat/user.
–web.enable-lifecycleEnableshutdownandreloadviaHTTPrequest.
–web.enable-admin-apiEnableAPIendpointsforadmincontrolactions.
–web.console.templates="consoles"
Pathtotheconsoletemplatedirectory,availableat/consoles.
–web.console.libraries="console_libraries"
Pathtotheconsolelibrarydirectory.
–web.page-title="PrometheusTimeSeriesCollectionandProcessingServer"
DocumenttitleofPrometheusinstance.
–web.cors.origin=".*"RegexforCORSorigin.Itisfullyanchored.Example:'https?://(domain1|domain2)\\.com'
–storage.tsdb.path="data/"
Basepathformetricsstorage.
–storage.tsdb.retention=STORAGE.TSDB.RETENTION
[DEPRECATED]Howlongtoretainsamplesinstorage.Thisflaghasbeendeprecated,use"storage.tsdb.retention.time"instead.
–storage.tsdb.retention.time=STORAGE.TSDB.RETENTION.TIME
Howlongtoretainsamplesinstorage.Whenthisflagissetitoverrides"storage.tsdb.retention".Ifneitherthisflagnor"storage.tsdb.retention"nor
"storage.tsdb.retention.size"isset,theretentiontimedefaultsto15d.UnitsSupported:y,w,d,h,m,s,ms.
–storage.tsdb.retention.size=STORAGE.TSDB.RETENTION.SIZE
[EXPERIMENTAL]Maximumnumberofbytesthatcanbestoredforblocks.Aunitisrequired,supportedunits:B,KB,MB,GB,TB,PB,EB.Ex:"512MB".Thisflagisexperimentaland
canbechangedinfuturereleases.
–storage.tsdb.no-lockfile
Donotcreatelockfileindatadirectory.
–storage.tsdb.allow-overlapping-blocks
[EXPERIMENTAL]Allowoverlappingblocks,whichinturnenablesverticalcompactionandverticalquerymerge.
–storage.tsdb.wal-compression
CompressthetsdbWAL.
–storage.remote.flush-deadline=<duration>
Howlongtowaitflushingsampleonshutdownorconfigreload.
–storage.remote.read-sample-limit=5e7
Maximumoverallnumberofsamplestoreturnviatheremotereadinterface,inasinglequery.0meansnolimit.Thislimitisignoredforstreamedresponsetypes.
–storage.remote.read-concurrent-limit=10
Maximumnumberofconcurrentremotereadcalls.0meansnolimit.
–storage.remote.read-max-bytes-in-frame=1048576
Maximumnumberofbytesinasingleframeforstreamingremotereadresponsetypesbeforemarshalling.Notethatclientmighthavelimitonframesizeaswell.1MBas
recommendedbyprotobufbydefault.
–rules.alert.for-outage-tolerance=1h
Maxtimetotolerateprometheusoutageforrestoring"for"stateofalert.
–rules.alert.for-grace-period=10m
Minimumdurationbetweenalertandrestored"for"state.Thisismaintainedonlyforalertswithconfigured"for"timegreaterthangraceperiod.
–rules.alert.resend-delay=1m
MinimumamountoftimetowaitbeforeresendinganalerttoAlertmanager.
–alertmanager.notification-queue-capacity=10000
ThecapacityofthequeueforpendingAlertmanagernotifications.
–alertmanager.timeout=10s
TimeoutforsendingalertstoAlertmanager.
–query.lookback-delta=5mThemaximumlookbackdurationforretrievingmetricsduringexpressionevaluationsandfederation.
–query.timeout=2mMaximumtimeaquerymaytakebeforebeingaborted.
–query.max-concurrency=20
Maximumnumberofqueriesexecutedconcurrently.
–query.max-samples=50000000
Maximumnumberofsamplesasinglequerycanloadintomemory.Notethatquerieswillfailiftheytrytoloadmoresamplesthanthisintomemory,sothisalsolimitsthe
numberofsamplesaquerycanreturn.
–log.level=infoOnlylogmessageswiththegivenseverityorabove.Oneof:[debug,info,warn,error]
–log.format=logfmtOutputformatoflogmessages.Oneof:[logfmt,json]
注册成服务
目前linux大部分的发行版本都是使用systemd管理系统服务了,我们可以直接编辑一个systemd的service文件,来部署prometheus服务。
vim/etc/systemd/system/prometheus.service
如果没有设置–storage.tsdb.path,记得设置好工作目录WorkingDirectory,不然所有数据都会保存到家目录里面。
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/prometheus/prometheus
ExecStart=/opt/prometheus/prometheus/prometheus–config.file="/opt/prometheus/prometheus/prometheus.yml"
LimitNOFILE=65536
PrivateTmp=true
RestartSec=2
StartLimitInterval=0
Restart=always
[Install]
WantedBy=multi-user.target
使用systemctl加载文件、控制服务
systemctldaemon-reload
systemctlenableprometheus
systemctlstartprometheus
WebUI
启动之后,默认监听是9090端口,浏览器直接访问即可
http://[ip]:9090
原文地址:https://www.toutiao.com/i6910113923572253196/




