可以将以下代码编写为SP,如果需要,可以加上获取时间(getDate()),插入表中.
该sql会调用xp_cmdshell查询磁盘总大小,一般服务器会因安全问题禁用该SP!!!
取硬盘可用空间可用系统过程实现:EXEC master.sys.xp_fixeddrives
if not exists( select * from sys.configurations(nolock) cc
where cc.name='xp_cmdshell'
and cc.value_in_use=1)
begin
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'xp_cmdshell',1
reconfigure
end
if OBJECT_ID('tempdb..#useddrives_temp') is not null drop table #useddrives_temp
if OBJECT_ID('tempdb..#totaldrives_temp') is not null drop table #totaldrives_temp
if OBJECT_ID('tempdb..#alldriveres_temp') is not null drop table #alldriveres_temp
create table tempdb..#useddrives_temp(drive char(1),freesize bigint)
create table tempdb..#totaldrives_temp(size varchar(100));
create table tempdb..#alldriveres_temp( server_name varchar(50),
drive char(1),
total_size_MB decimal(20,0),
used_size_MB decimal(20,0),
free_size_MB decimal(20,0),
used_precent decimal(5,2));
insert into #totaldrives_temp exec xp_cmdshell 'wmic LogicalDisk get deviceid,size'
insert into #useddrives_temp exec xp_fixeddrives
insert into #alldriveres_temp
select 'local',
f.drive,
t.[totalsizeMB],
(t.[totalsizeMB]-cast(f.freesize as decimal(20,0))),
f.freesize,
cast(((t.[totalsizeMB]-cast(f.freesize as bigint))*100.0/t.[totalsizeMB]) as decimal(5,2))
from (select rtrim(left(LTRIM(size),1)) as drive,
cast(replace(replace(replace(ltrim(RIGHT(rtrim(size),LEN(size)-2)),char(9),''),char(10),''),CHAR(13),'') as bigint)/1024/1024 as [totalsizeMB]
from #totaldrives_temp
where size not like '%DeviceID Size%' and LEN(size) not IN (0,1)
) AS t
inner join #useddrives_temp f on t.drive=f.drive
-----获取链服服务器磁盘占用信息
declare @allLinkServer cursor
declare @serverNameDesc nvarchar(50)
declare @linkServer varchar(20)
declare @str1 nvarchar(2000)
set @allLinkServer=CURSOR for
SELECT distinct [name],[data_source]
FROM [master].[sys].[servers]
where is_linked =1
open @allLinkServer
fetch next from @allLinkServer into @linkServer,@serverNameDesc
while (@@FETCH_STATUS=0)
begin
truncate table #totaldrives_temp
truncate table #useddrives_temp
--set @str1='
-- select '''+Rtrim(@serverNameDesc)+''' ,*
-- from OPENQUERY('+Rtrim(@linkServer)+',''SET FMTONLY OFF;SET NOCOUNT ON exec master.dbo.xp_fixeddrives'') a'
set @str1='
insert into #totaldrives_temp select * from OPENQUERY('+Rtrim(@linkServer)+',''SET FMTONLY OFF;SET NOCOUNT ON exec master.dbo.xp_cmdshell ''wmic LogicalDisk get deviceid,size'' '') a
insert into #useddrives_temp select * from OPENQUERY('+Rtrim(@linkServer)+',''SET FMTONLY OFF;SET NOCOUNT ON exec master.dbo.xp_fixeddrives'') b
insert into #alldriveres_temp
select '''+Rtrim(@serverNameDesc)+''',
f.drive,
t.[totalsizeMB],
(t.[totalsizeMB]-cast(f.freesize as decimal(20,0))),
f.freesize,
cast(((t.[totalsizeMB]-cast(f.freesize as bigint))*100.0/t.[totalsizeMB]) as decimal(5,2))
from (select rtrim(left(LTRIM(size),1)) as drive,
cast(replace(replace(replace(ltrim(RIGHT(rtrim(size),LEN(size)-2)),char(9),''''),char(10),''''),CHAR(13),'''') as bigint)/1024/1024 as [totalsizeMB]
from #totaldrives_temp
where size not like ''%DeviceID Size%'' and LEN(size) not IN (0,1)
) AS t
inner join #useddrives_temp f on t.drive=f.drive '
begin try
exec (@str1)
end try
begin catch
print N'错误'
--insert into #fdtest2 values(@serverNameDesc,0,0)
end catch
fetch next from @allLinkServer into @linkServer,@serverNameDesc
end
close @allLinkServer
deallocate @allLinkServer
select * from #alldriveres_temp
分享到:
相关推荐
您可能感兴趣的文章:SqlServer如何通过SQL语句获取处理器(CPU)、内存(Memory)、磁盘(Disk)以及操作系统相关信息SQL Server 2008 R2占用cpu、内存越来越大的两种解决方法SQL Server误区30日谈 第12天 TempDB的...
用于实时监控和分析 MySQL 服务器的性能指标和相关信息。 它可以帮助 DBA(数据库管理员)和开发人员定位和解决数据库性能问题 1、实时监控:mysqlstat 可以实时监控 MySQL 服务器的 QPS(每秒查询数)、TPS(每秒...
要解决“磁盘数据组织不合理,导致磁盘的访问次数过多”这个问题,我们可以将经常读写的数据放置在不同的磁盘上,也就是将经常在一起被多表连接查询的表放在同一个文件组上。这里强调:这里反复提到的“不同的磁盘”...
四、磁盘阵列等存储设备管理 如服务器有磁盘阵列,需对每块硬盘进行编号,并记录在案,对软件设置中的参数也要进行详细的记录,以备远程维护时指导机房人员进行远程操作。 五、机柜、电源、网线布局管理 1、服务器...
有效抵御CC、SQL注入、XSS病毒、木马、webshell等黑客攻击,为广大服务器管理员打造高效、可靠、便捷的服务器安全管理方案。 永久免费!永久贴心呵护您的服务器安全! 安装方法 注:云锁分为服务器端、PC...
生产环境的数据库可能比较大,如果直接进行全备而不压缩的话,备份集就会占用了大量磁盘空间。给备份文件的存放管理带来不便。 解决方案: 通过with compression显式启用备份压缩,指定对此备份执行备份压缩,覆盖...
在FROM后面的表中的列表顺序会对SQL执行性能影响,在没有索引及ORACLE没有对表进行统计分析的情况下ORACLE会按表出现的顺序进行链接,由此因为表的顺序不对会产生十分耗服务器资源的数据交叉。(注:如果对表进行...
服务器常规的修理方法 服务器常规的修理方法 目前流行的中高档服务器都拥有强大的管理程序,为客户提供了方便的管理途径 。相比PC而言,服务器出故障的机率是小多了,但是它出故障造成的损失可也大多了。 作为服务器...
有一台HPLH6000R服务器,开机后,系统日志报电压调节模块异常(VRM)的错误,报错的信息是:"VoltageRegulatorModule(VRM)over/under-voltage2.88V/0V"。从表面来看,极有可能是服务器的电压调节模块或其它硬件出现...
4 启动mysql服务: 4 启动svn服务: 5 启动resin服务 5 查看文件权限 5 查看cpu占用率 5 查看文件底部命令 5 查看文件顶部命令 5 创建文件 5 强行退出文件 5 Tar文件 5 ftp命令 5 看自动运行crontab 5 查看磁盘空间...
磁盘:一般安装需要20M左右的空间,根据所选择模块的不同和安装方式的不同,最少也要5M的磁盘空间(从网络服务器读取) 内存:Windows 9x/Me:16M 内存;Windows NT/2000: Min 32M] Tuning模块需要额外的...
分析占用率 1. 平均事务响应时间 Average Transaction Response Time 优秀: 良好:2-5s 及格:6-10s 不及格:>10s 2. 每秒点击率 Hits per Second LoadRunner分析页面 LoadRunner分析页面 当增大系统的压力(或增加...
充分利用临时数据表,及建立合理的索引、调整优化SQL语句,等可以减少客户访问数据库的次数,减小CPU的占用时间,提高内存的利用率,减小系统响应时间,缩短用户等待时间等都有很重要的意义。 3)调整内存分配。内存...
GBase 8s数据库日常管理包括数据库模式的切换,以及服务器的监控。监控主要分为两个方面,一方面是系统级别的监控,主要包括对系统cpu的监控,以及内存的占用情况;另一方面是数据库级别的监控,包括对磁盘空间大小...
一、检查系统的状态 通过操作系统的一些工具检查系统的状态,比如CPU、内存、交换、磁盘的利用率,根据经验或与系统正常时的状态相比对,有时系统表面上看起来看空闲,这也可能不是一个正常的状态,因为cpu可能正...
oracle语句优化:多表关联,exists ,in ORACLE对每个SQL都会对其进行分析,占用共享内存,服务器当前性能(共享内存、磁盘文件碎片)、数据库对象(表、索引)统计信息
), interpreted (然后 PL/SQL 模块将被编译为 PL/SQL 字节代码格式), debug (PL/SQL 模块将用探测调试符号来编译), non_debug。 默认值: " interpreted, non_debug " plsql_native_linker: 说明: 此参数指定链接...
mssql 微软 只能能运行在windows平台,体积比较庞大,占用许多系统资源, 但使用很方便,支持命令和图形化管理,收费。 中型企业 Mysql 甲骨文 是个开源的数据库server,可运行在多种平台, 特点是响应速度特别快,...
Oracle优化的一般顺序如下:环境调整(服务器、网络、磁盘)、Oracle实例调整、Oracle对象调整、Oracle SQL调整。我们的测试采用的Oracle数据表容量为50 M,记录条数为50万条。测试方法为:根据用户的查询要求计算...
全面保护服务器安全,阻止黑客通过SQL注入、Unicode恶意编码、跨站脚本攻击、WebShell利用、木马上传等多种攻击方式入侵您的服务器,是至今为止功能最强大的IIS防黑客保护产品之一。 ■ 防护CC攻击 可有用户自由...