組件架構圖
數(shù)據(jù)格式
時序
時序 由 名字(Metric) 及一組key/value標簽定義逗嫡,具有相同的名字以及標簽屬于相同時序。
<-------------------metric-------------------><--timestamp--><-value->
<metric name>{<label name>=<label value>, ...}><--timestamp--><-value->
http_request_total{status="200",method="get"}@1434417560938 =>94355
http_request_total{status="200",method="get"}@1434417560938 =>94390
http_request_total{status="404",method="get"}@1434417560938 =>38472
http_request_total{status="404",method="get"}@1434417560938 =>38544
http_request_total{status="404",method="post"}@1434417560938 =>4785
指標舉例
#指標意義注釋
#HELP node_cpu_seconds_total Seconds the cpus spent in each mode.
#指標值類型榕栏,counter類型表示只增不減
#TYPE node_cpu_seconds_total counter
#指標名表示節(jié)點的CPU0的空閑時間共計1.40181324e+06秒许昨。數(shù)值從系統(tǒng)開機時算起芽丹,重啟歸零将塑。
node_cpu_seconds_total{cpu="0",mode="idle"} 1.40181324e+06
Prometheus詞義解析
- metric:時序名脉顿,命名應該具有語義化,表示metric的功能点寥,一般表示一個可以度量的指標艾疟,如 http_requests_total, 表示 http 請求總數(shù)。(應用名稱監(jiān)測對象數(shù)值類型單位)开财,由 ASCII 字符汉柒,數(shù)字,下劃線责鳍,冒號組成,必須滿足正則表達式 [a-zA-Z:][a-zA-Z0-9_:]*
Metric類型
- 計數(shù)器:Counter兽间,累加metric历葛,如請求個數(shù),結束任務數(shù),出現(xiàn)錯誤數(shù)等恤溶,只增不減乓诽;
- 儀表盤:Gauge,常規(guī)metric咒程,如溫度鸠天,瞬時,與時間沒關系帐姻,可以任意變化稠集,可任意加減;
- 直方圖:Histogram饥瓷,用于觀察結果采樣剥纷,分組及統(tǒng)計,如:請求持續(xù)時間呢铆。根據(jù)統(tǒng)計區(qū)間計算晦鞋;
- 摘要:Summary,表示一段時間內數(shù)據(jù)采樣結果棺克,不根據(jù)統(tǒng)計區(qū)間計算悠垛,直接存儲結果;
- lable:標簽:key-value對娜谊,一條時間序列不同維度的識別 鼎文,標簽可以擴展,提供監(jiān)控項的識別因俐,方便聚合
- value:樣本:按照某個時序以時間維度采集的數(shù)據(jù)拇惋。實際的時間序列,每個序列包括一個float64的值和一個毫秒級的unix 時間戳
部署
Prometheus下載
測試版本:prometheus-2.21.0.linux-amd64.tar.gz
配置prometheus.yml
# global config
global:
scrape_interval: 15s # 監(jiān)控項數(shù)據(jù)收集時間間隔,15秒向目標抓取一次數(shù)據(jù).默認1min
evaluation_interval: 15s # 規(guī)則發(fā)現(xiàn)時間間隔. 默認1min
scrape_timeout: 10s # 收集數(shù)據(jù)超時時間. 默認10s
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
- localhost:9093 #指定 Alertmanager 組件的IP和端口
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
- "./rules/rule_*.yml"
remote_write:
- url: "http://localhost:8086/api/v1/prom/write?db=prometheus"
# write_relabel_configs:
# - source_labels: [__name__]
# regex: expensive.*
# action: drop
# - url: http://remote2/push
remote_read:
- url: "http://localhost:8086/api/v1/prom/write?db=prometheus"
# read_recent: false/true
# required_matchers:
# job: special
# - url: http://remote3/push
# Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
scrape_interval: 30s #重寫全局抓取間隔時間抹剩,由15秒重寫成30秒
static_configs:
- targets: ['localhost:9090']
#instance: 收集數(shù)據(jù)的目標端點撑帖,一般對應一個進程,即指定其來源澳眷,如某個機器
#job: 實現(xiàn)同一功能或目標的一組instance胡嘿。 如一組機器的集合。
- job_name: 'base'
file_sd_configs:
- files:
- /usr/local/prometheus/node_discovery.json
refresh_interval: 60s
- job_name: 'mysql'
file_sd_configs:
- files:
- /usr/local/prometheus/mysql_discovery.json
refresh_interval: 60s
- job_name: 'openstack'
static_configs:
- targets: ['127.0.0.1:9091']
labels:
instance: gateway
tar -xvzf prometheus-2.21.0.linux-amd64.tar.gz
mv prometheus-2.21.0.linux-amd64 /usr/local/prometheus
檢查配置正確性
./promtool check config prometheus.yml
Checking prometheus.yml
SUCCESS: 2 rule files found
Checking rules/rule_mysql.yml
SUCCESS: 5 rules found
Checking rules/rule_node.yml
SUCCESS: 0 rules found
./promtool check rules rules/rule_mysql.yml
Checking rules/rule_mysql.yml
SUCCESS: 5 rules found
啟動prometheus
./prometheus --config.file=prometheus.yml &
啟動參數(shù):
--config.file=prometheus.yml #指定配置文件
--storage.tsdb.path=/prometheus #指定tsdb路徑
--storage.tsdb.retention.time=24h #指定數(shù)據(jù)存儲時間
--web.enable-lifecycle #配置熱加載
--storage.tsdb.no-lockfile #如果使用k8s的deployment管理要開啟
node_exporter
被監(jiān)控節(jié)點安裝node_exporter钳踊,獲取當前CPU負載衷敌、系統(tǒng)負載、內存消耗拓瞪、硬盤使用量缴罗、網(wǎng)絡IO等監(jiān)控項。
#安裝
tar -zxvf node_exporter-1.0.1.linux-amd64.tar.gz -C /usr/local/
cd /usr/local; mv node_exporter-1.0.1.linux-amd64 node_exporter-1.0.1
#啟動
/usr/local/node_exporter &
#監(jiān)聽
ss -naltp | grep 9100
LISTEN 0 4096 :::9100 :::* users:(("node_exporter",pid=171161,fd=3))
mysqld_exporter
數(shù)據(jù)庫服務節(jié)點安裝mysqld_exporter祭埂,獲取mysql所有status面氓、variables信息。
#安裝
tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local/
mv mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter
#目標服務器授權
GRANT SELECT, PROCESS, REPLICATION CLIENT ON *.* TO 'prometheus'@'IP' IDENTIFIED BY '';
#數(shù)據(jù)庫相關配置
vim .my.cnf
[client]
user=prometheus
password=######## #經(jīng)過測試,盡量不使用特殊字符
port=####
host=localhost
#啟動mysqld_exporter
/root/mysqld_exporter/mysqld_exporter --config.my-cnf=/root/.my.cnf
#查看監(jiān)聽
ss -naltp | grep 9104
LISTEN 0 4096 :::9104 :::* users:(("mysqld_exporter",pid=3010579,fd=3))
Pushgateway
使用場景:
- 自定義監(jiān)控指標
- 網(wǎng)絡限制
tar -zxf pushgateway-1.2.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/;mv pushgateway-1.2.0.linux-amd64 pushgateway-1.2.0;cd pushgateway-1.2.0/
#啟動pushgateway
./pushgateway --web.enable-admin-api --persistence.file="push_file" &
#配置文件添加job
vim /usr/local/prometheus/prometheus.yml
- job_name: gateway
static_configs:
- targets: ['127.0.0.1:9091']
labels:
instance: gateway
#熱加載生效
curl -XPOST http://IP:9090/-/reload
#查看網(wǎng)頁
http://IP:9091
API推送metrics
格式:一般標簽名采用 instance
http://pustgatewayIP/metrices/job/job名/標簽名/標簽值
- 單條數(shù)據(jù)
echo "backup_status `cat /data/galera/backup/mysqldump/dumpdata/\`date +\"%Y%m%d\"\`/full_db.dmp |grep "completed" |wc -l`" | curl --data-binary @- http://IP:9091/metrics/job/backup_node/instance/IP
- 多條數(shù)據(jù)
#!/bin/bash
#Author:mh
#date:2020/11/17
mysqlbin="/usr/local/mariadb/bin/mysql -uprometheus -p*** -h *** -P ***"
mysqladminbin="/usr/local/mariadb/bin/mysqladmin -uprometheus -p*** -h *** -P ***"
cat <<EOF | curl --data-binary @- http://IP:9091/metrics/job/guizou1/instance/IP*/node/control
# HA/keepalived/httpd/memcaches
service_haproxy `systemctl status haproxy | grep Active | grep -E "running|exited" | wc -l`
service_keepalived `systemctl status keepalived | grep Active | grep -E "running|exited" | wc -l`
service_httpd `systemctl status httpd | grep Active | grep -E "running|exited" | wc -l`
service_memcached `systemctl status memcached | grep Active | grep -E "running|exited" | wc -l`
#OpenStack_Server
service_neutron_server `systemctl status neutron-server | grep Active | grep -E "running|exited" | wc -l`
...
#DB_galera
mysql_up2 `${mysqladminbin} ping | grep -c alive`
mysql_connections `${mysqlbin} -NBe "use information_schema;select count(*) from PROCESSLIST;"`
mysql_galera_status `${mysqlbin} -e "SHOW STATUS LIKE 'wsrep_local_state'" |grep -i 'wsrep_local_state' |awk '{print $2}'`
mysql_galera_cluster_size `${mysqlbin} -e "show status like 'wsrep_cluster_size'"|grep -i 'wsrep_cluster_size' |awk '{print $2}'`
mysql_galera_cluster_conf_id `${mysqlbin} -e "show status like 'wsrep_cluster_conf_id'" |grep -i 'wsrep_cluster_conf_id' |awk '{print $2}'`
mysql_status_com_commit `${mysqlbin} -e "show status like 'com_commit'" |grep -i 'com_commit' |awk '{print $2}'`
mysql_status_com_rollback `${mysqlbin} -e "show status like 'com_rollback'" |grep -i 'com_rollback' |awk '{print $2}'`
mysql_status_com_select `${mysqlbin} -e "show status like 'com_select'" |grep -i 'com_select' |awk '{print $2}'`
mysql_status_com_update `${mysqlbin} -e "show status like 'com_update'" |grep -i 'com_update' |awk '{print $2}'`
mysql_status_com_insert `${mysqlbin} -e "show status like 'com_insert'" |grep -i 'com_insert' |awk '{print $2}'`
mysql_status_com_delete `${mysqlbin} -e "show status like 'com_delete'" |grep -i 'com_delete' |awk '{print $2}'`
EOF
Alertmanager
通過在prometheus.yml配置文件中添加規(guī)則的方式舌界,計算觸發(fā)條件后發(fā)出警報
Alert三種狀態(tài)
- pending:警報被激活掘譬,但是低于配置的持續(xù)時間【rule里for設置的時間】該狀態(tài)下不發(fā)送報警。
- firing: 警報已被激活呻拌,而且超出設置的持續(xù)時間葱轩。該狀態(tài)下發(fā)送報警。
- inactive:既不是pending也不是firing時
觸發(fā)一條告警過程
prometheus-->觸發(fā)閾值-->超出持續(xù)時間-->alertmanager-->分組|抑制|靜默-->媒體:郵件|釘釘|微信等藐握。
- 分組: 通過route的group_by進行報警分組靴拱,多條消息一起發(fā)送,將性質類似告警組合成一條告警發(fā)出趾娃,從而減少告警數(shù)量缭嫡;
- 抑制: 高級別報警抑制低級別報警。減少由于高級別告警引發(fā)的系列低級別告警抬闷,從而減少告警數(shù)量妇蛀;
- 靜默:故障靜默(在頁面配置),對已知故障在維護修復期間可以確保在接下來的時間內不會在收到同樣報警信息笤成。從而減少告警數(shù)量评架。
rule_mysql.yml
更新規(guī)則后熱加載生效(需要在prometheus啟動時加上--web.enable-lifecycle參數(shù))
curl -XPOST http://172.28.8.143:9090/-/reload
配置rule
vim /usr/local/prometheus/rules/rule_mysql.yml
groups:
- name: MySQL #報警分組名稱
rules:
- alert: OS is down #報警名稱 alertname
expr: up{job="mysql_galera"} == 0 #條件表達式
for: 1m #服務宕機持續(xù)時間
labels:
severity: critical #報警級別
annotations: #注釋,添加實例
summary: "Instance {{ $labels.instance }} OS is down"
description: "MySQL OS is down. This requires immediate action!"
- alert: MySQL server is down
expr: mysql_up{job="mysql_galera"} == 0
for: 1m
labels:
severity: critical
annotations:
summary: "Instance {{ $labels.instance }} MySQL is down"
description: "MySQL server is down. This requires immediate action!"
Prometheus-webhook-dingtalk
tar -zxf prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz -C /usr/local/
mv prometheus-webhook-dingtalk-1.4.0.linux-amd64 prometheus-webhook-dingtalk-1.4.0
./prometheus-webhook-dingtalk --config.file=webhook_config.yml --web.enable-lifecycle &
配置 webhook_config.yml
## Request timeout
# timeout: 5s
templates:
- contrib/templates/legacy/template.tmpl
default_message:
title: '{{ template "legacy.title" . }}'
## Targets, previously was known as "profiles"
targets:
webhook1:
url: https://oapi.dingtalk.com/robot/send?access_token=***
# secret for signature
# secret: SEC000000000000000000000
# webhook2:
# url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxx
# webhook_legacy:
# url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxx
# # Customize template content
# message:
# # Use legacy template
# title: '{{ template "legacy.title" . }}'
# text: '{{ template "legacy.content" . }}'
# webhook_mention_all:
# url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxx
# mention:
# all: true
webhook_mention_users:
url: https://oapi.dingtalk.com/robot/send?access_token=***
#default_message:
# at: { "atMobiles":["17****"] , "isAtAll":"false" }
?? 在電腦端釘釘創(chuàng)建接收告警群
新建群名稱-XX業(yè)務XX服務告警-->添加機器人-->選擇自定義-->獲取機器人token
TSDB Admin APIs
?? 需要在啟動prometheus 服務時添加參數(shù)--web.enable-admin-api 才能使用API
數(shù)據(jù)備份
curl -XPOST http://localhost:9090/api/v1/admin/tsdb/snapshot
{
"status": "success",
"data": {
"name": "20171210T211224Z-2be650b6d019eb54"
}
}
#快照存儲在 <data-dir>/snapshots/20171210T211224Z-2be650b6d019eb54
# skip_head=<bool>: 選擇是否跳過備份內存中的數(shù)據(jù)炕泳,默認跳過
# 不跳過內存中的數(shù)據(jù)纵诞,即同時備份內存中的數(shù)據(jù)
curl -XPOST http://172.28.8.143:9090/api/v1/admin/tsdb/snapshot?skip_head=false
# 跳過內存中的數(shù)據(jù)
curl -XPOST http://127.0.0.1:9090/api/v2/admin/tsdb/snapshot?skip_head=true
數(shù)據(jù)恢復
將snapshot中的文件覆蓋到data目錄下,重啟prometheus即可
數(shù)據(jù)刪除
刪除一個時間范圍內一系列選擇的數(shù)據(jù)培遵,實際數(shù)據(jù)仍然存在于磁盤上浙芙,并在以后的壓縮中進行清理∽淹螅可以通過單擊Clean Tombstones端點進行顯式清理嗡呼。
參數(shù)
- match[]=<series_selector>: Repeated label matcher argument that selects the series to delete. At least one match[] argument must be provided.
- start=<rfc3339 | unix_timestamp>: Start timestamp.
- end=<rfc3339 | unix_timestamp>: End timestamp.
curl -X POST -g 'http://172.28.8.143:9090/api/v1/admin/tsdb/delete_series?match[]=backup_status&match[]={job="gateway"}'
?? 如果不同時提及開始時間和結束時間,會清除數(shù)據(jù)庫中匹配序列的所有數(shù)據(jù)皇耗。
Clean Tombstones
從磁盤上刪除已刪除的數(shù)據(jù)南窗,并清理現(xiàn)有的邏輯刪除。刪除后可以使用它來釋放空間郎楼。
curl -XPOST http://localhost:9090/api/v1/admin/tsdb/clean_tombstones
PTSDB
原理
核心:倒排索引+窗口存儲Block
數(shù)據(jù)寫入按2h一個窗口万伤,2h內產(chǎn)生的數(shù)據(jù)存儲在Head Block中,每一個塊中包含該時間窗口內的所有樣本數(shù)據(jù)(chunks)呜袁,元數(shù)據(jù)文件(meta.json)以及索引文件(index)敌买,最新寫入的數(shù)據(jù)保存在內存block中, 2小時后寫入磁盤傅寡。后臺線程把2小時的數(shù)據(jù)最終合并成更大的數(shù)據(jù)塊放妈。
PTSDB內存大小由最小時間周期北救,采集周期以及時間線數(shù)量決定荐操。
防止程序異常而導致數(shù)據(jù)丟失采取的措施
- WAL機制芜抒,即2小時內記錄的數(shù)據(jù)存儲在內存中的同時,還會記錄一份日志托启,存儲在block下的wal目錄中宅倒。當程序再次啟動時,會將wal目錄中的數(shù)據(jù)寫入對應的block中屯耸,達到恢復數(shù)據(jù)效果拐迁。
- 刪除數(shù)據(jù)時,刪除條目會記錄在tombstones 中疗绣,而不是立刻刪除线召。
ll /usr/local/prometheus/data
drwxr-xr-x 3 root root 68 Nov 17 07:00 01EQ9MJQBFPPR27ECX56AWPGX4
drwxr-xr-x 3 root root 68 Nov 23 23:00 01EQTSX62XKFRN5JX2JZS334TN
drwxr-xr-x 3 root root 68 Nov 24 17:00 01EQWQPD2BWPNDNZRNTWN3NYDF
drwxr-xr-x 3 root root 68 Nov 25 11:00 01EQYNFZ2KJHHZP9GFFM08P918
drwxr-xr-x 3 root root 68 Nov 25 17:00 01EQZA32A527R17FWN47S4FPGA
drwxr-xr-x 3 root root 68 Nov 25 17:00 01EQZA32XV9173J7ZYN7D74YAS
drwxr-xr-x 3 root root 68 Nov 25 17:57 01EQZD5RWRCFWE8X8M2QWVKRHA
drwxr-xr-x 2 root root 104 Jan 20 14:19 chunks_head
-rw-r--r-- 1 root root 20001 Jan 20 16:44 queries.active
drwxr-xr-x 2 root root 6 Dec 8 14:45 snapshots
drwxr-xr-x 3 root root 4096 Jan 20 14:17 wal
ll 01EQ9MJQBFPPR27ECX56AWPGX4
drwxr-xr-x 2 root root 20 Sep 30 09:00 chunks #000001 保存timeseries數(shù)據(jù)
-rw-r--r-- 1 root root 157769 Sep 30 09:00 index #通過metric名和labels查找時序數(shù)據(jù)在chunk文件中的位置
-rw-r--r-- 1 root root 277 Sep 30 09:00 meta.json #配置文件,包含起止時間多矮、包含哪些block
-rw-r--r-- 1 root root 9 Sep 30 09:00 tombstones #刪除操作會首先記錄到這個文件
測試數(shù)據(jù)量
運行時間 | 采集頻率 | 監(jiān)控項總量 | 存儲占用 |
---|---|---|---|
7d | 10s | 55203 | 6G |
PromQL (Prometheus Query Language)
查詢語法
加減乘除:+ - * / % ^
比較運算:== != > < >= <=
邏輯運算:and or
聚合運算:sum min max avg stddev stdvar count topk
內置函數(shù):rate irate abs ceil increse sort sort_desc
時間范圍單位 :s/m/h/d/w/y【秒/分/小時/天/周/年】
查詢結果類型
瞬時數(shù)據(jù) : 包含一組時序缓淹,每個時序只有一個點
http_requests_total
區(qū)間數(shù)據(jù) : 包含一組時序,每個時序有多個點
http_requests_total[5m]
純量數(shù)據(jù) : 只有一個數(shù)字塔逃,沒有時序
count(http_requests_total)
查詢舉例
#范圍查詢: 過去1分鐘數(shù)據(jù)
mysql_global_status_aborted_connects{instance="172.x.x.132:9104"}[1m]
#范圍查詢:查詢結果
mysql_global_status_aborted_connects{idc="xxx",instance="172.x.x.132:9104",job="mysql"}
54 @1611124329.273
54 @1611124344.273
54 @1611124359.273
54 @1611124374.273
#比較查詢:查詢某項監(jiān)控超過某個數(shù)值
mysql_global_status_aborted_connects>20
#比較查詢:查詢結果
Element Value
mysql_global_status_aborted_connects{idc="xxx",instance="172.x.x.132:9104",job="mysql"} 54
mysql_global_status_aborted_connects{idc="xxx",instance="172.x.x.133:9104",job="mysql"} 5263
Grafana
#[Red Hat, CentOS, RHEL, and Fedora(64 Bit)]
wget https://dl.grafana.com/oss/release/grafana-7.2.2-1.x86_64.rpm
sudo yum install grafana-7.2.2-1.x86_64.rpm -y
systemctl status grafana-server
influxDB簡介
InfluxDB特性
- 極簡架構:單機版的InfluxDB只需要安裝一個binary讯壶,即可運行使用,沒有任何外部依賴湾盗。
- 極強的寫入能力: 底層采用自研TSM (Time-Structured Merge Tree) 存儲引擎伏蚊,基于LSM,提供極強寫能力以及高壓縮率格粪。
- 高效查詢:對Tags會進行索引躏吊,提供高效檢索。
- InfluxQL:提供SQL-Like的查詢語言帐萎,方便使用
- Continuous Queries: 通過CQ能夠支持auto-rollup和pre-aggregation比伏,對常見的查詢操作可以通過CQ來預計算加速查詢。
名詞對比
概念 | MySQL | InfluxDB |
---|---|---|
數(shù)據(jù)庫 | database | database |
表 | table | measurement |
列 | column | Point:tag/field/timestemp(唯一主鍵) |
Point由時間戳(time)數(shù)據(jù)(field)和標簽(tags)組成吓肋。
- time:每條數(shù)據(jù)記錄的時間凳怨,也是數(shù)據(jù)庫自動生成的主索引;
- fields:各種記錄的值是鬼;
- tags:各種有索引的屬性肤舞。
??
tag 只能為字符串類型,field 類型無限制均蜜。
支持連續(xù)查詢操作:CONTINUOUS QUERY李剖,不支持join。
部署
#rpm安裝
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.3.x86_64.rpm
yum install -y influxdb-1.8.3.x86_64.rpm
sudo yum localinstall influxdb-1.8.3.x86_64.rpm
systemctl start influxdb.service
ps -ef | grep influx
influxdb 7017 1 0 15:15 ? 00:00:01 /usr/bin/influxd -config /etc/influxdb/influxdb.conf
#tar安裝
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.3_linux_amd64.tar.gz
tar -zxf influxdb-1.8.3_linux_amd64.tar.gz -C /usr/local/
cd /usr/local/;mv influxdb-1.8.3-1/ influxdb-1.8.3-1
mkdir -p /var/data/influxdb/{meta,data,wal}
#修改配置文件中路徑相關設置后啟動
/usr/local/influxdb-1.8.3-1/usr/bin/influxd --config /usr/local/influxdb-1.8.3-1/etc/influxdb/influxdb.conf &
netstat -tunlp|grep 8086
tcp6 0 0 :::8086 :::* LISTEN 1731275/influxd
#查看InfluxDB相關命令
ll /usr/local/influxdb-1.8.3-1/usr/bin
influxd 啟動influxdb服務器
influx influxdb命令行客戶端
influx_inspect 查看工具
influx_stress 壓力測試工具
influx_tsm 數(shù)據(jù)庫轉換工具(將數(shù)據(jù)庫從b1或bz1格式轉換為tsm1格式)
export PATH=/usr/local/influxdb-1.8.3-1/usr/bin:$PATH
#客戶端登錄
./influx -host XXX -port xx 遠程連接服務端
常用命令
#創(chuàng)建庫
create database "db_name"
#使用庫
use db_name
#輸出所有數(shù)據(jù)庫
show databases
#輸出所有表
show measurements
#匹配輸出表
show measurements ON prometheus_data with measurement =~ /threads*/
#刪除數(shù)據(jù)庫
drop database "db_name"
#刪除表
drop measurement "measurement_name"
#插入
insert test,host=127.0.0.1,monitor_name=test count=1
#查詢
select * from mysql_global_status_wsrep_thread_count order by time desc limit 10;
#?? 時間字段默認顯示納秒時間戳囤耳,要輸出可讀格式篙顺,需要指定precision后查詢。
#也可以指定參數(shù)連接數(shù)據(jù)庫:influx -precision rfc3339
precision rfc3339;
select * from mysql_global_status_wsrep_thread_count order by time desc limit 10;
#查看一個measurement中所有的tag key
show tag keys
#查看一個measurement中所有的field key
show field keys
備份數(shù)據(jù)庫
influxd backup -portable /backup/total
influxd backup -portable -db prometheus /backup/prometheus_data
influxd backup -portable -db prometheus -start 2020-07-27T2:31:57Z -end 2020-07-27T2:32:59Z /backup/prometheus_20200701
恢復數(shù)據(jù)庫
--To restore only the telegraf database (dbname database must not exist):
influxd restore -portable -db dbname path-to-backup
--To Restore the existing database backup to a temporary database.
influxd restore -portable -db dbname -newdb dbname_bak path-to-backup
> USE dbname_bak
> SELECT * INTO dbname..:MEASUREMENT FROM /.*/ GROUP BY *
> DROP DATABASE dbname_bak
集群高可用架構
更新中匪蟀。