Mac OS安装victoriametrics
docker run -it --name vm -v /Users/xxx/data/vm:/victoria-metrics-data -p 8428:8428 victoriametrics/victoria-metrics
启动后,查看运行参数
http://localhost:8428/metrics
http://localhost:8428/debug/pprof/
使用influxdb协议写入vm
pom.xml引入依赖
<dependency>
<groupId>com.influxdb</groupId>
<artifactId>influxdb-client-java</artifactId>
<version>2.0.0</version>
</dependency>
?将数据写入vm示范代码
package example;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.WriteApi;
import com.influxdb.client.domain.WritePrecision;
import com.influxdb.client.write.Point;
import java.time.Instant;
/**
* @author admin
*/
public class Write2VM {
public static void main(String[] args) {
String bucket = "flink";
String org = "galaxy";
InfluxDBClient client = InfluxDBClientFactory.create("http://localhost:8428");
Point point = Point
.measurement("mem")
.addTag("vm", "pointWay")
.addField("used_percent", 66)
.time(Instant.now(), WritePrecision.NS);
try (WriteApi writeApi = client.getWriteApi()) {
writeApi.writePoint(bucket, org, point);
}
}
}
在grafana中查看数据点
命令行查询?
curl -G 'http://localhost:8428/api/v1/export' -d 'match={__name__=~"mem_used_percent.*"}'
结果:
{"metric":{"__name__":"mem_used_percent","vm":"pointWay"},"values":[66,88],"timestamps":[1634307675617,1634308728583]}
命令行curl写入数据到vm
curl -d 'measurement,tag1=value1,tag2=value2 field1=666,field2=1.23' -X POST 'http://localhost:8428/write'
|