Skip to content

Commit

Permalink
Update alloy-integrations
Browse files Browse the repository at this point in the history
Signed-off-by: Weifeng Wang <[email protected]>
  • Loading branch information
qclaogui committed Apr 22, 2024
1 parent 58cd37f commit 622a0d3
Show file tree
Hide file tree
Showing 40 changed files with 2,988 additions and 1,918 deletions.
56 changes: 56 additions & 0 deletions alloy-modules/kubernetes/integrations/k8s-events.alloy
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Module Components: component_cluster_events
*/

declare "component_cluster_events" {

/*****************************************************************
* ARGUMENTS
*****************************************************************/
argument "forward_to" {
comment = "Must be a list(LogsReceiver) where collected logs should be forwarded to"
}

argument "job_label" {
optional = true
default = "integrations/kubernetes/eventhandler"
}

argument "cluster" {
optional = true
default = "k3d"
}

loki.source.kubernetes_events "cluster_events" {
job_name = argument.job_label.value
log_format = "logfmt"
forward_to = [loki.process.logs_service.receiver]
}

loki.process "logs_service" {
stage.static_labels {
values = {
cluster = argument.cluster.value,
}
}
forward_to = argument.forward_to.value
}

// // Logs Service
// remote.kubernetes.secret "logs_service" {
// name = "loki-k8s-monitoring"
// namespace = "k8s-monitoring"
// }
// // Loki
// loki.write "logs_service" {
// endpoint {
// url = nonsensitive(remote.kubernetes.secret.logs_service.data["host"]) + "/loki/api/v1/push"
// tenant_id = nonsensitive(remote.kubernetes.secret.logs_service.data["tenantId"])

// basic_auth {
// username = nonsensitive(remote.kubernetes.secret.logs_service.data["username"])
// password = remote.kubernetes.secret.logs_service.data["password"]
// }
// }
// }
}
33 changes: 17 additions & 16 deletions alloy-modules/kubernetes/integrations/memcached.alloy
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ declare "component_memcached" {
comment = "Must be a list(MetricssReceiver) where collected metrics should be forwarded to"
}

