Compare commits

...

5 Commits

Author SHA1 Message Date
Manas 8674832d58
Merge 7a774d04ea into 6a9004890f 2024-11-20 03:34:13 +03:00
Kemal Akkoyun 6a9004890f
Add codeowners (#1688)
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
2024-11-19 18:14:03 +01:00
Kemal Akkoyun 7d0a0fbb72
fix: replace fmt.Errorf with errors.New (#1689)
```shell
prometheus/process_collector_darwin.go:28:25: fmt.Errorf can be replaced with errors.New (perfsprint)
var notImplementedErr = fmt.Errorf("not implemented")
```

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
2024-11-19 18:13:52 +01:00
Manas 7a774d04ea
Merge branch 'main' into dbstatscollectorexample 2024-10-21 22:16:23 +05:30
manask322 13df7a91e9 add example for dbstatscollector
Signed-off-by: manask322 <manask322@gmail.com>
2024-10-21 22:15:50 +05:30
5 changed files with 69 additions and 1 deletions

1
.github/CODEOWNERS vendored Normal file
View File

@ -0,0 +1 @@
* @ArthurSens @bwplotka @kakkoyun @vesari

View File

@ -0,0 +1,64 @@
// Copyright 2022 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// A minimal example of how to include Prometheus instrumentation for database stats.
package main
import (
"database/sql"
"flag"
"fmt"
"log"
"net/http"
"time"
_ "github.com/mattn/go-sqlite3"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")
func main() {
flag.Parse()
// Set up an in-memory SQLite DB.
db, err := sql.Open("sqlite3", ":memory:") // In-memory SQLite database
if err != nil {
log.Fatalf("Failed to connect to in-memory database: %v", err)
}
defer db.Close()
// Set connection pool limits to simulate more activity.
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(5)
db.SetConnMaxIdleTime(5 * time.Minute)
db.SetConnMaxLifetime(30 * time.Minute)
// Create a new Prometheus registry.
reg := prometheus.NewRegistry()
// Create and register the DB stats collector.
dbStatsCollector := collectors.NewDBStatsCollector(db, "sqlite_in_memory")
reg.MustRegister(dbStatsCollector)
// Expose the registered metrics via HTTP.
http.Handle("/metrics", promhttp.HandlerFor(
reg,
promhttp.HandlerOpts{},
))
fmt.Println("Server is running, metrics are available at /metrics")
log.Fatal(http.ListenAndServe(*addr, nil))
}

1
go.mod
View File

@ -9,6 +9,7 @@ require (
github.com/json-iterator/go v1.1.12 github.com/json-iterator/go v1.1.12
github.com/klauspost/compress v1.17.11 github.com/klauspost/compress v1.17.11
github.com/kylelemons/godebug v1.1.0 github.com/kylelemons/godebug v1.1.0
github.com/mattn/go-sqlite3 v1.14.24
github.com/prometheus/client_model v0.6.1 github.com/prometheus/client_model v0.6.1
github.com/prometheus/common v0.60.1 github.com/prometheus/common v0.60.1
github.com/prometheus/procfs v0.15.1 github.com/prometheus/procfs v0.15.1

2
go.sum
View File

@ -21,6 +21,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=

View File

@ -25,7 +25,7 @@ import (
// notImplementedErr is returned by stub functions that replace cgo functions, when cgo // notImplementedErr is returned by stub functions that replace cgo functions, when cgo
// isn't available. // isn't available.
var notImplementedErr = fmt.Errorf("not implemented") var notImplementedErr = errors.New("not implemented")
type memoryInfo struct { type memoryInfo struct {
vsize uint64 // Virtual memory size in bytes vsize uint64 // Virtual memory size in bytes