English | 中文
The plug-in implements sending historical operation records to the Loki log system, and retrieves and visualizes the logs in Loki through Grafana.
Download binary package
$ curl -O -L "https://github.com/grafana/loki/releases/download/v2.6.1/loki-linux-amd64.zip"
# extract the binary
$ unzip "loki-linux-amd64.zip"
# make sure it is executable
$ chmod a+x "loki-linux-amd64"
Download configuration file
$ wget https://raw.githubusercontent.com/grafana/loki/v2.6.0/cmd/loki/loki-local-config.yaml
Start Loki
$ nohup ./loki-linux-amd64 -config.file=loki-local-config.yaml > ./loki.log 2>&1 &
For more installation methods, please refer to Loki official installation documentation
RPM package installation
$ wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.1.6-1.x86_64.rpm
$ sudo yum install grafana-enterprise-9.1.6-1.x86_64.rpm
Start the Grafana service
$ sudo systemctl daemon-reload
$ sudo systemctl start grafana-server
$ sudo systemctl status grafana-server
For more installation methods, please refer to Grafana official installation documentation
- git clone https://github.com/polarismesh/polaris.git
- Go to the polaris directory
- Execute go get github.com/polaris-contrib/polaris-server-plugin-history-loki
- Execute go mod tidy -compat=1.17
- Edit polaris/plugin.go, add in the import block
import ( ... _ "github.com/polarismesh/polaris/plugin/history/loki" # Introduce the plugin and trigger the plugin's automatic registration logic )
- Execute build.sh to build polaris-server
In the polaris-server.yaml configuration file, in the plugin configuration section, the history plugin configuration block is set as follows:
plugin:
history:
name: HistoryLoki # [Required] Plugin name
option:
queueSize: 1024 # [Required] The length of the log cache queue
pushURL: http://127.0.0.1:3100/loki/api/v1/push # [Required] loki push interface address
tenantID: "test" # [optional] set loki log tenant
labels: # [optional] custom log labels
key1: "value1"
key2: "value2"
timeout: 5s # [Optional] Send log http request timeout, default 10s
After polaris-server starts, the plugin will be loaded according to the configuration file, and historical operation records will be reported to the Loki log system through the plugin.
Click the configuration icon on the Grafana page, click Data Sources, and add the Loki data source:
- Name: Set the data source name
- URL: set the address of the Loki instance
After the configuration is complete, click the Save & Test
button at the bottom of the page. If the Loki system is running and a log is reported to the system, it will prompt that the data source is connected and the tag is found.
Create a Grafana panel to display logs, select Loki as the data source, and filter logs based on tags to generate query conditions. The plugin will set three tags, source
, resource_type
and operation_type
by default, and source
is the plugin name. HistoryLoki
, resource_type
is the resource type in the operation record, operation_type
is the operation type in the operation record.
For more configuration and usage, please refer to Using Loki in Grafana