Skip to content

PDO/Sqlite not persisting metrics #172

@apms75

Description

@apms75

I tried to setup PDO/Sqlite (Windows 11, prometheus_client_php 2.13.0) with the 2 end-points:

$registry = new \Prometheus\CollectorRegistry(new \Prometheus\Storage\PDO(new \PDO('sqlite::memory:')));

$counter = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']);
$counter->incBy(3, ['blue']);
$registry = new \Prometheus\CollectorRegistry(new \Prometheus\Storage\PDO(new \PDO('sqlite::memory:')));

$renderer = new \Prometheus\RenderTextFormat();
$result = $renderer->render($registry->getMetricFamilySamples());

header('Content-type: ' . \Prometheus\RenderTextFormat::MIME_TYPE);
print($result."\n");

The second end-point keeps returning

# HELP php_info Information about the PHP environment.
# TYPE php_info gauge
php_info{version="8.4.1"} 1

Note: I had to change the line building $registry as the original line from the example in https://github.com/PromPHP/prometheus_client_php/README.md: $registry = new CollectorRegistry(new \PDO('sqlite::memory:')); triggers an error

If I persist the database in a file with new \PDO('sqlite:C:/temp/prom.sqlite'), I get this error the second time I run any of the 2 scripts:

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1 index name already exists in...

It's working well after adding an IF NOT EXISTS in PDO.php line 644

$sqlIndex = "CREATE INDEX IF NOT EXISTS `name` ON `{$this->prefix}_summaries`(`name`);";);";

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions