ridvanaltun/cortex
Composer 安装命令:
composer require ridvanaltun/cortex
包简介
Manage cortex.
关键字:
README 文档
README
Manage Cortex.
Table of Contents
Installation
$ composer require ridvanaltun/cortex
Usage
use ridvanaltun\Cortex\Cortex; use ridvanaltun\Cortex\Exceptions\RuleExist; use ridvanaltun\Cortex\Exceptions\RuleNotExist; use ridvanaltun\Cortex\Exceptions\TemplateExist; use ridvanaltun\Cortex\Exceptions\TemplateNotExist; use ridvanaltun\Cortex\Exceptions\UnknownRuleFormatVersion; use ridvanaltun\Cortex\Exceptions\AlertmanagerConfigNotOk; use ridvanaltun\Cortex\Exceptions\AlertmanagerConfigNotExist; $host = 'http://localhost:9002'; $username = 'username'; $password = 'password'; $cortex = new Cortex($host, $username, $password, [ 'timeout' => 5, 'verify' => false, // don't verify ssl ]); $consumer = 'consumer'; $configsService = $cortex->configsService($consumer); try { # list all alertmanager configs (all tenants) $allConfigs = $cortex->listAllAlertmanagerConfigs(); var_dump($allConfigs); # list tenant rules $rules = $configsService->getRuleFiles(); var_dump($rules); # add a rule file for tenant $configsService->addRuleFile('filename', [ [ 'alert' => 'alertname1', 'for' =>'10m', 'expr' => 'up == 0', ], [ 'alert' => 'alertname2', 'for' =>'15m', 'expr' => 'up == 1', 'labels' => [ 'severity' => 'page', ], 'annotations' => [ 'summary' => 'High request latency', ], ] ]); # add or replace rule file for tenant $configsService->applyRuleFile('filename', [ [ 'alert' => 'alertname4', 'for' =>'10m', 'expr' => 'up == 0', ], [ 'alert' => 'alertname2', 'for' =>'15m', 'expr' => 'up == 1', 'labels' => [], 'annotations' => [], ] ]); # remove rule for tenant $configsService->removeRuleFile('rulename'); # remove all rules for tenant $configsService->removeAllRuleFiles(); # change rule format version for tenant, can be set 1 or 2 $configsService->changeRuleFormatVersion('2'); # list tenant templates $templates = $configsService->getTemplateFiles(); var_dump($templates); # add a template file for tenant $template = '{{ define "slack.myorg.text" }}https://internal.myorg.net/wiki/alerts/{{ .GroupLabels.app }}/{{ . GroupLabels.alertname }}{{ end}}'; $configsService->addTemplateFile('filename', $template); # add or replace template file for tenant $template = '{{ define "slack.myorg.text" }}https://internal.myorg.net/wiki/alerts/{{ . GroupLabels.app }}/{{ .GroupLabels.alertname }}{{ end}}'; $configsService->applyTemplateFile('filename', $template); # remove template for tenant $configsService->removTemplateFile('templatename'); # remove all templates for tenant $configsService->removeAllTemplateFiles(); # get tenant alertmanager config $alertmanager = $configsService->getAlertmanagerConfig(); var_dump($alertmanager); # remove tenant alertmanager config $configsService->removeAlertmanagerConfig(); # replace tenant alertmanager config $configsService->replaceAlertmanagerConfig([ 'global' => [ 'smtp_smarthost' => 'localhost:25', 'smtp_from' => 'alertmanager@example.org', 'smtp_auth_username' => 'alertmanager', 'smtp_auth_password' => 'password', ], 'route' => [ 'receiver' => 'team-X-mails', ], 'receivers' => [ [ 'name' => 'team-X-mails', 'email_configs' => [ [ 'to' => 'abc@domain.com', ], ], ], ], ]); # remove alertmanager config for tenant $configsService->removeAlertmanagerConfig(); # validate alertmanager config $cortex->validateAlertmanagerConfig([ 'global' => [ 'smtp_smarthost' => 'localhost:25', 'smtp_from' => 'alertmanager@example.org', 'smtp_auth_username' => 'alertmanager', 'smtp_auth_password' => 'password', ], 'route' => [ 'receiver' => 'team-X-mails', ], 'receivers' => [ [ 'name' => 'team-X-mails', 'email_configs' => [ [ 'to' => 'abc@domain.com', ], ], ], ], ]); # deactive alerting for tenant $configsService->deactivate(); # activate alerting for tenant $configsService->activate(); } catch (AlertmanagerConfigNotOk $e) { echo "Provided config not ok."; } catch (RuleExist $e) { echo "Rule already exist."; } catch (RuleNotExist $e) { echo "Rule not exist."; } catch (TemplateExist $e) { echo "Template already exist."; } catch (TemplateNotExist $e) { echo "Template not exist."; } catch (AlertmanagerConfigNotExist $e) { echo "Alertmanager config not exist."; } catch (UnknownRuleFormatVersion $e) { echo "Unknown rule format version."; }
ridvanaltun/cortex 适用场景与选型建议
ridvanaltun/cortex 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 05 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cortex」 「prometheus」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ridvanaltun/cortex 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ridvanaltun/cortex 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ridvanaltun/cortex 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A fluent JSON Schema builder for PHP
Metrics endpoint for Laravel applications
Validation engine for Cortex and the PHP Fat-Free Framework
A Prometheus exporter for Laravel and Lumen
Rinvex Composer is an intuitive package that leverages the Composer Plugin API, offering enhanced installation features, that allow packages to be installed outside the standard vendor directory and executing custom scripts during the install, update, and uninstall phases.
Laravel SDK for working with prometheus metrics
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-05-21