Prometheus监控cassandra

作者: ropon 分类: Prometheus 发布时间: 2022-01-27 14:00
  • 1、将jmx jar包上传到cassandra安装目录的lib目录下
  • 2、在conf目录下新建cassandra-jmx.yml
    lowercaseOutputName: true
    lowercaseOutputLabelNames: true
    whitelistObjectNames: [
    "org.apache.cassandra.metrics:type=ColumnFamily,name=RangeLatency,*",
    "org.apache.cassandra.metrics:type=ColumnFamily,name=LiveSSTableCount,*",
    "org.apache.cassandra.metrics:type=ColumnFamily,name=SSTablesPerReadHistogram,*",
    "org.apache.cassandra.metrics:type=ColumnFamily,name=SpeculativeRetries,*",
    "org.apache.cassandra.metrics:type=ColumnFamily,name=MemtableOnHeapSize,*",
    "org.apache.cassandra.metrics:type=ColumnFamily,name=MemtableSwitchCount,*",
    "org.apache.cassandra.metrics:type=ColumnFamily,name=MemtableLiveDataSize,*",
    "org.apache.cassandra.metrics:type=ColumnFamily,name=MemtableColumnsCount,*",
    "org.apache.cassandra.metrics:type=ColumnFamily,name=MemtableOffHeapSize,*",
    "org.apache.cassandra.metrics:type=ColumnFamily,name=BloomFilterFalsePositives,*",
    "org.apache.cassandra.metrics:type=ColumnFamily,name=BloomFilterFalseRatio,*",
    "org.apache.cassandra.metrics:type=ColumnFamily,name=BloomFilterDiskSpaceUsed,*",
    "org.apache.cassandra.metrics:type=ColumnFamily,name=BloomFilterOffHeapMemoryUsed,*",
    "org.apache.cassandra.metrics:type=ColumnFamily,name=SnapshotsSize,*",
    "org.apache.cassandra.metrics:type=ColumnFamily,name=TotalDiskSpaceUsed,*",
    "org.apache.cassandra.metrics:type=CQL,name=RegularStatementsExecuted,*",
    "org.apache.cassandra.metrics:type=CQL,name=PreparedStatementsExecuted,*",
    "org.apache.cassandra.metrics:type=Compaction,name=PendingTasks,*",
    "org.apache.cassandra.metrics:type=Compaction,name=CompletedTasks,*",
    "org.apache.cassandra.metrics:type=Compaction,name=BytesCompacted,*",
    "org.apache.cassandra.metrics:type=Compaction,name=TotalCompactionsCompleted,*",
    "org.apache.cassandra.metrics:type=ClientRequest,name=Latency,*",
    "org.apache.cassandra.metrics:type=ClientRequest,name=Unavailables,*",
    "org.apache.cassandra.metrics:type=ClientRequest,name=Timeouts,*",
    "org.apache.cassandra.metrics:type=Storage,name=Exceptions,*",
    "org.apache.cassandra.metrics:type=Storage,name=TotalHints,*",
    "org.apache.cassandra.metrics:type=Storage,name=TotalHintsInProgress,*",
    "org.apache.cassandra.metrics:type=Storage,name=Load,*",
    "org.apache.cassandra.metrics:type=Connection,name=TotalTimeouts,*",
    "org.apache.cassandra.metrics:type=ThreadPools,name=CompletedTasks,*",
    "org.apache.cassandra.metrics:type=ThreadPools,name=PendingTasks,*",
    "org.apache.cassandra.metrics:type=ThreadPools,name=ActiveTasks,*",
    "org.apache.cassandra.metrics:type=ThreadPools,name=TotalBlockedTasks,*",
    "org.apache.cassandra.metrics:type=ThreadPools,name=CurrentlyBlockedTasks,*",
    "org.apache.cassandra.metrics:type=DroppedMessage,name=Dropped,*",
    "org.apache.cassandra.metrics:type=Cache,scope=KeyCache,name=HitRate,*",
    "org.apache.cassandra.metrics:type=Cache,scope=KeyCache,name=Hits,*",
    "org.apache.cassandra.metrics:type=Cache,scope=KeyCache,name=Requests,*",
    "org.apache.cassandra.metrics:type=Cache,scope=KeyCache,name=Entries,*",
    "org.apache.cassandra.metrics:type=Cache,scope=KeyCache,name=Size,*",
    #"org.apache.cassandra.metrics:type=Streaming,name=TotalIncomingBytes,*",
    #"org.apache.cassandra.metrics:type=Streaming,name=TotalOutgoingBytes,*",
    "org.apache.cassandra.metrics:type=Client,name=connectedNativeClients,*",
    "org.apache.cassandra.metrics:type=Client,name=connectedThriftClients,*",
    "org.apache.cassandra.metrics:type=Table,name=WriteLatency,*",
    "org.apache.cassandra.metrics:type=Table,name=ReadLatency,*",
    "org.apache.cassandra.net:type=FailureDetector,*",
    ]
    #blacklistObjectNames: ["org.apache.cassandra.metrics:type=ColumnFamily,*"]
    rules:
    - pattern: org.apache.cassandra.metrics<type=(Connection|Streaming), scope=(\S*), name=(\S*)><>(Count|Value)
    name: cassandra_$1_$3
    labels:
      address: "$2"
    - pattern: org.apache.cassandra.metrics<type=(ColumnFamily), name=(RangeLatency)><>(Mean)
    name: cassandra_$1_$2_$3
    - pattern: org.apache.cassandra.net<type=(FailureDetector)><>(DownEndpointCount)
    name: cassandra_$1_$2
    - pattern: org.apache.cassandra.metrics<type=(Keyspace), keyspace=(\S*), name=(\S*)><>(Count|Mean|95thPercentile)
    name: cassandra_$1_$3_$4
    labels:
      "$1": "$2"
    - pattern: org.apache.cassandra.metrics<type=(Table), keyspace=(\S*), scope=(\S*), name=(\S*)><>(Count|Mean|95thPercentile)
    name: cassandra_$1_$4_$5
    labels:
      "keyspace": "$2"
      "table": "$3"
    - pattern: org.apache.cassandra.metrics<type=(ClientRequest), scope=(\S*), name=(\S*)><>(Count|Mean|95thPercentile)
    name: cassandra_$1_$3_$4
    labels:
      "type": "$2"
    - pattern: org.apache.cassandra.metrics<type=(\S*)(?:, ((?!scope)\S*)=(\S*))?(?:, scope=(\S*))?,
      name=(\S*)><>(Count|Value)
    name: cassandra_$1_$5
    labels:
      "$1": "$4"
      "$2": "$3"
  • 3、在conf目录下cassandra-env.sh增加javaagent
    JVM_OPTS="$JVM_OPTS -javaagent:$CASSANDRA_HOME/lib/jamm-0.3.0.jar -javaagent:$CASSANDRA_HOME/lib/jmx_prometheus_javaagent-0.16.0.jar=7070:${CASSANDRA_HOME}/conf/cassandra-jmx.yml"
  • 4、etcd注册
    etcdctl put /prometheus/discovery/cassandra/cassandra-v2-2 '{"name":"cassandra-v2-2","address":"10.10.21.177:7070","labels": [{"key":"c_type","val":"cassandra"},{"key":"ip","val":"10.10.21.177"}]}'

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!