c盤清理的步驟是什么(如何清理C盤空間)
如何清理C盤空間怎么清理C盤的垃圾文件?每天上網會給電腦帶來很多臨時文件,這些垃圾文件不清理掉時間久了就會影響到電腦的運行速度。那怎
2022/12/08
(資料圖片)
1、pushgateway是什么pushgateway是另一種數據采集的方式,采用被動推送來獲取監控數據的prometheus插件,它可以單獨運行在任何節點上,并不一定要運行在被監控的客戶端。首先通過用戶自定義編寫的腳本把需要監控的數據發送給pushgateway,pushgateway再將數據推送給對應的Prometheus服務。對于短時運行、不支持輪詢的任務,可以引入 pushgateway,將指標數值以 push 的方式推送到 pushgateway暫存,然后 prometheus 從 pushgateway 中輪詢pushgateway是Prometheus下的一個組件,用來當做采集對象和Prometheus的代理,Prometheus會定時的從gateway上面pull數據。2、使用pushgateway的原因原因一:因為Prometheus 采用 pull 模式,可能由于不在一個子網或者防火墻,導致 Prometheus 無法直接拉取各個 target 數據。Prometheus 在一些情況下無法直接拉取各個 target 數據原因二:在監控業務數據的時候,需要將不同數據匯總, 由 Prometheus 統一收集。3、弊端a:將多個節點數據匯總到 pushgateway, 如果pushgateway掛了,受影響比多個target大。通過單個 Pushgateway 監控多個實例時, Pushgateway 將會成為單點故障和潛在瓶頸b:Prometheus 拉取狀態 up 只針對 pushgateway, 無法做到對每個節點有效。c:Pushgateway可以持久化推送給它的所有監控數據。 因此,即使你的監控已經下線,prometheus還會拉取到舊的監控數據,需要手動清理pushgateway不要的數據
pushgateway結構圖
與prometheus結合流程圖
下載地址https://github.com/prometheus/pushgateway/releases/
1、解壓tar -zxvf pushgateway-1.2.0.linux-amd64.tar.gzcp -r pushgateway-1.2.0.linux-amd64 /usr/local/pushgateway2、編寫systemd管理文件vi /usr/lib/systemd/system/pushgateway.service[Unit]Descriptinotallow=Prometheus Pushgateway daemonAfter=network.target[Service]Type=simpleUser=rootGroup=rootExecStart=/usr/local/pushgateway/pushgateway \ --persistence.file=/usr/local/pushgateway/pushgateway_persist_file \ --persistence.interval=5m \ --web.listen-address=:9091Restart=on-failure[Install]WantedBy=multi-user.target3、配置說明# --persistence.file=/usr/local/pushgateway/pushgateway_persist_file,指定持久化文件路徑或名稱。如果沒有指定存儲,則監控指標僅保存在內存中,若出現pushgateway重啟或意外故障,便會導致數據丟失。默認情況下,持久化文件每5分鐘寫一次,可以使用“--persistence.interval”重新設置寫入文件的時間間隔。# --web.listen-address=:9091,進行端口設置。4、重新加載system并啟動pushgatewaysystemctl daemon-reloadsystemctl restart pushgatewaysystemctl status pushgateway5、訪問http://192.168.10.131:9091
[root@root pushgateway-1.0.0]# ./pushgateway -husage: pushgateway []The PushgatewayFlags: -h, --help Show context-sensitive help (also try --help-long and --help-man). #指定服務端口 --web.listen-address=":9091" Address to listen on for the web interface, API, and telemetry. #指定暴露出去的接口 --web.telemetry-path="/metrics" Path under which to expose metrics. --web.external-url= The URL under which the Pushgateway is externally reachable. --web.route-prefix="" Prefix for the internal routes of web endpoints. Defaults to the path of --web.external-url. --web.enable-lifecycle Enable shutdown via HTTP request. --web.enable-admin-api Enable API endpoints for admin control actions. #持久化存儲的地址,否則重啟后采集的指標就沒有了 --persistence.file="" File to persist metrics. If empty, metrics are only kept in memory. #持久化存儲的間隔時間 --persistence.interval=5m The minimum interval at which to write out the persistence file. --log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error] --log.format=logfmt Output format of log messages. One of: [logfmt, json] --version Show application version.
因為Prometheus配置pushgateway的時候,指定job和instance,但是它只表示pushgateway實例,不能真正表達收集數據的含義。所以在prometheus中配置pushgateway的時候,需要添加honor_labels: true參數,從而避免收集數據被push本身的job和instance被覆蓋。不加honor_labels: true,會取gateway的job和instance,設置了的話會取push過來的數據,job必填,instance沒有就為""空字符串 - job_name: pushgetway honor_labels: true honor_timestamps: true scrape_interval: 15s scrape_timeout: 10s metrics_path: /metrics scheme: http static_configs: - targets: - 127.0.0.1:9091 labels: instance: pushgateway
1、提交一條數據到 {job=‘some_job’}echo "some_metric 3.14" | curl --data-binary @- http://pushgateway.example.org:9091/metrics/job/some_job2、下面我們加上instance的值echo "some_metrics 3.14" | curl --data-binary @- http://pushgateway.example.org:9091/metrics/job/some_job/instance/some_instance可以看到pushgateway頁面上產生了兩個group,pgw是以job和instance分組的。用來更細力度的區分。3、可以添加更多的標簽,但是只會以job和instance區分官方的例子如下:cat <三、數據推送
1、數據推送格式
Pushgateway 監聽的默認端口是 9091。路徑看起來像:/metrics/job/{/ / }要 Push 數據到 PushGateway 中,可以通過其提供的 API 標準接口來添加,默認URL地址為:http:// :9091/metrics/job/ {/ / }, 用作job標簽的值,后跟任意數量的其他標簽對(可能包含也可能不包含 instance標簽)一般我們會添加一個 instance/ 實例名稱標簽,來方便區分各個指標 2、簡單命令行數據推送
echo "test_metric 123456" | curl --data-binary @- http://pushgateway.example.org:9091/metrics/job/test_job刷新pushgateway,點擊Metrics除了test_metric外,同時還新增了push_time_seconds和push_failure_time_seconds兩個指標,這兩個是PushGateway系統自動生成的相關指標。同時,在Prometheus UI頁面上Graph頁面可以查詢test_metric的指標了。test_metric{job="test_job"}3、較為復雜數據的推送(命令行數據)
Push 一個復雜一些的,一次寫入多個指標,而且每個指標添加 TYPE 及 HELP 說明。推送命令:cat <4、大量數據提交(通過寫入文件將文件提交)
cat pgdata.txt# TYPE http_request_total counter# HELP http_request_total get interface request count with different code.http_request_total{code="200",interface="/v1/save"} 276http_request_total{code="404",interface="/v1/delete"} 0http_request_total{code="500",interface="/v1/save"} 1# TYPE http_request_time gauge# HELP http_request_time get core interface http request time.http_request_time{code="200",interface="/v1/core"} 0.122curl -XPOST --data-binary @pgdata.txt http://pushgateway.example.org:9091/metrics/job/app/instance/app-172.30.0.0四、刪除指標
1、ui界面刪除
2、命令行刪除
刪除 job=“test_job” 組下的所有指標值,可以執行如下命令:curl -X DELETE http://pushgateway.example.org:9091/metrics/job/test_job刪除job="test_job"組下的所有指標值,不包括{job="test_job", instance="test_instance"}中的指標值,雖然它們的job名稱都為test_job。如果想刪除該指標值,那么需要執行如下命令:并且前提(requires to enable the admin API via the command line flag --web.enable-admin-api)curl -X DELETE http://pushgateway.example.org:9091/metrics/job/test_job/instance/test_instance五、使用注意事項
1、指標值只能是數字類型,非數字類型報錯echo "test_metric 12.34.56ff" | curl --data-binary @- http://pushgateway.example.org:9091/metrics/job/test_job_1"text format parsing error in line 1: expected float as value, got "12.34.56ff""2、指標值支持最大長度為 16 位,超過16 位后默認置為 0echo "test_metric 1234567898765432123456789" | curl --data-binary @- http://pushgateway.example.org:9091/metrics/job/test_job_2實際獲取值 test_metric{job=“test_job_2”} 1234567898765432000000003、PushGateway 數據持久化操作默認PushGateway不做數據持久化操作,當PushGateway重啟或者異常掛掉,導致數據的丟失,可以通過啟動時添加-persistence.file和-persistence.interval參數來持久化數據。-persistence.file 表示本地持久化的文件,將 Push 的指標數據持久化保存到指定文件,-persistence.interval 表示本地持久化的指標數據保留時間,若設置為 5m,則表示 5 分鐘后將刪除存儲的指標數據。4、PushGateway推送及Prometheus拉取時間設置Prometheus每次從PushGateway拉取的數據,并不是拉取周期內用戶推送上來的所有數據,而是最后一次Push到PushGateway上的數據,所以推薦設置推送時間小于或等于Prometheus拉取的時間,這樣保證每次拉取的數據是最新Push上來的。
標簽: 數據匯總