123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- /**
- * dolphin. Collection of useful PHP skeletons.
- * Copyright (C) 2024 Johannes 'Banana' Keßler
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
- *
- * You should have received a copy of the
- * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
- * along with this program. If not, see http://www.sun.com/cddl/cddl.html
- */
- /**
- * This is an exmaple to show how to send custom logs/metrics
- * to loki and use them in grafana
- */
- # basic loki endpoint information
- const LOKI_HOST = "localhost";
- const LOKI_PORT = 3100;
- const LOKI_PUSH_API = "/loki/api/v1/push";
- # loki does not have protection
- # https://grafana.com/docs/loki/latest/operations/authentication/
- # this example does use basic auth
- # if you do not use it, comment both constants
- const LOKI_USER = "name";
- const LOKI_USER_PW = "pass";
- # Loki
- require_once 'loki.php';
- # see https://grafana.com/docs/loki/latest/reference/loki-http-api/#ingest-logs for
- # data structure
- $Loki = new Loki(LOKI_HOST, LOKI_PORT, array("streamlabel1" => "value1", "streamlabel2" => "value2"));
- $Loki->log("log line text", array("structuredData" => "value"));
- $Loki->log("log line text", array("structuredData" => "value2"));
- # send the data to loki at the end to avoid and multiple calls and breaking
- # the process of the script.
- $Loki->send();
|