argument "memcached_address" {
comment = "address of the Memcached"
argument "job_label" {
comment = "job label (default: integrations/kubernetes/memcached)"
optional = true
default = "memcached:11211"
}

argument "memcached_timeout" {
comment = "timeout of the Memcached"
argument "namespace" {
comment = "kubernetes secret name (default: monitoring-system)"
optional = true
default = "5s"
}

argument "instance_name" {
comment = "instance of the Memcached"
argument "name" {
comment = "kubernetes secret name (default: alloy-integrations-redis)"
optional = true
}

Expand All @@ -36,22 +34,25 @@ declare "component_memcached" {
argument "scrape_interval" {
comment = "How often to scrape metrics from the targets (default: 60s)"
optional = true
default = "60s"
}

argument "scrape_timeout" {
comment = "How long before a scrape times out (default: 10s)"
optional = true
default = "10s"
}

remote.kubernetes.secret "memcached" {
namespace = coalesce(argument.namespace.value, "monitoring-system")
name = coalesce(argument.name.value, "alloy-integrations-memcached")
}

/***************************************************************
* Integrations Memcached
****************************************************************/
// https://grafana.com/docs/alloy/latest/reference/components/prometheus.exporter.memcached/
prometheus.exporter.memcached "integrations_memcached_exporter" {
address = argument.memcached_address.value
timeout = argument.memcached_timeout.value
address = nonsensitive(remote.kubernetes.secret.memcached.data["instance-address"])
timeout = nonsensitive(remote.kubernetes.secret.memcached.data["instance-timeout"])
}

/***************************************************************
Expand All @@ -62,12 +63,12 @@ declare "component_memcached" {

rule {
target_label = "job"
replacement = "integrations/kubernetes/memcached"
replacement = coalesce(argument.job_label.value, "integrations/kubernetes/memcached")
}

rule {
target_label = "instance"
replacement = coalesce(argument.instance_name.value, constants.hostname)
replacement = coalesce(nonsensitive(remote.kubernetes.secret.memcached.data["instance-name"]), constants.hostname)
}
}

Expand All @@ -82,8 +83,8 @@ declare "component_memcached" {
enable_protobuf_negotiation = true
scrape_classic_histograms = true

scrape_interval = argument.scrape_interval.value
scrape_timeout = argument.scrape_timeout.value
scrape_interval = coalesce(argument.scrape_interval.value, "60s")
scrape_timeout = coalesce(argument.scrape_timeout.value, "10s")

clustering {
enabled = true
Expand Down
107 changes: 107 additions & 0 deletions alloy-modules/kubernetes/integrations/mysql.alloy
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
Module Components: component_mysql
*/

declare "component_mysql" {

/*****************************************************************
* ARGUMENTS
*****************************************************************/
argument "forward_to" {
comment = "Must be a list(MetricssReceiver) where collected metrics should be forwarded to"
}

argument "job_label" {
comment = "job label (default: integrations/kubernetes/mysql)"
optional = true
}

argument "namespace" {
comment = "kubernetes secret name (default: monitoring-system)"
optional = true
}

argument "name" {
comment = "kubernetes secret name (default: alloy-integrations-mysql)"
optional = true
}

argument "keep_metrics" {
optional = true
default = "(up|instance:mysql_heartbeat_lag_seconds|instance:mysql_slave_lag_seconds|mysql_global_status_aborted_clients|mysql_global_status_aborted_connects|mysql_global_status_buffer_pool_pages|mysql_global_status_bytes_received|mysql_global_status_bytes_sent|mysql_global_status_commands_total|mysql_global_status_created_tmp_disk_tables|mysql_global_status_created_tmp_files|mysql_global_status_created_tmp_tables|mysql_global_status_handlers_total|mysql_global_status_innodb_log_waits|mysql_global_status_innodb_mem_adaptive_hash|mysql_global_status_innodb_mem_dictionary|mysql_global_status_innodb_num_open_files|mysql_global_status_innodb_page_size|mysql_global_status_max_used_connections|mysql_global_status_open_files|mysql_global_status_open_table_definitions|mysql_global_status_open_tables|mysql_global_status_opened_files|mysql_global_status_opened_table_definitions|mysql_global_status_opened_tables|mysql_global_status_qcache_free_memory|mysql_global_status_qcache_hits|mysql_global_status_qcache_inserts|mysql_global_status_qcache_lowmem_prunes|mysql_global_status_qcache_not_cached|mysql_global_status_qcache_queries_in_cache|mysql_global_status_queries|mysql_global_status_questions|mysql_global_status_select_full_join|mysql_global_status_select_full_range_join|mysql_global_status_select_range|mysql_global_status_select_range_check|mysql_global_status_select_scan|mysql_global_status_slow_queries|mysql_global_status_sort_merge_passes|mysql_global_status_sort_range|mysql_global_status_sort_rows|mysql_global_status_sort_scan|mysql_global_status_table_locks_immediate|mysql_global_status_table_locks_waited|mysql_global_status_table_open_cache_hits|mysql_global_status_table_open_cache_misses|mysql_global_status_table_open_cache_overflows|mysql_global_status_threads_cached|mysql_global_status_threads_connected|mysql_global_status_threads_created|mysql_global_status_threads_running|mysql_global_status_uptime|mysql_global_status_wsrep_local_recv_queue|mysql_global_status_wsrep_local_state|mysql_global_status_wsrep_ready|mysql_global_variables_innodb_additional_mem_pool_size|mysql_global_variables_innodb_buffer_pool_size|mysql_global_variables_innodb_log_buffer_size|mysql_global_variables_key_buffer_size|mysql_global_variables_max_connections|mysql_global_variables_open_files_limit|mysql_global_variables_query_cache_size|mysql_global_variables_table_definition_cache|mysql_global_variables_table_open_cache|mysql_global_variables_thread_cache_size|mysql_global_variables_tokudb_cache_size|mysql_global_variables_wsrep_desync|mysql_heartbeat_now_timestamp_seconds|mysql_heartbeat_stored_timestamp_seconds|mysql_info_schema_processlist_threads|mysql_slave_status_seconds_behind_master|mysql_slave_status_slave_io_running|mysql_slave_status_slave_sql_running|mysql_slave_status_sql_delay|mysql_up)"
}

argument "scrape_interval" {
comment = "How often to scrape metrics from the targets (default: 60s)"
optional = true
}

argument "scrape_timeout" {
comment = "How long before a scrape times out (default: 10s)"
optional = true
}

remote.kubernetes.secret "mysql" {
name = coalesce(argument.name.value, "alloy-integrations-mysql")
namespace = coalesce(argument.namespace.value, "monitoring-system")
}

/***************************************************************
* Integrations Mysql
****************************************************************/
prometheus.exporter.mysql "integrations_mysqld_exporter" {
data_source_name = nonsensitive(remote.kubernetes.secret.mysql.data["mysql-username"]) + ":" + nonsensitive(remote.kubernetes.secret.mysql.data["mysql-password"]) + "@(" + nonsensitive(remote.kubernetes.secret.mysql.data["mysql-host"]) + ")/"
}

/***************************************************************
* Discovery Relabelings (pre-scrape)
****************************************************************/
discovery.relabel "integrations_mysqld_exporter" {
targets = prometheus.exporter.mysql.integrations_mysqld_exporter.targets

rule {
target_label = "job"
replacement = coalesce(argument.job_label.value, "integrations/kubernetes/mysql")
}

rule {
target_label = "instance"
replacement = coalesce(nonsensitive(remote.kubernetes.secret.mysql.data["instance-name"]), constants.hostname)
}
}

/***************************************************************
* Prometheus Scrape Integrations Targets
****************************************************************/
prometheus.scrape "integrations_mysqld_exporter" {
targets = concat(
discovery.relabel.integrations_mysqld_exporter.output,
)

enable_protobuf_negotiation = true
scrape_classic_histograms = true

scrape_interval = coalesce(argument.scrape_interval.value, "60s")
scrape_timeout = coalesce(argument.scrape_timeout.value, "10s")

clustering {
enabled = true
}

forward_to = [prometheus.relabel.integrations_mysqld_exporter.receiver]
}

/***************************************************************
* Prometheus Metric Relabelings (post-scrape)
****************************************************************/
prometheus.relabel "integrations_mysqld_exporter" {
forward_to = argument.forward_to.value

// keep only metrics that match the keep_metrics regex
rule {
source_labels = ["__name__"]
regex = argument.keep_metrics.value
action = "keep"
}
}
}
110 changes: 110 additions & 0 deletions alloy-modules/kubernetes/integrations/redis.alloy
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
Module Components: component_redis_exporter
*/

declare "component_redis_exporter" {

/*****************************************************************
* ARGUMENTS
*****************************************************************/
argument "forward_to" {
comment = "Must be a list(MetricssReceiver) where collected metrics should be forwarded to"
}

argument "job_label" {
comment = "job label (default: integrations/kubernetes/redis_exporter)"
optional = true
}

argument "namespace" {
comment = "kubernetes secret name (default: monitoring-system)"
optional = true
}

argument "name" {
comment = "kubernetes secret name (default: alloy-integrations-redis)"
optional = true
}

argument "keep_metrics" {
optional = true
default = "(up|redis_blocked_clients|redis_cluster_slots_fail|redis_cluster_slots_pfail|redis_cluster_state|redis_commands_duration_seconds_total|redis_commands_total|redis_connected_clients|redis_connected_slaves|redis_db_keys|redis_db_keys_expiring|redis_evicted_keys_total|redis_keyspace_hits_total|redis_keyspace_misses_total|redis_master_last_io_seconds_ago|redis_memory_fragmentation_ratio|redis_memory_max_bytes|redis_memory_used_bytes|redis_memory_used_rss_bytes|redis_total_system_memory_bytes|redis_up)"
}

argument "scrape_interval" {
comment = "How often to scrape metrics from the targets (default: 60s)"
optional = true
default = "60s"
}

argument "scrape_timeout" {
comment = "How long before a scrape times out (default: 10s)"
optional = true
default = "10s"
}

remote.kubernetes.secret "redis" {
namespace = coalesce(argument.namespace.value, "monitoring-system")
name = coalesce(argument.name.value, "alloy-integrations-redis")
}

/***************************************************************
* Integrations Redis
****************************************************************/
prometheus.exporter.redis "integrations_redis_exporter" {
redis_addr = nonsensitive(remote.kubernetes.secret.redis.data["instance-address"])
redis_password = nonsensitive(remote.kubernetes.secret.redis.data["instance-password"])
}

/***************************************************************
* Discovery Relabelings (pre-scrape)
****************************************************************/
discovery.relabel "integrations_redis_exporter" {
targets = prometheus.exporter.redis.integrations_redis_exporter.targets

rule {
target_label = "job"
replacement = coalesce(argument.job_label.value, "integrations/kubernetes/redis_exporter")
}

rule {
target_label = "instance"
replacement = coalesce(nonsensitive(remote.kubernetes.secret.redis.data["instance-name"]), constants.hostname)
}
}

/***************************************************************
* Prometheus Scrape Integrations Targets
****************************************************************/
prometheus.scrape "integrations_redis_exporter" {
targets = concat(
discovery.relabel.integrations_redis_exporter.output,
)

enable_protobuf_negotiation = true
scrape_classic_histograms = true

scrape_interval = argument.scrape_interval.value
scrape_timeout = argument.scrape_timeout.value

clustering {
enabled = true
}

forward_to = [prometheus.relabel.integrations_redis_exporter.receiver]
}

/***************************************************************
* Prometheus Metric Relabelings (post-scrape)
****************************************************************/
prometheus.relabel "integrations_redis_exporter" {
forward_to = argument.forward_to.value

// keep only metrics that match the keep_metrics regex
rule {
source_labels = ["__name__"]
regex = argument.keep_metrics.value
action = "keep"
}
}
}
Loading

0 comments on commit 622a0d3

Please sign in to comment.