andrii29 / mongodb-profiler-exporter

A Prometheus exporter for MongoDB Profiler
MIT License
13 stars 0 forks source link

try to enable mongodb-profiler-exporter in k3s enviorment #15

Open sshoster opened 1 week ago

sshoster commented 1 week ago

Hi i did the following steps 1.) // enable profile in all db

db.adminCommand('listDatabases').databases.forEach(function (database) {
    db.getSiblingDB(database.name).setProfilingLevel(1, { slowms: 100 });
});

2.) // start a new pod using the following command in k3s

 kubectl run mongodb-profiler-exporter   --image=andriik/mongodb-profiler-exporter   --restart=Never   --env="MONGODB_URI=mongodb://10.109.0.42:27017/?directConnection=true"   --overrides='
{
  "apiVersion": "v1",
  "spec": {
    "hostNetwork": true,
    "containers": [
      {
        "name": "mongodb-profiler-exporter",
        "image": "andriik/mongodb-profiler-exporter",
        "env": [
          {
            "name": "MONGODB_URI",
            "value": "mongodb://10.109.0.42:27017/?directConnection=true"
          }
        ]
      }
    ]
  }
}'
pod/mongodb-profiler-exporter created

3.) // config Prometheus job_name: 'mongodb-profiler-exporter'\n metrics_path: /metrics\n \ static_configs:\n - targets:\n - 192.168.40.119:9179

as for now in the logs kubectl logs -f pod/mongodb-profiler-exporter 2024-11-14 12:55:54,458 - INFO - Starting MongoDB Prometheus Exporter with the following parameters: 2024-11-14 12:55:54,458 - INFO - Wait Interval: 10 seconds 2024-11-14 12:55:54,458 - INFO - Maximum String Size: 1000 2024-11-14 12:55:54,458 - INFO - Listen IP: 0.0.0.0 2024-11-14 12:55:54,458 - INFO - Listen Port: 9179 2024-11-14 12:55:54,458 - INFO - Metrics Endpoint: /metrics

looks ok aslo prometheus-server no erros but in the prometheus UI i don't see the non of slow mertric

can you advice what is wrong ?

andrii29 commented 1 week ago
andrii29 commented 1 week ago
sshoster commented 5 days ago

just want to update that i add some typo error and now is working good

after some time i see that there are in mogo logs some collection scan queries that are not displayed in the graph do you know why ?

for example taken from mongo logs

2024-11-14T17:10:52+02:00 2024-11-14T17:10:52.448466654+02:00 stdout F {"t":{"$date":"2024-11-14T15:10:52.447+00:00"},"s":"I", "c":"COMMAND", "id":51803, "ctx":"conn6075","msg":"Slow query","attr":{"type":"command","ns":"bridge.bridgestate","command":{"findAndModify":"bridgestate","query":{},"new":true,"update":{"$max":{"lastHandledEvent":2106,"lastHandledRevision":826}},"writeConcern":{"w":"majority","wtimeout":10000},"txnNumber":416,"$db":"bridge","$clusterTime":{"clusterTime":{"$timestamp":{"t":1731597052,"i":3}},"signature":{"hash":{"$binary":{"base64":"AAAAAAAAAAAAAAAAAAAAAAAAAAA=","subType":"0"}},"keyId":0}},"lsid":{"id":{"$uuid":"b8b529b8-8ea5-4f67-ab5f-13b62c02f8e0"}}},"planSummary":"COLLSCAN","keysExamined":0,"docsExamined":1,"nMatched":1,"nModified":1,"numYields":0,"reslen":307,"locks":{"ParallelBatchWriterMode":{"acquireCount":{"r":2}},"FeatureCompatibilityVersion":{"acquireCount":{"r":1,"w":2}},"ReplicationStateTransition":{"acquireCount":{"w":4}},"Global":{"acquireCount":{"r":1,"w":2}},"Database":{"acquireCount":{"w":2}},"Collection":{"acquireCount":{"w":2}},"Mutex":{"acquireCount":{"r":2}}},"flowControl":{"acquireCount":1,"timeAcquiringMicros":1},"writeConcern":{"w":"majority","wtimeout":10000,"provenance":"clientSupplied"},"storage":{},"protocol":"op_msg","durationMillis":160}}

image

andrii29 commented 5 days ago

The provided log was generated on 2024-11-14T17:10:52+02:00. The exporter parses only new log entries. If the exporter was enabled during this time, you should adjust the time range in Grafana and check if this query was captured.